gpt4 book ai didi

Highcharts |制作多个 y 轴比例

转载 作者:行者123 更新时间:2023-12-04 22:56:22 25 4
gpt4 key购买 nike

我试图让这个图表有多个 Y 轴,所有这些都具有不同的值和刻度间隔。就像信号强度在 0%-100% 的范围内一样,温度 0F-100F 和主电源是 0V 到 25V,但似乎无法弄清楚。这是我的 jFiddle:
http://jsfiddle.net/0k5k8ygz/

代码:

function createChart() {

Highcharts.stockChart('container', {

rangeSelector: {
selected: 4
},

yAxis: [{ // Primary yAxis
labels: {
format: '{value}°F',
style: {
color: Highcharts.getOptions().colors[2]
}
},
title: {
text: 'Temperature',
style: {
color: Highcharts.getOptions().colors[2]
}
},
opposite: true

}, { // Secondary yAxis
gridLineWidth: 0,
title: {
text: 'Main Power',
style: {
color: Highcharts.getOptions().colors[0]
}
},
labels: {
format: '{value} volts',
style: {
color: Highcharts.getOptions().colors[0]
}
}

}, { // Tertiary yAxis
gridLineWidth: 0,
title: {
text: 'Signal Strength',
style: {
color: Highcharts.getOptions().colors[1]
}
},
labels: {
format: '{value} %',
style: {
color: Highcharts.getOptions().colors[1]
}
},
opposite: true
}],

plotOptions: {
series: {
compare: 'percent',
showInNavigator: true
}
},

tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2,
split: true
},

series: seriesOptions
});
}


$.each(names, function(i, name) {

$.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=' + name.toLowerCase() + '-c.json&callback=?', function(data) {

seriesOptions[i] = {
name: name,
data: data
};

// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter += 1;

if (seriesCounter === names.length) {
createChart();
}
});
});

最佳答案

如果您向每个 y 轴添加一些数据,它们将自动获得刻度线。您可以使用 series.yAxis 将数据分配到特定的 y 轴指数:

seriesOptions[i] = {
name: name,
data: data,
yAxis: i,
};

如果您还想为 y 轴指定一个有效范围,您可以设置 minmax在每个单独的轴上:
...
labels: {
format: '{value} volts',
},
min: 0,
max: 25,
...

http://jsfiddle.net/0k5k8ygz/5/

关于 Highcharts |制作多个 y 轴比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44269617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com