Javascript 如何使Highstock rangeselector按钮加载新数据?
我正在尝试使用django创建一个网站,显示不同数据范围的highstock(highcharts)图。我是一名高级python用户,尽管我是javascript初学者 我希望数据范围(1d、1w、1m、all)的按钮在每次单击时调用不同的url。我已经在下面列出了代码,以及rangeSelector按钮的文档。在示例代码中,我尝试了我在网上找到的几种变体,但都不起作用。非常感谢您的帮助Javascript 如何使Highstock rangeselector按钮加载新数据?,javascript,django,highcharts,highstock,Javascript,Django,Highcharts,Highstock,我正在尝试使用django创建一个网站,显示不同数据范围的highstock(highcharts)图。我是一名高级python用户,尽管我是javascript初学者 我希望数据范围(1d、1w、1m、all)的按钮在每次单击时调用不同的url。我已经在下面列出了代码,以及rangeSelector按钮的文档。在示例代码中,我尝试了我在网上找到的几种变体,但都不起作用。非常感谢您的帮助 rangeSelector: { allButtonsEnabled: true,
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]]]
}
}],
},
谢谢大家! 您可以在
事件中使用jQuery。单击从外部API获取数据。然后使用新的数据和数据分组选项更新图表
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
}
}
现场演示: