Skip to content
Advertisement

Using dropdown filter to dynamic update Highchart

currently I was trying to add a dropdown filter button on my chart to let users select a specific values from a data attribute and filter the related data shown on the chart.

I populated my data’s attribute to the select unit, and I was trying to update the chart with parse the data from the selective value, but seems the data didn’t update on the HighChart.

Here is my code: jsfiddle

JavaScript

Is there anything I did wrong? Thank you.

=================================================================

Updated: Solution from JMS work prefectly, but in my real case my json data was called from somewhere so this will be a function. Based on JMS’s method the result was while I make selection from dropdown it counldn’t find update() function since it was nested inside my function. Sorry I’m still new in the javascript and I can’t figure out how to solve it.

JavaScript

Advertisement

Answer

You never subscribed to changes of the dropdown, so the data will not change.

  1. Add an onchange listener on the dropdown

    JavaScript
  2. Put your update logic into the function update() function

JavaScript
  1. Call update() once yourself right at the start, to get the initial chart

See the working fiddle here: http://jsfiddle.net/ran2vz7s/3/

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement