javascript - highchart json 数据点

标签 javascript json highcharts datapoint

我为这件事伤透了脑筋。

我有一个包含 Json 数据的图表。现在想将 Json 数据拆分为 2 个数据点。

json data;
[1340283205000,5,32]

Explanation
time, number, number

当前图表适用于时间、数字。现在我添加了另一个数据点,但 dows 不起作用。

function requestData() {
        $.ajax({
            url: 'php/hits_json.php', 
            success: function(point) {
                var series = chart1.series[0],
shift = series.data.length > 20; // shift if      the series is longer than 20

                // add the point
                chart1.series[0].addPoint(eval(point), true, shift);

                // call it again after one second
                setTimeout(requestData, 5000);  
            },
            cache: false
        });
    }

    $(document).ready(function() {
        window.chart1 = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                defaultSeriesType: 'areaspline',
                events: {
                    load: requestData
                }
            },
            title: {
                text: 'Hits per 5 sec'
            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 100,
                maxZoom: 10 * 10000
            },
            yAxis: {
                min: 0,
                minPadding: 0.25,
                maxPadding: 0.1,
                title: {
                    text: 'Hits',
                    margin: 40
                }
            },
    plotOptions: {
                series: {
                    dataLabels: {
                        enabled: true
                            },
                    marker: {
                        enabled: true
                            },
                        }
                    },
        credits: {
                enabled: false
                    },
            series: 

            [{
                name: 'Hits',

                data: [0],lineWidth: 1
            },{
                        name: 'Requests',
                        data: [0],lineWidth: 1
            }]
        });     
    });

有人可以指出正确的方向来解决我的问题:)

提前致谢

最佳答案

您的 json 中没有标记数据。所以前两个值被视为 x 和 y,第三个被忽略。要正确格式化您的数据,请执行以下操作:

var json = [
{
  "x":1340283205000,
  "y":5
}, 
{
  "x":1340283205000,
  "y":32
}];

关于javascript - highchart json 数据点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11138733/

相关文章:

javascript - fastify-plugin 的具体用途是什么

c# - 整个类型的 Json.NET 条件序列化

javascript - Object.assign 嵌套属性

highcharts - Highcharts不会显示具有大量数据点的系列

javascript - 如何在突出显示的国家周围设置边界但高 map 中的填充颜色没有变化?

javascript - Bootstrap Carousel 不工作(显示页面上的所有元素)

javascript - 合并数组内多个对象的值

javascript - 为什么我从 here-string 中收到 "not a cmdlet"错误?

ruby - 是否可以将 JSON 字符串转换为对象?

angular - 在 ionic 3 中使用仪表