如何在一个 ZingChart 图表中绘制周对周图形?

7
我在尝试将两条线图绘制在一个ZingChart图表上,但我不知道应该以什么样的格式传递数据。

基本上,我有一个时间戳/整数对数组,用于今天和一周前的数据,间隔为一小时,例如:

today = [[timestamp1, 1], [timestamp2, 4], ......, [timestamp18, 7]] <-- 假设现在是下午6点,所以没有其余一天的数据

week_ago = [[timestamp1, 4], [timestamp2, 7], ......, [timestamp23, 1]] <-- 全24小时数据

x轴应显示从00:00到23:00的小时,y轴只是整数。 此外,我希望在每个图形点上,工具提示显示日期和整数值。

这听起来非常简单,实际上也是如此,但因为我对ZingChart还比较陌生,所以无法想出解决方法。

非常感谢

1个回答

7

您是想要这样做吗?我使用了两个 series 对象来包含我的数据:第一个包含今天的时间序列数据,第二个包含上周的时间序列数据。有关 时间序列数据和刻度的更多信息,请参见此处

接下来,我创建了两个 x 轴刻度scaleX 绑定到第一个 series 对象(今天的数据),scaleX2 绑定到第二个 series 对象(或上周的数据)。您可以选择“混合”两个刻度,使它们出现在同一轴线上(但这在 y 轴上更常见)。或者您可以关闭第二个 x 轴的可见性,这就是我在下面的演示中所做的。

当然,您可以使用工具提示(在此演示中关闭)、十字线和/或图例来进一步解释您的数据。

var myConfig = {
  type: 'line',
  utc: true, //If set to false, this will default to UTC time.
  timezone: -5, //Currently set to EST time. You can specify your desired time zone.
  scaleX: {
    minValue: 1471496400000,
    maxValue: 1471579200000,
    step: 'hour',
    transform: {
      type: 'date',
      all: '%g%a'
    },
    label: {
      text: 'X-Axis'
    },
    item: {
      fontSize: 10
    }, 
    maxItems: 24
  },
  scaleX2: {
    minValue: 1470891600000,
    maxValue: 1470974400000,
    placement: 'default',
    blended: true,
    visible: false,
    step: 'hour',
    transform: {
      type: 'date',
      all: '%g%a'
    },
    item: {
      fontSize: 10
    }, 
  },
  scaleY: {
    values: '0:10:1',
    label: {
      text: 'Y-Axis'
    },
    item: {
      fontSize: 10
    },
    guide: {
      lineStyle: 'solid'
    }
  },
  plot: {
    tooltip: {
      visible: false
    }
  },
  crosshairX: {
    plotLabel: {
      multiple: true
    }
  },
 series: [
  { //Today, or 08/18/16 until 6am
    scales: 'scaleX, scaleY',
    values: [
      [1471496400000, 3], //08/18/16 at midnight, EST time
      [1471500000000, 7], //1am
      [1471503600000, 5], //2am
      [1471507200000, 9], //3am
      [1471510800000, 4], //4am
      [1471514400000, 5], //5am
      [1471518000000, 2] //6am
    ],
    text: 'Today'
  },
  { //Last Thursday, or 08/11/16, all 24 hours
    scales: 'scaleX2, scaleY',
    values: [
      [1470891600000, 5], //08/11/16 at midnight, EST time
      [1470895200000, 6], //1am
      [1470898800000, 4], //2am
      [1470902400000, 9], //3am
      [1470906000000, 1], //4am
      [1470909600000, 5], //5am
      [1470913200000, 6], //6am
      [1470916800000, 3], //7am
      [1470920400000, 5], //8am
      [1470924000000, 7], //9am
      [1470927600000, 8], //10am
      [1470931200000, 2], //11am
      [1470934800000, 3], //12am
      [1470938400000, 1], //1pm
      [1470942000000, 4], //2pm
      [1470945600000, 6], //3pm
      [1470949200000, 7], //4pm
      [1470952800000, 3], //5pm
      [1470956400000, 5], //6pm
      [1470960000000, 6], //7pm
      [1470963600000, 2], //8pm
      [1470967200000, 3], //9pm
      [1470970800000, 5], //10pm
      [1470974400000, 4] //11pm
    ],
    text: 'Last Week'
  }
 ],
 legend: {
   align: 'center',
   verticalAlign: 'bottom',
   marker: {
     type: 'circle',
     size: 4,
     showLine: true
   },
   borderWidth: 1
 }
};
zingchart.render({ 
 id : 'myChart', 
 data : myConfig, 
 height: 400, 
 width: 600
});
<head>
  <script src= "https://cdn.zingchart.com/zingchart.min.js"></script>
 </head>
 <body>
  <div id='myChart'></div>
 </body>

希望这能有所帮助。我是ZingChart团队的成员,如果您有进一步的问题,请告诉我。熟悉我们的比例尺教程应该为使用我们的库打下良好的基础。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接