1
我正在编辑一个网站,我无法访问原始代码,我所能做的就是将代码追加到最后。我没有访问PHP(我认为我不需要那个)。仅使用JavaScript更新现有Highstock图形的数据
这是现有代码:
<div class="highstockchart" data-container="chartContainer" data-metadata-contractno="1" data-yaxis-title-text="kWh">
<div class="chart-serie in" data-serie-data="[4.0,4.0,3.0,4.0,3.0]" data-serie-id="0" data-serie-name="Forbruk" data-serie-pointstart="1424818800000" data-serie-tooltip-decimals="0" data-serie-tooltip-suffix=" kWh" id="chartContainer">
</div>
</div>
<script src="/Modules/Enoro.Standard/scripts/enoro.standard-0.2.8.js" type="text/javascript"></script>
<script src="/Modules/Enoro.Standard/scripts/highstock-1.3.9.js" type="text/javascript"></script>
<script src="/Modules/Enoro.Standard/scripts/highstock.exporting-1.3.9.js" type="text/javascript"></script>
<script src="/Themes/Enoro.Bootstrap/scripts/bootstrapx-clickover.js" type="text/javascript"></script>
<script type="text/javascript">
//HIGHSTOCKCHART
(function() {
var highstockchart = enoro.namespace("orchard.standard.consumption.highstockchart");
highstockchart.defaults = {
chart: {
renderTo: null,
},
credits: {
enabled: false
},
navigator: {
series: {
includeInHtmlTableExport: false
}
},
rangeSelector: {
buttonTheme: {
width: 70,
height: 20
},
inputEnabled: false,
buttons: [
{
type: 'day',
count: 1,
text: 'Dag'
}, {
type: 'week',
count: 1,
text: 'Uke'
}, {
type: 'month',
count: 1,
text: 'Måned'
}, {
type: 'all',
text: 'All'
}
],
selected: 2
},
yAxis: [
{
id: 'yAxis-consumption',
title: {
text: 'kWh'
}
}
],
title: {
text: null
},
series: [
{
id: 'thisyear',
name: null,
data: null,
type: 'spline',
pointStart: null,
pointInterval: 3600 * 1000,
dataGrouping: {
approximation: "sum",
enabled: true
},
tooltip: {
valueDecimals: 1,
valueSuffix: " kWh"
}
}
]
};
}());
(function() {
var consumption = enoro.namespace("orchard.standard.consumption");
consumption.init();
}());
</script>
使用下面的代码,我可以从一个网址检索新的数据,但我不知道如何使用它,并重新绘制图形。记住我不能编辑的任何代码高于此:
$.getJSON('*url*', function(data) {
// data.data gives the following result: [3.0,2.0,3.0,5.0,8.0]
// How do I apply this data and redraw the graph?
});
目前图形从属性数据系列数据=“[4.0,4.0,3.0,4.0,3.0]”绘制的值。
如何将data.data应用到图形并重绘它?
编辑:
我试过以下,但不工作:
highstockchart.series[0].setData(data.data,true);
如果您执行'$(“#chartContainer”)。data(“serie-data”,“[3.0,2.0,3.0,5.0,8.0]”)会发生什么情况; enoro.namespace(“orchard.standard.consumption”).init();' – mplungjan
我会尝试'Highcharts.charts [0] .series [0] .setData(data.data,true);'。您无法访问'highstockchart'变量。 –