msemochkin

airflow-nvd3

Jan 30th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.12 KB | None | 0 0
  1. In [60]: from nvd3 import lineChart
  2.     ...: chart = lineChart(name="lineChart", x_is_date=False, x_axis_format="AM_PM")
  3.     ...:
  4.     ...: xdata = range(24)
  5.     ...: ydata = [0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 4, 3, 3, 5, 7, 5, 3, 16, 6, 9, 15, 4, 12]
  6.     ...: ydata2 = [9, 8, 11, 8, 3, 7, 10, 8, 6, 6, 9, 6, 5, 4, 3, 10, 0, 6, 3, 1, 0, 0, 0, 1]
  7.     ...:
  8.     ...: extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " calls"}}
  9.     ...: chart.add_serie(y=ydata, x=xdata, name='sine', extra=extra_serie)
  10.     ...: extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}}
  11.     ...: chart.add_serie(y=ydata2, x=xdata, name='cose', extra=extra_serie)
  12.     ...:
  13.  
  14. In [61]: chart.buildhtml()
  15.  
  16. In [62]: str(chart)
  17. Out[62]: '<!DOCTYPE html>\n<html lang="en">\n    <head>\n        <meta charset="utf-8" />\n        <link href="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.7.0/nv.d3.min.css" rel="stylesheet" />\n        <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>\n        <script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.7.0/nv.d3.min.js"></script>\n    </head>\n    <body>\n        \n    <div id="linechart"><svg style="height:450px;"></svg></div>\n\n\n    <script>\n\n\n\n            data_linechart=[{"values": [{"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 1}, {"x": 3, "y": 1}, {"x": 4, "y": 0}, {"x": 5, "y": 0}, {"x": 6, "y": 0}, {"x": 7, "y": 0}, {"x": 8, "y": 1}, {"x": 9, "y": 0}, {"x": 10, "y": 0}, {"x": 11, "y": 4}, {"x": 12, "y": 3}, {"x": 13, "y": 3}, {"x": 14, "y": 5}, {"x": 15, "y": 7}, {"x": 16, "y": 5}, {"x": 17, "y": 3}, {"x": 18, "y": 16}, {"x": 19, "y": 6}, {"x": 20, "y": 9}, {"x": 21, "y": 15}, {"x": 22, "y": 4}, {"x": 23, "y": 12}], "key": "sine", "yAxis": "1"}, {"values": [{"x": 0, "y": 9}, {"x": 1, "y": 8}, {"x": 2, "y": 11}, {"x": 3, "y": 8}, {"x": 4, "y": 3}, {"x": 5, "y": 7}, {"x": 6, "y": 10}, {"x": 7, "y": 8}, {"x": 8, "y": 6}, {"x": 9, "y": 6}, {"x": 10, "y": 9}, {"x": 11, "y": 6}, {"x": 12, "y": 5}, {"x": 13, "y": 4}, {"x": 14, "y": 3}, {"x": 15, "y": 10}, {"x": 16, "y": 0}, {"x": 17, "y": 6}, {"x": 18, "y": 3}, {"x": 19, "y": 1}, {"x": 20, "y": 0}, {"x": 21, "y": 0}, {"x": 22, "y": 0}, {"x": 23, "y": 1}], "key": "cose", "yAxis": "1"}];\n\n\n        nv.addGraph(function() {\n        var chart = nv.models.lineChart();\n\n        chart.margin({top: 30, right: 60, bottom: 20, left: 60});\n\n        var datum = data_linechart;\n\n\n\n                chart.xAxis\n                .tickFormat(function(d) { return get_am_pm(parseInt(d)); });\n            chart.yAxis\n                .tickFormat(d3.format(\',.02f\'));\n\n\n        function get_am_pm(d){\n            if (d > 12) {\n                d = d - 12; return (String(d) + \'PM\');\n            }\n            else {\n                return (String(d) + \'AM\');\n            }\n        };\n\n          chart.showLegend(true);\n\n\n    \n\n        \n\n\n\n            d3.select(\'#linechart svg\')\n            .datum(datum)\n            .transition().duration(500)\n            .attr(\'height\', 450)\n            .call(chart);\n\n\n        });\n\n\n\n    </script>\n\n    </body>\n</html>'
  18.  
  19. In [63]: chart.buildcontent()
  20.  
  21. In [64]: str(chart.content)
  22. Out[64]: '\n    <div id="linechart"><svg style="height:450px;"></svg></div>\n\n\n    <script>\n\n\n\n            data_linechart=[{"values": [{"x": 0, "y": 0}, {"x": 1, "y": 0}, {"x": 2, "y": 1}, {"x": 3, "y": 1}, {"x": 4, "y": 0}, {"x": 5, "y": 0}, {"x": 6, "y": 0}, {"x": 7, "y": 0}, {"x": 8, "y": 1}, {"x": 9, "y": 0}, {"x": 10, "y": 0}, {"x": 11, "y": 4}, {"x": 12, "y": 3}, {"x": 13, "y": 3}, {"x": 14, "y": 5}, {"x": 15, "y": 7}, {"x": 16, "y": 5}, {"x": 17, "y": 3}, {"x": 18, "y": 16}, {"x": 19, "y": 6}, {"x": 20, "y": 9}, {"x": 21, "y": 15}, {"x": 22, "y": 4}, {"x": 23, "y": 12}], "key": "sine", "yAxis": "1"}, {"values": [{"x": 0, "y": 9}, {"x": 1, "y": 8}, {"x": 2, "y": 11}, {"x": 3, "y": 8}, {"x": 4, "y": 3}, {"x": 5, "y": 7}, {"x": 6, "y": 10}, {"x": 7, "y": 8}, {"x": 8, "y": 6}, {"x": 9, "y": 6}, {"x": 10, "y": 9}, {"x": 11, "y": 6}, {"x": 12, "y": 5}, {"x": 13, "y": 4}, {"x": 14, "y": 3}, {"x": 15, "y": 10}, {"x": 16, "y": 0}, {"x": 17, "y": 6}, {"x": 18, "y": 3}, {"x": 19, "y": 1}, {"x": 20, "y": 0}, {"x": 21, "y": 0}, {"x": 22, "y": 0}, {"x": 23, "y": 1}], "key": "cose", "yAxis": "1"}];\n\n\n        nv.addGraph(function() {\n        var chart = nv.models.lineChart();\n\n        chart.margin({top: 30, right: 60, bottom: 20, left: 60});\n\n        var datum = data_linechart;\n\n\n\n                chart.xAxis\n                .tickFormat(function(d) { return get_am_pm(parseInt(d)); });\n            chart.yAxis\n                .tickFormat(d3.format(\',.02f\'));\n\n\n        function get_am_pm(d){\n            if (d > 12) {\n                d = d - 12; return (String(d) + \'PM\');\n            }\n            else {\n                return (String(d) + \'AM\');\n            }\n        };\n\n          chart.showLegend(true);\n\n\n    \n\n        \n\n\n\n            d3.select(\'#linechart svg\')\n            .datum(datum)\n            .transition().duration(500)\n            .attr(\'height\', 450)\n            .call(chart);\n\n\n        });\n\n\n\n    </script>\n'
  23.  
  24. In [65]:
Advertisement
Add Comment
Please, Sign In to add comment