Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. class HtmlDashCreator(object):
  2.     def __init__():
  3.         ## add head
  4.         self.html = '''
  5.        <script src="https://code.highcharts.com/stock/highstock.js"></script>
  6.        <script src="https://code.highcharts.com/stock/modules/data.js"></script>
  7.        <script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
  8.        <script src="https://code.highcharts.com/stock/modules/export-data.js"></script>
  9.        '''
  10.         self.chart_counter = 1
  11.  
  12.     def add_chart(chart_name, chart_series_name, data_url):
  13.         chart_id = self.chart_counter
  14.         self.chart_counter += 1
  15.         template = '''
  16.        <script>
  17.  
  18.        Highcharts.getJSON('{data_url}', function (data) {
  19.            // Create the chart
  20.            Highcharts.stockChart('{chart_id}', {
  21.  
  22.  
  23.                rangeSelector: {
  24.                    selected: 1
  25.                },
  26.  
  27.                title: {
  28.                    text: '{chart_name}'
  29.                },
  30.  
  31.                series: [{
  32.                    name: '{series_name}',
  33.                    data: data,
  34.                    tooltip: {
  35.                        valueDecimals: 5
  36.                    }
  37.                }]
  38.            });
  39.        });
  40.  
  41.        </script>
  42.        <div id='{chart_id}' style="height: 400px; min-width: 310px"></div>
  43.        '''
  44.         self.html += template.format(chart_id=chart_id, chart_series_name=chart_series_name, data_url=data_url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement