【问题标题】:csv live data highchartcsv实时数据highchart
【发布时间】:2016-02-22 11:31:20
【问题描述】:

我的数据无法正确显示。 我有这样的数据:“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,所以我不知道我做错了什么。 需要解析吗?

【问题讨论】:

标签: javascript csv highcharts


【解决方案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)'
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    相关资源
    最近更新 更多