Highcharts - 由第三个元素在“隐藏”图中连续导航 [英] Highcharts - navigation by 3rd element in series 'hidden' in plot

查看:276
本文介绍了Highcharts - 由第三个元素在“隐藏”图中连续导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些这种格式的信息(速度,频率,日期)。发生什么事情是我需要用速度x频率来绘制这张图表,但是我想让用户使用日期的导航过滤功能,这个功能并没有出现在图表上。
$ b $另外,我还有一些不是动态构建的信息,这是速度x频率的限制。此信息将作为参考点固定在图上。所以,当我过滤的情节信息(而不是限制),它必须始终显示这些极限情节。

你可以有一个想法,通过这个图表,区域图显示点(速度,频率)的限制。然后,我将添加速度点x频率(x日期),然后按日期过滤。



我会考虑使用一个导航器作为一个单独的图表,那么你将不需要在主图表中的第二个x轴和系列,你不需要使它们看起来不可见。



例如只有导航器的图表在这里: http://jsfiddle.net/f7Y9p/


I have some info which is in this format (speed, frequency, date). What happens is that I need to plot this chart with speed x frequency, but I want to allow the users to use the navigation filtering by the date, which is not appearing on the chart.

Also, I have some info which is not built dynamically, which is the limits of speed x frequency. This info will be fixed as reference points on the plot. So, when I filter the plot info (not the limits), it must always display these limit plots.

You can have an idea by this chart, the area plots show the limits for the points (speed, frequency). Then, I would add points of speed x frequency (x date), and filter then by date.

Can you guys give me some advice on this?

here is a JSFIDDLE

JSFIDDLE

data: [
                [0, 20, here is a date], [10, 20,here is a date],
                [50, 39.9994, here is a date], [100,49.7494, here is a date]
            ],

Guys, notice that every element of the array in the series has 3 elements [a, b, c], suppose the third one (c) is a DATE and not a random number as it is right now. I want to be able to use the commented the navigator code to filter this series by this C element, which doesn't in fact appear on the chart you see, it is a hidden element, just to filter the data.

解决方案

There will be a little tricky, if you want to have a navigator in the same chart. Navigator works only with datetime data and it must be connected with the axis from the main chart.

So, you have data in that format:

var points = [
  [5, 9, Date.UTC(2016, 1, 0)],
  [65, 6, Date.UTC(2016, 1, 1)],
  ...

You need two x axes - one which represents the data and the other which is connected to the navigator. The second axis must be visible to work with the navigator and must be connected with the datetime data.

So now, except two x axes, you need two series - one with the actual data, and the other consists of [date, y] values from the first series. The additional data will be visible in the navigator - note, that in the navigator you cannot use scatter series - so it will be converted to line series - to happen it without errors, your data should be sorted by date.

series: [{
  id: 'main-series',
  data: points.map(function(point) {
    return [point[0], point[1], point[2], point[1]]
  }),
  showInNavigator: false,
  xAxis: 1,
  keys: ['x', 'y', 'date', 'holdY'] //holdY is for easier hiding points
}, {
  xAxis: 0,
  data: points.map(function(point) {
    return [point[2], point[1]];
  }),
  showInNavigator: true,
  enableMouseTracking: false,
  color: 'transparent',
  showInLegend: false
}],

xAxis: [{
  minRange: 1000 * 3600 * 24,
  type: 'datetime',
  tickLength: 0,
  tickLength: 0,
  labels: {
    enabled: false
  },
}, {
  type: 'linear'
}],

The last thing you need a callback which will hide/show points after the extremes in the navigator are set. Hiding/showing depends on the third point's property which is date. There is no directly API to hide/show specific points (except pie), but it can be achieved by setting point's value to null (that is why I preserved the real y in holdY).

events: {
  afterSetExtremes: function(e) {
    var points = this.chart.get('main-series').points;
    points.forEach(function(point) {
      point.update({
        y: e.min <= point.date && point.date <= e.max ? point.holdY : null
      }, false, false);
    });
    this.chart.redraw();
  }
}

example: https://jsfiddle.net/3wuwdonn/1/

I would consider using a navigator as a separate chart, then you wouldn't need the second x axis and series in the main chart and you wouldn't need to make them look invisible.

example with a navigator only chart here: http://jsfiddle.net/f7Y9p/

这篇关于Highcharts - 由第三个元素在“隐藏”图中连续导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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