简体   繁体   English

Highcharts中的多个类别和系列

[英]Multiple categories and series in Highcharts

I have been working in an application to visualize in a single chart, multiple vertical profiles of data collected from moored buoys . 我一直在一个应用程序中工作,以便在单个图表中可视化从停泊浮标收集的数据的多个垂直剖面。

An example of this kind of visualization looks like the following example https://jsfiddle.net/ordicu85/9g035cpo/ where the chart shows two vertical profiles of o2_concentration versus the related depth measurements. 这种可视化的示例类似于以下示例https://jsfiddle.net/ordicu85/9g035cpo/ ,其中该图表显示了o2_concentration与相关深度测量的两个垂直剖面。

I need to solve the following issues: 我需要解决以下问题:

  1. Show only a single vertical axis(depth) common for all active series in the legend. 仅显示图例中所有活动系列共有的单个垂直轴(深度)。 It should be adjusted automatically for all active series in teh legend. 应该为图例中的所有活动系列自动调整。

  2. Normalize values in the vertical axis, like for example: 0, 10, 20, 30. 40...instead of all those decimal values. 标准化垂直轴上的值,例如:0、10、20、30、40 ...而不是所有这些十进制值。

Here is the highchart code where categories represent depth measurements and series represent o2_concentration measurements.The first category corresponds to first data serie and the second category target the second data series: 这是高图代码,其中类别表示深度测量,系列表示o2浓度测量。第一个类别对应于第一个数据系列,第二个类别针对第二个数据系列:

let chart = Highcharts.chart('container', {
chart: { type: "line", inverted: true, zoomType: "xy"
},
title: {
    text: 'o2 concentration vs depth'
},
xAxis: [
    {
     categories: [0.38, 1.02, 2.01, 3.06, 4.01, 5.05, 6, 7.05, 8.01, 9.02, 
    10.03, 11, 12.08, 13.04, 14.06, 15.07, 16.02, 17.04, 18.09, 19.03, 
    20.03, 21.04, 22.07, 23.04, 24.04, 25, 26, 27.05, 28.04, 29.06, 30.05], 
     reversed: true, title:{text:'depth'}
    },
    {
     categories: [0.37, 1.01, 2, 3, 4.03, 5.05, 6.03, 7, 8.02, 9.03, 10.01, 
     11.08, 12.03, 13.04, 14.06, 15.04, 16.01, 17, 18.03, 19.05, 20.01, 
     21.11, 22.07, 23.04, 24.09, 25.03, 26.03, 27.06, 28.01, 29.02, 30.07, 
     31, 32, 33.02, 34, 35.05, 36.02, 37.03, 38.04], reversed: true, title:
     {text:'depth'} 
    },
],
yAxis: {
    title: {
        text: 'o2 concentration'
    }
},

series: [{
    name: 'Serie A',
    data: [  95.7, 82.7, 95.4, 96.5, 97.3, 98, 98.4, 98.8, 99.1, 99.4, 99.5, 
    99.6, 99.7, 99.8, 99.9, 100, 100.1, 100.2, 100.2, 100.2, 100.1, 100.1, 
    100, 99.9, 99.9, 100, 100.1, 100.2, 100.2, 100.3, 100.4],
    xAxis:0
}, {
    name: 'Serie B',
    data: [96.7, 85.6, 92, 97.7, 98.1, 98.5, 98.9, 99.3, 99.6, 99.8, 100, 
    100.1, 100.2, 100.3, 100.4, 100.6, 100.9, 101.1, 101.2, 101.1, 101, 
    100.9, 100.9, 101, 101, 101, 101, 101.1, 101.1, 101.1, 101.1, 101.1, 
    101.1, 101.1, 101, 101, 100.9, 100.9, 100.9 ],
    xAxis:1
}]

}); });

Please, i would appreciate any help in those directions, i have been struggling for days with no success. 拜托,我将不胜感激在这些方向上的帮助,我已经努力了好几天没有成功。

You are overriding the default behavior by defining 2 xAxis and setting their categories. 您将通过定义2 xAxis并设置其类别来覆盖默认行为。 To get what you want, let highcharts do it's thing. 要获得想要的东西,就让Highcharts完成它。 You will need to transform your data into {x:val1, y:val2} objects. 您将需要将数据转换为{x:val1,y:val2}对象。 I did it with code, because I am too lazy to type all those numbers. 我用代码来做,因为我懒得键入所有这些数字。

var xAxis1 = [0.38, 1.02, 2.01, 3.06, 4.01, 5.05, 6, 7.05, 8.01, 9.02,
  10.03, 11, 12.08, 13.04, 14.06, 15.07, 16.02, 17.04, 18.09, 19.03,
  20.03, 21.04, 22.07, 23.04, 24.04, 25, 26, 27.05, 28.04, 29.06, 30.05
];
var xAxis2 = [0.37, 1.01, 2, 3, 4.03, 5.05, 6.03, 7, 8.02, 9.03, 10.01,
  11.08, 12.03, 13.04, 14.06, 15.04, 16.01, 17, 18.03, 19.05, 20.01,
  21.11, 22.07, 23.04, 24.09, 25.03, 26.03, 27.06, 28.01, 29.02, 30.07,
  31, 32, 33.02, 34, 35.05, 36.02, 37.03, 38.04
];
var data1 = [95.7, 82.7, 95.4, 96.5, 97.3, 98, 98.4, 98.8, 99.1, 99.4, 99.5,
  99.6, 99.7, 99.8, 99.9, 100, 100.1, 100.2, 100.2, 100.2, 100.1, 100.1,
  100, 99.9, 99.9, 100, 100.1, 100.2, 100.2, 100.3, 100.4
];
var data2 = [96.7, 85.6, 92, 97.7, 98.1, 98.5, 98.9, 99.3, 99.6, 99.8, 100,
  100.1, 100.2, 100.3, 100.4, 100.6, 100.9, 101.1, 101.2, 101.1, 101,
  100.9, 100.9, 101, 101, 101, 101, 101.1, 101.1, 101.1, 101.1, 101.1,
  101.1, 101.1, 101, 101, 100.9, 100.9, 100.9
];

for (var i = 0; i < xAxis1.length; i++) {
  data1[i] = {
    x: xAxis1[i],
    y: data1[i]
  };
}
for (i = 0; i < xAxis2.length; i++) {
  data2[i] = {
    x: xAxis2[i],
    y: data2[i]
  };
}
var chart = Highcharts.chart('container', {
  chart: {
    type: "line",
    inverted: true,
    zoomType: "xy"
  },
  title: {
    text: 'o2 concentration vs depth'
  },
  xAxis: [{
    reversed: true,
    title: {
      text: 'depth'
    }
  }, ],
  yAxis: {
    title: {
      text: 'o2 concentration'
    }
  },

  series: [{
    name: 'Serie A',
    data: data1

  }, {
    name: 'Serie B',
    data: data2

  }]
});

https://jsfiddle.net/9g035cpo/2/ https://jsfiddle.net/9g035cpo/2/

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

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