score:1
The first problem is reading out the error generated by your code. When you select a option from the dropdown your code generates the error:
Uncaught ReferenceError: chartBench is not defined
This is because chartBench
is created within the ready(function() { ... })
scope, and can't be access from the outside on('change', function() { ... })
. You may want to take a look at Javascript Variable Scope.
To solve this you can define the chartBench
variable at the top level to make sure it is accessible, like this:
var chartBench;
$(document).ready(function () {
chartBench = new Highcharts.Chart({
....
You could alternatively also move your change listener declaration within the ready(function() { ... })
scope.
Regarding the updating of data, your code still has issues. You are using chartBench.series[0].setData
as if it can update all your data at the same time. This is not the case. This function sets the data of a single series, so you will have to loop through your series and update them individually. Correct use of setData
to update a single column would look something like this:
chartBench.series[0].setData([210, 200, 220, 230]);
This updates the first series in your chart to use those specific values instead of those it had previously. This updated JSFiddle gives a example updating a single column with dropdown. It is up to you to utilize this functionality for all series, if desired.
score:3
DEMO to update data for all series (not only the first series).
code:
var chartBench
$(document).ready(function () {
chartBench = new Highcharts.Chart({
chart: {
renderTo: 'containerYo',
type: 'column'
},
title: {
text: ''
},
credits: {
enabled: false
},
legend: {},
plotOptions: {
series: {
shadow: false,
borderWidth: 0
}
},
xAxis: {
lineColor: '#999',
lineWidth: 1,
tickColor: '#666',
tickLength: 3,
categories: ['2011', '2012', '2013', '2014'],
title: {
text: 'Years'
}
},
yAxis: {
lineColor: '#999',
lineWidth: 1,
tickColor: '#666',
tickWidth: 1,
tickLength: 3,
gridLineColor: '#ddd',
labels: {
format: '$ {value}'
},
title: {
text: ''
}
},
series: [{
"name": "Yours",
"data": [110, 100, 120, 130]
}, {
"name": "Another",
"data": [100, 90, 110, 120]
}, {
"name": "Another B",
"data": [90, 80, 100, 110]
}, {
"name": "Another C",
"data": [80, 70, 90, 100]
}]
});
});
var option_a_data = [{
"name": "Option-A (1)",
"data": [10, 20, 30, 40]
}, {
"name": "Option-A (2)",
"data": [50, 60, 70, 80]
}, {
"name": "Option-A (3)",
"data": [90, 100, 110, 120]
}, {
"name": "Option-A (4)",
"data": [130, 140, 150, 160]
}];
var option_b_data = [{
"name": "Option-B (1)",
"data": [110, 100, 90, 80]
}, {
"name": "Option-B (2)",
"data": [110, 100, 90, 80]
}, {
"name": "Option-B (3)",
"data": [110, 100, 90, 80]
}, {
"name": "Option-B (4)",
"data": [110, 100, 90, 80]
}];
$("#list").on('change', function () {
//alert('f')
var selVal = $("#list").val();
if (selVal == "a")
{
//chartBench.series[0].setData([110, 100, 120, 130]);
for(i=0; i<chartBench.series.length; i++)
{
//alert(i);
//chartBench.series[i].setData(my_data[i].data);
chartBench.series[i].update({
name: option_a_data[i].name,
data:option_a_data[i].data
});
}
chartBench.redraw();
}
else if (selVal == "b")
{
for(i=0; i<chartBench.series.length; i++)
{
//alert(i);
//chartBench.series[i].setData(my_data[i].data);
chartBench.series[i].update({
name: option_b_data[i].name,
data:option_b_data[i].data
});
}
chartBench.redraw(); // redraw only after add all series
}
else
{
}
});
Source: stackoverflow.com
Related Query
- Highcharts - update column graph with setData() not working
- Highcharts graph does not update with firebase
- HIGHCHARTS Treemap update is not working with animation
- The continuous update highcharts with more data plotting the continuity is not visible so we need that continuity in the centre of the graph
- Highcharts setData not working with php,json on button click
- Can I with highcharts column stacking on hover not highlighting the whole serie
- Highcharts not displaying series data for graph with multiple Y-axes
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- HighCharts pointPlacement option not working in a single column chart
- Highcharts buttons with different menuitems not working
- HIghcharts column graph with more than 50 data points
- Highcharts - verticalAlign on dataLabels not working on line graph
- Update chart with HighchartsReact is not working when a timer is used in React
- Angular5 - Responsive Highcharts with configuration is not working
- highcharts - Not able to switch between bar to column or vice versa graph type in drilldown
- Highcharts - Small column not clickable when covered with a (sp)line serie
- Data and tooltip not working for graph using highcharts
- Stacked Column Highchart with Angular6 is not working
- Highcharts setData on pie chart not working
- highcharts datetime data not working on column type, but working on line
- rCharts and highcharts with shiny plot does not update correctly
- Stacked column not lining up with highcharts
- Highcharts Column Graph with background color?
- jQuery Highcharts not working with JSF 2.0
- Highcharts Column w/ drilldown not working in Rails 4
- Highcharts - Column labels with different widths are not aligned
- Highcharts upgrade to 8.1.2 not working with Angular 8
- Highcharts - setData() not updating Column Graph Correctly - stumped
- HighCharts angular not working with dynamic data from Angular service
- Angular 9 Highcharts - when using series of type pie with type gauge the innerSize of pie is not working
More Query from same tag
- I was trouble with tittle of the Highcharts
- Change title when drilldown in Highcharts
- How do you remove elements added with .add() function in HighCharts?
- 3D Column chart not working with sliders in asp .net project
- Highstock: Hover-over Tooltip format
- How can I remove the legend symbol for a SINGLE legend in Highcharts?
- Highcharts - Segmented column bar
- Highcharts I've lost my drilldown scrollbar
- Highcharts Export to CSV No Data Grouping
- How to change color on the Highchart Sparkline line only?
- How to display values on line stacked columns on highcharts
- Highchart: how to update a dynamic chart by clicking on a button?
- How can I get every bar in different colour using Highchart?
- Bar chart labels
- Highchart graph customization not performing well
- Highstock theming range buttons
- ASP.Net Chart controls Vs Highcharts
- Selenium WebDriver and Highchart testing
- Highcharts tooltip x axis font size
- Cannot get a series highchart
- How to handle mousedown event on chart part?
- Highcharts (highstock) anyway to detect maximum value in a series
- How to render the missing data series and fix the dates on the x-axis in Highcharts?
- Change the series title in a Highcharts drill down legend
- My column highcharts is not rendering any data
- High Charts - HTML in label
- HighCharts : How to REMOVE (or) HIDE a certain data POINT in Series?
- highchart print chart/chart context menu un-clickable
- In Highcharts, any way we can get the plotWidth and plotHeight before rendering the chart?
- how do you set the yaxis values in highcharts