I posted a topic earlier about the need of an API to reset the color for series. One workaround Shawn suggested is to keep the reference to the series object and call Series.setPoints() to update the chart when new data arrives. Unfortunately this approach doesn't work. There seems to be a bug in Series.setPoints(). Only one data point would show up after I make this call. The following program can reproduce this bug.
`
public class HighchartTest implements EntryPoint {
private static final int DATA_LENGTH = 10;
private Number[] randomData(){
int length = DATA_LENGTH;
Number[] data = new Number[length];
for(int i = 0; i < length; i++){
data[i] = Double.valueOf(Math.random() * 100);
}
return data;
}
/**
* This is the entry point method.
*/
public void onModuleLoad() {
Chart chart = new Chart();
chart.setToolTip(new ToolTip().setFormatter(new ToolTipFormatter() {
public String format(ToolTipData toolTipData) {
return toolTipData.getXAsString() + ": "
+ toolTipData.getYAsLong();
}
}));
final Series series = chart.createSeries().setName("Random Data").setPoints(randomData());
series.setType(Type.COLUMN);
chart.addSeries(series);
String[] categories = new String[DATA_LENGTH];
for(int i = 0; i < categories.length; i++){
categories[i] = "Day " + i;
}
chart.getXAxis().setCategories(categories);
FlowPanel panel = new FlowPanel();
panel.add(chart);
Button refresh = new Button("Refresh");
refresh.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event) {
series.setPoints(randomData());
}
});
panel.add(refresh);
RootLayoutPanel.get().add(panel);
}
}
`
Last edit: Henry Sue 2011-09-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've investigated this a bit, and can't seem to duplicate the problem you're seeing. The following is a trimmed down example (which uses your "randomData" function) which shows the "setPoints" method in operation:
Chart chart = new Chart();
final Series series = chart.createSeries()
.setName("Random Data")
.setPoints(randomData());
chart.addSeries(series);
chart.setClickEventHandler(new ChartClickEventHandler() {
public boolean onClick(ChartClickEvent chartClickEvent) {
series.setPoints(randomData());
return true;
}
});
I'm running against GWT Highcharts version 1.1.1 though, so you may want to try upgrading to see if that resolves the problem. If this still doesn't work for you though, it's possible that you're being bit by the issue with the "splat()" function in the core highcharts.js file. There's a related post on the Highcharts forums here:
I posted a topic earlier about the need of an API to reset the color for series. One workaround Shawn suggested is to keep the reference to the series object and call Series.setPoints() to update the chart when new data arrives. Unfortunately this approach doesn't work. There seems to be a bug in Series.setPoints(). Only one data point would show up after I make this call. The following program can reproduce this bug.
`
Last edit: Henry Sue 2011-09-07
I've investigated this a bit, and can't seem to duplicate the problem you're seeing. The following is a trimmed down example (which uses your "randomData" function) which shows the "setPoints" method in operation:
I'm running against GWT Highcharts version 1.1.1 though, so you may want to try upgrading to see if that resolves the problem. If this still doesn't work for you though, it's possible that you're being bit by the issue with the "splat()" function in the core highcharts.js file. There's a related post on the Highcharts forums here:
http://highslide.com/forum/viewtopic.php?f=9&t=11268&p=56062
You'll see on that post I proposed replacing the splat() function in Highcharts with the following to work around the problem:
Can you let us know if either of those ideas work for you?