javascript - 仅使用 JavaScript 更新现有 Highstock 图表的数据

标签 javascript jquery highcharts

我正在编辑一个网站,但无法访问原始代码,我所能做的就是将代码附加到其末尾。我无法访问 PHP(我想我也不需要它)。

这是现有的代码:

<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>

使用以下代码,我可以从 URL 检索新数据,但我不确定如何应用它并重新绘制图表。请记住,我无法编辑上面的任何代码:

$.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?
});

当前图表从属性 data-serie-data="[4.0,4.0,3.0,4.0,3.0]"中绘制值。

如何将 data.data 应用到图表并重新绘制它?

编辑:

我尝试了以下方法,但不起作用:

highstockchart.series[0].setData(data.data,true);

最佳答案

在 Chrome 控制台的/Meter/Conspiration 页面上,您应该能够粘贴以下内容,并且它应该突出显示最高的 4 个值:http://pastebin.com/4RzYXcBh

关于javascript - 仅使用 JavaScript 更新现有 Highstock 图表的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35628369/

相关文章:

javascript - 对象文字速记语法。尾随逗号需要吗?

javascript - 如何将原型(prototype)应用于现有对象

javascript - 使用 Javascript 和 Jquery 正确的 Img Src 路径

javascript - window.addEventListener 中的延迟

javascript - UIWebView 下载它的图片内容

javascript - 自定义工具提示,使烛台保持原样

javascript匹配两个数组然后显示最大值

javascript - 2个键值对象js之间的数学差异

c# - 如何访问 CheckBoxList 中 ListItems 的键

javascript - 平移多个 Y 轴之一以获取 Highcharts