csv实时数据高图

时间:2016-02-22 11:31:20

标签: javascript csv highcharts

我的数据无法正常显示。 我有这样的数据:" 1456135353.000000 | 5424492576222277 | 8156610153681827"

" 1456135353"是时候了。

" 5424492576222277"是第一个X

" 8156610153681827"是第二个X

这是我的代码:

    var chart

/**
 * Request data from the server, add it to the graph and set a timeout
 * to request again
 */
function requestData () {
    $.ajax({
    url: 'api/chart',
          dataType: 'text',
        success: function (point) {
            var series = chart.series[0].push
                                                 // longer than 20
            // add the point
            chart.series[0].addPoint(point, true)
            // call it again after one second
            setTimeout(requestData, 1000)
        },
        cache: false
    })
}

$(document).ready(function () {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            defaultSeriesType: 'line',
            events: {
                load: requestData
            }
        },
        title: {
            text: 'XSnews Graph'
        },
        xAxis: {
            type: 'datetime',
            tickPixelInterval: 150,
            maxZoom: 20 * 1000
        },
        yAxis: {
            gridLineColor: '#197F07',
            gridLineWidth: 1,
            title: {
                text: 'GB',
                margin: 80
            }
        },
        series: [{
            name: 'Time',
            data: []
        }]
    })
})

我对Highcharts不熟悉所以我不知道我做错了什么。 我需要解析吗?

1 个答案:

答案 0 :(得分:1)

在添加点之前,您需要先解析数据。像这样:

success: function (point) {
    var options = point.split("|"),
        x = parseFloat(options[0]) * 1000,
        y_1 = parseFloat(options[1]),
        y_2 = parseFloat(options[2]);

    chart.series[0].addPoint([x, y_1], true);
    setTimeout(requestData, 1000)'
}