Reputation:
I am making a graph with multiple series parsed through json from a mysql database. I want, the graph to only display one serie from start. HighChart there is an option doing exactly that, example below:
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
visible: false
},
Since my series is defined: series: []
I have not been able to work out how to adresse those series I want not visible. I am trying to learn by adapting tutorials to my own projects.
Here is my code
var options;
$(document).ready(function() {
options = {
chart: {
renderTo: 'container',
type: 'spline'
},
title: {
text: 'Graf'
},
subtitle: {
text: ''
},
xAxis: {
categories: [],
labels: {
step: 6
}
},
title: {
text: 'Grafisk fremstilling af den valgte dag',
y: 10,
margin: 20
},
tooltip: {
enabled: true,
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
plotOptions: {
series: {
marker: {
enabled: false
}
}
},
series: []
}
$.getJSON("dataNew.php", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
options.series[3] = json[4];
options.series[4] = json[5];
chart = new Highcharts.Chart(options);
});
});
$(function() {
$( "#datepicker" ).datepicker({
dateFormat: "yy-mm-dd",
showOn: "button",
buttonImage: "calendar.gif",
buttonImageOnly: true,
onSelect: function(dateText, inst) {
$.getJSON("dataNew.php?dateParam="+dateText, function(json){
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
options.series[3] = json[4];
options.series[4] = json[5];
chart = new Highcharts.Chart(options);
});
}
});
});
</script>
Upvotes: 0
Views: 448
Reputation: 11
I've done it by hiding the series after the chart has been drawn.
So, you've got this code where you get your JSON:
$.getJSON("dataNew.php?dateParam="+dateText, function(json){
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
options.series[3] = json[4];
options.series[4] = json[5];
chart = new Highcharts.Chart(options);
});
What I've done to make hide a specific series is to add the following after the chart draws:
chart.series[i].hide();
In your example, if you want to hide your second series, your code would look like:
$.getJSON("dataNew.php?dateParam="+dateText, function(json){
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
options.series[3] = json[4];
options.series[4] = json[5];
chart = new Highcharts.Chart(options);
chart.series[1].hide();
});
I think that should do it.
Upvotes: 1