gpt4 book ai didi

javascript - 如何在 Highcharts 中显示多个 "dataMax"?

转载 作者:行者123 更新时间:2023-12-03 00:14:13 24 4
gpt4 key购买 nike

目前,我正在折线图中显示最大值点。但我想将 dataMax 更改为图表中的前 5 个最大值点。如何在 Highcharts 中实现此目的?

var defaultData = 'urlto.csv';
var urlInput = document.getElementById('fetchURL');
var pollingCheckbox = document.getElementById('enablePolling');
var pollingInput = document.getElementById('pollingTime');

function createChart() {
Highcharts.chart('closed5', {
chart: {
type: 'area',
zoomType: 'x'
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
style: {},
formatter: function() {
if (this.y === this.series.dataMax) {
return this.y;
}
}
}
}
},
title: {
text: 'Chart for charting'
},
data: {
csvURL: urlInput.value,
enablePolling: pollingCheckbox.checked === true,
dataRefreshRate: parseInt(pollingInput.value, 10)
}
});

if (pollingInput.value < 1 || !pollingInput.value) {
pollingInput.value = 1;
}
}

urlInput.value = defaultData;

// We recreate instead of using chart update to make sure the loaded CSV
// and such is completely gone.
pollingCheckbox.onchange = urlInput.onchange = pollingInput.onchange = createChart;

// Create the chart
createChart();

最佳答案

@ewolden 正确地注意到,您可以对数据进行排序并仅显示五个最高值:

var data = [11, 22, 33, 44, 55, 66, 15, 25, 35, 45, 55, 65],
sortedData = data.slice().sort(function(a, b){
return b - a
});

Highcharts.chart('container', {
series: [{
data: data,
dataLabels: {
enabled: true,
formatter: function() {
if (sortedData.indexOf(this.y) < 5) {
return this.y;
}
}
}
}]
});

现场演示:http://jsfiddle.net/BlackLabel/xkf2w5tb/

API:https://api.highcharts.com/highmaps/series.mapbubble.dataLabels.formatter

关于javascript - 如何在 Highcharts 中显示多个 "dataMax"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54588853/

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