gpt4 book ai didi

php - 如何创建具有 3 个不同系列类别名称的 Highcharts

转载 作者:行者123 更新时间:2023-12-01 04:35:50 24 4
gpt4 key购买 nike

我目前正在新创建一个 highcart,我只是想知道这些是否可以在 highcart 中实现。我想创建一个包含 3 个类别的购物车

3 个类别:

  1. 低优先级
  2. 中优先级
  3. 高优先级

所以,如果我的类别是 3,那么栏也是 3,并且具有不同的名称和不同的数据。

在我的 console.log 中显示数据结果。

result

我的输出: wrong output

我的函数代码:

$.getJSON('ajax/ams_sla_report_chart.php', function(data,name){
console.log(data);
var json_data = "";
var json_name = "";
var chart = new Highcharts.Chart({
chart: {
renderTo: 'containers',
type: 'column',
inverted: false
},
legend: {
layout: 'horizontal',
align: 'right',
verticalAlign: 'middle'
},
yAxis: {
title: {
text: 'SLA PERCENTAGE'
}

},
title: {
text: 'Priority Based on SLA'
},

series:[{
name:'Low Priority',
colorByPoint: true,
data:data[0]
},

{
name:'Medium Priority',
colorByPoint: true,
data:data[1]
},


{
name:'High Priority',
colorByPoint: true,
data:data[2]
},


]
});


json_data = chart.series.data = data;



function showValues() {
$('#alpha-value').html(chart.options.chart.options3d.alpha);
$('#beta-value').html(chart.options.chart.options3d.beta);
$('#depth-value').html(chart.options.chart.options3d.depth);
}

// Activate the sliders
$('#sliders_eng input').on('input change', function () {
chart.options.chart.options3d[this.id] = parseFloat(this.value);
showValues();
chart.redraw(false);
});

showValues();


});

输出必须是:

Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'SLA BASED ON PRIORITY AND PERCENTAGE OF HIT'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: [
'Low',
'Medium',
'High',
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'SLA BASED ON PERCENTAGE (mm)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y}</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'CLOSE MR',
data: [49.9, 71.5, 106.4]

}, {
name: 'OPEN MR',
data: [83.6, 78.8, 98.5]

}, {
name: 'TOTAL MR HIT',
data: [48.9, 38.8, 39.3]

}, {
name: 'TOTAL MR HIT AVERAGE',
data: [50, 38.8, 39.3]

}]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

最佳答案

您需要将数据预处理为 Highcharts 所需的格式:

var data = [
['Low Priority', 100, 9],
['Medium Priority', 100, 2],
['High Priority', 100, 1]
],
categories = [],
series = [];

data.forEach(function(arr) {
arr.forEach(function(el, i) {
if (i === 0) {
categories.push(el);
} else if (series[i - 1]) {
series[i - 1].data.push(el)
} else {
series.push({
data: [el]
});
}
});
});


Highcharts.chart('container', {
...
series: series
});

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

关于php - 如何创建具有 3 个不同系列类别名称的 Highcharts ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56181619/

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