Highcharts.js看不到图线

时间:2016-06-23 11:41:54

标签: javascript jquery highcharts

我正在使用localhost上的highcharts.js制作折线图。

我已尝试实施超过20,000条记录,但效果很好 喜欢魅力。

但我有一个json文件,其中包含11,000条记录,但由于某些原因 不明原因,当我运行它时,它没有显示图形线。

如果我放一张显示我不到三千条记录的支票 我看到了这条线。

只需将代码复制粘贴到html文件中即可。

<!DOCTYPE html>
<html>

<head>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>

</head>

<body style="background:#212224;">

<div id="container" style="max-width: 1666px;  margin: 0 auto"></div>
<button id="button">Destroy the chart</button>
<button id="create">create the chart</button>


<script type="text/javascript">

      $('#button').click(function () {
        $('#container').highcharts().destroy();
            });

     $('#create').click(function (){
    $.getJSON('https://dl.dropboxusercontent.com/u/76618626/data2.json', function (data) {
        console.log("data size is : ");
        console.log(data.data.length);      

        var data3 = [];

        //you can comment this loop and uncomment the loop below for working code.      
        $.each(data.data,function(i,d){
            data3.push([new Date(d.timestamp).getTime(),d.value])
            });

        //below is commented code which works for 3000 records.

        //$.each(data.data,function(i,d){
        //if(i<3000){
        //      data3.push([new Date(d.timestamp).getTime(),d.value])
        //      }
        //});



        console.log(data3);

        $('#container').highcharts({

            chart: {
            backgroundColor: '#000000',
                },

            title: {
                text: 'Test Graph',
                style: {
                color: '#FFFFFF',
                fontWeight: 'bold'
                }
            },
            xAxis: {
                type: 'datetime',
                title: {
                    text: 'Time Stamp'
                },
                gridLineColor: 'grey',
                gridLineWidth: 1,
                lineWidth:1

            },
            yAxis: {
                title: {
                    text: 'Value'
                },
                gridLineColor: 'grey',
                gridLineWidth: 1,
                lineWidth:1
            },
            legend: {
                enabled: true
            },

            exporting: false,



            plotOptions: {
                line: {                 
                    lineColor: 'red',
                    fillOpacity: 1,                    
                    lineWidth: 2,
                    states: {
                        hover: {
                            lineWidth: 2
                        }
                    },
                    threshold: null,
                    marker: {
                        fillColor: '#e57255'
                        }


                },


            },


            series: [{
                type: 'line',
                name: 'test',
                data: data3
            }]
        });
    });
});
</script>
</body>
</html>  

1 个答案:

答案 0 :(得分:1)

确保所有数据格式正确,目前数据格式不正确。您可以使用以下内容进行快速检查:

$.each(data.data,function(i,d){
    // Return if value is not a number
    if (isNaN(parseInt(d.value))) return;
    data3.push([new Date(d.timestamp).getTime(),d.value])
});

Updated Fiddle