简体   繁体   English

高图中不相关的图线

[英]Irrelevant graph lines in highchart

I have a made of chart of temperature and time using highcharts, but when i click the range of 1 week,3 day or 1 day. 我使用高图制作了温度和时间图表,但是当我单击1周,3天或1天的范围时。 the chart get messy on some points and draw irrelevant graph lines in the chart like this in the picture below. 图表在某些点上变得凌乱,并在图表中绘制了不相关的图形线,如下图所示。

You can also check it on jsfiddl e Demo . 您也可以在jsfiddl e Demo 上进行检查

You can find the data of the chart on this link Data . 您可以在此链接 Data 上找到图表 数据

图片

Code

<!DOCTYPE html>
<html>
<head>
    <title></title>
     <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/highcharts-more.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="https://code.highcharts.com/stock/modules/export-data.js"></script>
<style>
@import 'https://code.highcharts.com/css/highcharts.css';

#container {
    height: 400px;
    max-width: 800px;
    margin: 0 auto;
}
.highcharts-xaxis-grid .highcharts-grid-line {
    stroke-width: 2px;
    stroke: #d8d8d8;
}
.highcharts-xaxis .highcharts-tick {
    stroke-width: 2px;
    stroke: #d8d8d8;
}
.highcharts-minor-grid-line {
    stroke-dasharray: 2, 2;
}
</style>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>



</body>
</html>
<script type="text/javascript">
// Notice that the dataset has missing data
$.getJSON('https://api.myjson.com/bins/m5imk', function (data) {

  Highcharts.stockChart('container', {

    chart: {
      type: 'spline'
    },
    rangeSelector: { enabled: false },
                scrollbar: { enabled: false },
     xAxis: {
         gridLineColor: '#f44242',
        minorTickInterval: 'auto',
        startOnTick: true,
        endOnTick: true
    },
    yAxis: {
        gridLineColor: '#f44242'
    },
    rangeSelector: {
      buttons: [
      {
        type: 'day',
        count: 1,
        text: '1d'
      },
      {
        type: 'day',
        count: 3,
        text: '3d'
      }, {
        type: 'week',
        count: 1,
        text: '1w'
      }, {
        type: 'month',
        count: 1,
        text: '1m'
      }, {
        type: 'month',
        count: 6,
        text: '6m'
      }, {
        type: 'year',
        count: 1,
        text: '1y'
      }, {
        type: 'all',
        text: 'All'
      }],
      selected: 3
    },

    title: {
      text: 'Temperature variation by day'
    },

    tooltip: {
      valueSuffix: '°C',
      valueDecimals: 1,
    },

    series: [{
      name: 'Temperatures',
      data: data,
      color: '#BF0B23',

        marker: 
        {
            fillColor: 'blue',
            lineWidth: 0

        }
    }]

  });
});



</script>

You have Highcharts Error #15 in a console, which means that you have unsorted data: https://www.highcharts.com/errors/15/ . 控制台中出现Highcharts Error #15 ,这意味着您没有未排序的数据: https : //www.highcharts.com/errors/15/

You need to sort your data before creating the chart: 您需要在创建图表之前对数据进行排序:

data.sort(function(a, b) {
    return a[0] - b[0]
});

Live demo: https://jsfiddle.net/BlackLabel/wtc0pfu8/ 现场演示: https : //jsfiddle.net/BlackLabel/wtc0pfu8/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM