score:19
EDIT: The response down below is more correct!
https://stackoverflow.com/a/8408466/387285
http://www.highcharts.com/ref/#series-object
HTML:
<SELECT id="list">
<OPTION VALUE="A">Data Set A
<OPTION VALUE="B">Data Set B
</SELECT>
<button id="change">Refresh Table</button>
<div id="container" style="height: 400px"></div>
Javascript:
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'spline'
},
series: []
};
$("#change").click(function() {
if ($("#list").val() == "A") {
options.series = [{name: 'A', data: [1,2,3,2,1]}]
// $.get('/dough/includes/live-chart.php?mode=month'
} else {
options.series = [{name: 'B', data: [3,2,1,2,3]}]
// $.get('/dough/includes/live-chart.php?mode=newmode'
}
var chart = new Highcharts.Chart(options);
});
This is a very simple example since I don't have my files here with me but the basic idea is that every time the user selects new options for the stuff they want to see, you're going to have replace the .series data object with the new information from your server and then recreate the chart using the new Highcharts.Chart();.
Hope this helps! John
EDIT:
Check this out, its from something I've worked on in the past:
$("table#tblGeneralInfo2 > tbody > tr").each(function (index) {
if (index != 0) {
var chartnumbervalue = parseInt($(this).find("td:last").text());
var charttextvalue = $(this).find("td:first").text();
chartoptions.series[0].data.push([charttextvalue, chartnumbervalue]);
}
});
I had a table with information in the first and last tds that I needed to add to the pie chart. I loop through each of the rows and push in the values. Note: I use chartoptions.series[0].data since pie charts only have 1 series.
score:0
data = [150,300]; // data from ajax or any other way
chart.series[0].setData(data, true);
The setData
will call redraw method.
Reference: http://api.highcharts.com/highcharts/Series.setData
score:1
If you are using push to push the data to the option.series dynamically .. just use
options.series = [];
to clear it.
options.series = [];
$("#change").click(function(){
}
score:1
You can always load a json data
here i defined Chart as namespace
$.getJSON('data.json', function(data){
Chart.options.series[0].data = data[0].data;
Chart.options.series[1].data = data[1].data;
Chart.options.series[2].data = data[2].data;
var chart = new Highcharts.Chart(Chart.options);
});
score:2
Correct answer is:
$.each(lines, function(lineNo, line) {
var items = line.split(',');
var data = {};
$.each(items, function(itemNo, item) {
if (itemNo === 0) {
data.name = item;
} else {
data.y = parseFloat(item);
}
});
options.series[0].data.push(data);
data = {};
});
You need to flush the 'data' array.
data = {};
score:4
You need to clear the old array out before you push the new data in. There are many ways to accomplish this but I used this one:
options.series[0].data.length = 0;
So your code should look like this:
options.series[0].data.length = 0;
$.each(lines, function(lineNo, line) {
var items = line.split(',');
var data = {};
$.each(items, function(itemNo, item) {
if (itemNo === 0) {
data.name = item;
} else {
data.y = parseFloat(item);
}
});
options.series[0].data.push(data);
});
Now when the button is clicked the old data is purged and only the new data should show up. Hope that helps.
score:4
Actually maybe you should choose the function update
is better.
Here's the document of function update
http://api.highcharts.com/highcharts#Series.update
You can just type code like below:
chart.series[0].update({data: [1,2,3,4,5]})
These code will merge the origin option, and update the changed data.
score:103
The other answers didn't work for me. I found the answer in their documentation:
http://api.highcharts.com/highcharts#Series
Using this method (see JSFiddle example):
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
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]
}]
});
// the button action
$('#button').click(function() {
chart.series[0].setData([129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4] );
});
Source: stackoverflow.com
Related Query
- Reload chart data via JSON with Highcharts
- Returning JSON file with cURL to use data in a HighCharts stock chart
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- Data Conversion from SQL, C# with Linq to JSON for Highcharts Line chart
- Highcharts cloud issue with data source when duplicating chart
- Javascript, using Highcharts to display a chart of rankings with JSON Data
- Passing data from PHP array to Highcharts chart with JSON
- Highcharts real time chart with incoming Json data [FIXED[]
- Highcharts Dynamic Chart with MySQL Data doesn't reload
- Highcharts with JSON data and multiple series
- Add dynamic data to line chart from mysql database with highcharts
- Highcharts - Global configuration with common code and unique data & Headings
- Show more data on Gauge chart with Highcharts
- Formatting JSON Data with ColdFusion for HighCharts
- Highcharts with ajax and json data what am i doing wrong?
- How to format my json data for stack column chart in HighCharts
- Splitted bar chart for paired data with highcharts
- How to Build a Column Chart in Highcharts with Data Entered Dynamically Within a CMS
- dynamic highcharts with json data
- How to construct HighCharts data series to match returned Json via ajax call
- Retrieving JSON data for Highcharts with multiple series?
- Highcharts add point to line chart with json
- Add different symbols to highcharts chart with dynamic data
- HighCharts load data via Json
- passing formatting JavaScript code to HighCharts with JSON
- Highcharts polar chart wind rose data from JSON
- Highcharts area chart hide graphs with one data point
- JSON Data Map Issue with HighCharts + Ajax
- Highcharts GANTT chart - need to allow category with no data
- highcharts Scatter Chart not loading with LOTS of data
More Query from same tag
- I change the min and max of the xaxis, but how to i change the 'navigator'?
- How can I access the 'this' field in plotOptions of highcharts
- Make equal distance for bars with different width Highchart
- Size and offset for plotBackgroundImage in Highcharts
- Highcharts 24 hours displayed on x axis
- Add/Remove Highstock stock tools?
- PHP Create array with placeholders
- Highstock lineWidth
- Setting additional data to Highchart series via <%= #{} %> works for integers but not Strings
- Pie chart controller by slider
- Change X axis label on Drill Down using HighCharts
- Angularjs highcharts and modal windows clear previous chart
- Strange behavior with highcharts when using "column" type and multiple datetime series
- HighChart Graph aligned wrong on Xaxis .. not able to reproduce on JSFiddle
- Make highcharts fullscreen also fullscreen the div wrapping the chart
- Highcharts reset y Axis
- How do I fix highchart to display series correctly with a special marker
- How to change highmap bubble color
- Highcharts add new data to series after click
- how do you change the color of cells in highcharts heatmap?
- Highcharts, tooltip on hover listing datapoints that do not exist, is it an approximation?
- Is there any way to test the highcharts with large data-set with Jest and React.?
- Highstock displayed inconsistent
- Getting error while using highcharts in Angular 7
- Highchart, polar chart multiple values in one line
- HighcharteR facetted item type chart
- Highcharts crashes when I assign the options
- When changing data, why is the data reduced every time the button is pressed?
- Basic jquery fiddle to Angular Directive
- Remove Highcharts dataLabel border