Highcharts在某些缩放级别不显示数据 [英] Highcharts not displaying data at some zoom levels

查看:190
本文介绍了Highcharts在某些缩放级别不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Highcharts / Highstock绘制相当大量的数据(〜10,000点)。数据由X轴上的Date对象组成,并在Y上浮动,格式如下: [[(date),1.728],[(date),0.346],...] 。日期总是相隔1小时,并且数据中没有空白。

I'm using Highcharts/Highstock to plot a fairly large amount of data (~10,000 points). The data consists of Date objects on the X axis and floats on the Y, formatted as such: [[(date), 1.728], [(date), 0.346], ...]. The dates are always 1 hour apart and there are no gaps in the data.

当图表的范围> = 21天时(至少21天的数据是图表),图表正确显示。但是,只要范围小于此值,图表就会变为空白,并且工具提示将每个点显示为具有0.0的Y值。这些点的Y值存在于数组中(我可以在Firebug中看到它们),但它们不显示在图表上。下面是我如何初始化它:

When the chart's range is >= 21 days (such that at least 21 days of data is graphed), the chart appears correctly. Whenever the range is less than that, though, the chart becomes blank and the tooltip displays each point as having a Y-value of 0.0. The Y values for those points do exist in the array (I can see them in Firebug), but they aren't displayed on the chart. Here's how I'm initializing it:

mainChart = new Highcharts.StockChart({
  chart: {
    renderTo: 'linegraph'
  },

  rangeSelector: {
    buttons: [{
      type: 'day',
      count: 1,
      text: '1 d'
    }, {
      type: 'week',
      count: 1,
      text: '1 wk'
    }, {
      type: 'month',
      count: 1,
      text: '1 mo'
    }, {
      type: 'year',
      count: 1,
      text: '1 yr'
    }, {
      type: 'all',
      text: 'All'
    }],
    selected: 2
  },

  series: [{
    name: 'Electricity usage (kWh)',
    data: graphData,
    tooltip: {
      valueDecimals: 2,
      valueSuffix: "kWh"
    }
  }],
});


推荐答案

事实证明,您不能使用Date数据的X轴。相反,使用日期的Unix时间戳: Date.getTime()。主要道具为FloppyDisk指向正确的方向。

It turns out that you can't use Date in the X axis of your data. Instead, use the Unix timestamp of the date: Date.getTime(). Major props to FloppyDisk for pointing me in the right direction.

这篇关于Highcharts在某些缩放级别不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆