I need to include pagination for my chart (Bar). so that i can control the number of bars that can be displayed. Has anyone tried this earlier?
If this can be achieved, Anyone help me to sort this out.
The basic idea behind changing the 'data' of your chart is to update the series information for it. So that as you press the pagination buttons for your chart, you update the series data directly.
I put together a simple fiddle example based on another question I answered previously.
Check it out here: http://jsfiddle.net/Robodude/EmMxH/71/
html:
<SELECT id="list">
<OPTION VALUE="A">Data Set A
<OPTION VALUE="B">Data Set A + B
<OPTION VALUE="C">Data Set A + B + C
</SELECT>
<button id="change">Change Data Source</button>
<div id="container" style="height: 400px"></div>
Javascript/Jquery:
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'column'
},
series: []
};
$("#change").click(function(){
if ($("#list").val() == "A")
{
options.series = [{name: 'A', data: [1,2,3,2,1]}]
}
else if ($("#list").val() == "B")
{
options.series = [{name: 'A', data: [1,2,3,2,1]},{name: 'B', data: [3,2,1,2,3]}]
}
else if ($("#list").val() == "C")
{
options.series = [{name: 'A', data: [1,2,3,2,1]},{name: 'B', data: [3,2,1,2,3]},{name: 'C', data: [1,1,1,1,1]}]
}
var chart = new Highcharts.Chart(options);
});
This is the previous question I helped answer: Reload chart data via JSON with Highcharts
Obviously, this is a pretty straight forward example. If you update your post with more information, I can possibly expand on this further.
Good luck :)
The other way to do this would be to make use of axis.setExtremes to zoom into the first page then you update the parameters for the prev/next page so rather than the chart refreshing it actual moves left/right.
Pagination in highcharts can be achieved easily, using an extra plugin, Jquery pagination plugin.
I found this forum post informative and helpful.
function pageselectCallback(page_index, jq){
var items_per_page = 3,
max_elem = 5,
from = page_index * items_per_page,
to = from + max_elem,
newcontent = '',
chartData = [];
//pie.series[0].setData( data.slice(from,to) );
if(typeof pie !== 'object') {
pie = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
series: [{
data: []
}]
});
}
pie.series[0].setData( data.slice(from, to) );
// Prevent click eventpropagation
return false;
}
And an working demo is here.
Related
I build a drillable heatmap with Highchart. It's working well but I need to enhance the capabilities of drilldown on it.
You can see the demo here : https://jsfiddle.net/vegaelce/7wc6t2ex/
I would like to be able to drill on the Y Axis and on the X Axis on specific series.
In the example, by clicking on "California" axis label, I would like the chart drill on 'California_years' drilldown serie.
In the same way, I'd like to be able to click on X-Axis, in the example, by clicking on '2015' label value, the chart would drill to 'States_2015' drilldown serie.
Notice that I use axe_x and axe_y values in each serie to change the axis of the chart on drilldown/drillup event :
events:{
drilldown: function(e) {
var chart = this;
chart.yAxis[0].update({
type: 'category',
categories: y_axes[e.seriesOptions.axe_y]
});
chart.xAxis[0].update({
type: 'category',
categories: x_axes[e.seriesOptions.axe_x]
});
},
drillup: function(e) {
var chart = this;
chart.yAxis[0].update({
type: 'category',
categories: y_axes[e.seriesOptions.axe_y]
});
chart.xAxis[0].update({
type: 'category',
categories: x_axes[e.seriesOptions.axe_x]
});
}
}
How can I achieve these features ?
Thanks
You can check if e.category is defined, if it is, the drilldown was triggered by clicking on axis label. Next, you need to only bind the category with proper drilldown options. For example:
chart: {
type: 'heatmap',
events: {
drilldown: function(e) {
if (typeof e.category !== 'undefined') {
if (e.category === 0) {
e.seriesOptions = this.options.drilldown.series[3];
} else if (e.category === 3) {
e.seriesOptions = this.options.drilldown.series[2]
}
}
var chart = this;
chart.yAxis[0].update({
type: 'category',
categories: y_axes[e.seriesOptions.axe_y]
});
chart.xAxis[0].update({
type: 'category',
categories: x_axes[e.seriesOptions.axe_x]
});
},
...
}
}
Live demo: https://jsfiddle.net/BlackLabel/186mdyfx/
I have a dataset with the date indicated in the style of »2020/01/01«. Now, my Fiddle displays the corresponding data correctly considering the time/year (the right part climbs very steeply):
Pretty much the same code in the original PHP version however does not display it the correct way:
The code is really almost the same:
$.get('graph_global_ch4_concentration_800000.csv', function(data)
{
var chart = new Highcharts.Chart(
{
chart:
{
renderTo: "div_graph_ch4",
type: "spline"
},
xAxis:
{
tickWidth: 0,
tickInterval: 100000
},
data:
{
csv: data
},
});
});
Why is it that the fiddle does it the right way, and my PHP file not?
Thanks for any hints!
In Highcharts.js is it possible to disable/enable a given category by clicking on it? In the same way as you can disable/enable a given series in a legend by clicking on it.
If not, what is the next best alternative?
Disabling a category by clicking on it is not supported in Highcharts by default. To acheieve the wanted result you need to add custom code. For example, in render event you can add click event to xAxis labels and update the chart with new categories and data:
var H = Highcharts,
categories = ['one', 'two', 'three'],
data = [1, 2, 3];
chart = Highcharts.chart('container', {
chart: {
events: {
render: function() {
var chart = this;
H.objectEach(chart.xAxis[0].ticks, function(tick) {
if (tick.label) {
H.addEvent(tick.label.element, 'click', function() {
data.splice(tick.pos, 1);
categories.splice(tick.pos, 1);
chart.update({
series: [{
data: data
}],
xAxis: {
categories: categories
}
});
});
}
});
}
}
},
series: [{
type: 'column',
data: data
}],
xAxis: {
categories: categories
}
});
Live demo: http://jsfiddle.net/BlackLabel/8wfx5yve/
API Reference: https://api.highcharts.com/class-reference/Highcharts.Chart#update
Trying to create a chart with 1 dashed line and solid lines. I've only ever created a chart in which all the lines were styled the same. I'm using the getJSON method any everything works well, however I would like to individually style one of the lines. I thought I would be able to add something to the empty series section within options - but I can't seem to get it to work.
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'spline',
marginBottom: 100
},
xAxis: {
categories: [],
},
series: []
}
$.getJSON("php/mysqldata.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];
chart = new Highcharts.Chart(options);
});
});
Add style information in that way (for example for second serie).
options.series[1] = json[2];
options.series[1].dashstyle = 'Dash';
I have found this jsfiddle very helpful when I started working on paginated highchart columns. On top of this good example, I would like to know how I could change the x-axis labels into each data's corresponding name. (Ex. Along the x-axis, we should find the names of 'Fred G. Aandahl', 'Watkins Moorman Abbitt', 'Amos Abbott', etc. with their corresponding y-values and must change accordingly when the "Next" button is clicked.)
I have tried adding "xAxis" option inside the highcharts portion but still had no luck.
pie = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
xAxis: {
labels: {
formatter: function(){
return this.value;
}
}
},
series: [{
data: []
}]
});
and
pie = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
xAxis: {
labels: {
format: '{value}'
}
},
series: [{
data: []
}]
});
Can someone help me regarding on what I am missing in this example? It will be very much appreciated.
You can set type of xAxis to category and without category array the value in axis will be taken from the point. But you will need to change your setData call to
pie.series[0].setData( data.slice(from, to), true, true, false );
xAxis: {
type: 'category'
},
Example: http://jsfiddle.net/kpxp4/8/
I am able to change the x-axis labels accordingly by adding
pie.xAxis[0].update({
categories: category.slice(from, to)
})
after the setData call, where category is an array of all the x-axis labels that you want to display in correspondence to each y-axis value. Moreover, the
xAxis: {
type: 'category'
}
portion, as suggested by #Kacper Madej, works for the specific data format given originally. However, the pie.xAxis[0].update() could be used on a more general sense given that you know the array of x-axis labels that you want to use (regardless of the data or series format that you have).
Here is the link to the jsfiddle.
Hope this could be of any help, too.