简体   繁体   English

如何使Highstock范围选择器按钮加载新数据?

[英]How to make Highstock rangeselector buttons load new data?

I am trying to create a website using django, displaying highstock (highcharts) graphs for different ranges of data. 我正在尝试使用django创建一个网站,以显示针对不同数据范围的highstock(图表)图表。 I am an advanced python user, though a beginner with javascript. 我是高级python用户,尽管是使用javascript的初学者。

I want the buttons for the data ranges (1d, 1w, 1m, all) to each call a different url when clicked on. 我希望数据范围(1d,1w,1m等)的按钮在单击时分别调用不同的URL。 I have put the code below, as well as the documentation for rangeSelector buttons. 我将代码以及rangeSelector按钮的文档放在下面。 In the example code I have attempted several variations of things I have found online, though none work. 在示例代码中,我尝试了几种在网上找到的东西的变体,尽管没有用。 Any help is much appreciated! 任何帮助深表感谢!

rangeSelector: {
        allButtonsEnabled: true,
        buttons: [{
        type: 'day',
                count: 1,
                text: 'Day',
                events: {
                click: function () {
                return "https://0.0.0.0/daydata";
                }
                },
                dataGrouping: {
                forced: true,
                        units: [['day', [1]]]
                }
        }, {
        type: 'week',
                count: 1,
                text: 'Week',
                events: {
                click: function () {
                return "https://0.0.0.0/weekdata";
                }
                },
        },
        {
        type: 'month',
                count: 1,
                text: 'Month',
                click: function () {
                return "https://0.0.0.0/monthdata";
                },
                dataGrouping: {
                forced: true,
                        units: [['month', [1]]]
                }
        }, {
        type: 'all',
                text: 'All',
                events: {
                click: function (event) {
                return "https://0.0.0.0/alldata";
                }
                },
                dataGrouping: {
                forced: true,
                        units: [['month', [24]]]
                }
        }],
},

https://api.highcharts.com/highstock/rangeSelector.buttons https://api.highcharts.com/highstock/rangeSelector.buttons.events.click https://api.highcharts.com/highstock/rangeSelector.buttons https://api.highcharts.com/highstock/rangeSelector.buttons.events.click

Thank you! 谢谢!

You can use jQuery in events.click to fetch the data from an external API. 您可以在events.click使用jQuery ,以从外部API获取数据。 Then update the chart with the new data and data grouping options. 然后使用新的数据和数据分组选项更新图表。

  events: {
    click: function() {

      $.getJSON('https://cdn.rawgit.com/highcharts/highcharts/057b672172ccc6c08fe7dbb27fc17ebca3f5b770/samples/data/new-intraday.json',
        function(data) {
          chart.series[0].update({
            data,
            dataGrouping: {
              forced: true,
              units: [
                ['week', [1]]
              ]
            }
          });
        });

      return false; // prevent further actions
    }
  }

Live demo: http://jsfiddle.net/BlackLabel/2mb4fypn/ 现场演示: http : //jsfiddle.net/BlackLabel/2mb4fypn/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM