Reputation: 1449
I have question regarding series name, How can i set static series name to the element based on the categories in the HighChart.
The expected output will be like this:
As of now I have result on my web app.
Is it possible to change that Series1,Series2,Series3 based on what I want to put on the Series name?
I have here my codes:
categories = [],
series = [];
$.getJSON('ajax/ams_sla_report_chart.php', function(data,name){
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({
name:['MR','MR_HIT','MR_HIT_PERCENTAGE'],
data: [el]
});
}
});
});
var chart = new Highcharts.Chart({
chart: {
renderTo: 'containers',
type: 'column',
inverted: false
},
legend: {
layout: 'horizontal',
align: 'right',
verticalAlign: 'middle'
},
xAxis: {
categories: categories
},
title: {
text: 'Priority Based on SLA'
},
series:series
});
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();
});
Upvotes: 0
Views: 32
Reputation: 39069
You need to define the series names array outside of the loop and use only one name in the loop:
var seriesNames = ['MR', 'MR_HIT', 'MR_HIT_PERCENTAGE'],
...
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({
name: seriesNames[i - 1],
data: [el]
});
}
});
});
Live demo: http://jsfiddle.net/BlackLabel/ewauprqh/
Upvotes: 1