Dear Johannes,
After we succsseeded to display a vaadin chart we noticed a bug(?) connecting to the chart’s zooming.
We could reproduce the bug using your chart sample. Would you be so kind to take a look at it, and try it if you have some time. The problem is the following:
There is a vertical layout with a button and a graph in it. The button removes the old graph from the layout and creates a new instance of the chart and adds it to the layout. In the first instance of the graph the zooming is perfectly working. But after we push the button and recreating the chart the zooming doesn’t work. The createChart() method was copied from the vaadin charts demo page, I only added zoomType to the code.
I don’t know what goes wrong…
[code]
package some.package.component;
import com.vaadin.addon.charts.Chart;
import com.vaadin.addon.charts.model.;
import com.vaadin.ui.;
/**
*
*/
public class GraphWindow extends Window {
private VerticalLayout graphLayout;
public GraphWindow() {
super("Zooming problem");
initComponents();
}
private void initComponents() {
Panel p = new Panel();
p.setSizeFull();
graphLayout = createLayout();
Button button = createGenerateGraphButton();
VerticalLayout mainLayout = (VerticalLayout) p.getContent();
mainLayout.addComponent(button);
mainLayout.addComponent(graphLayout);
addComponent(p);
}
private Button createGenerateGraphButton() {
Button b = new Button();
b.setImmediate(true);
b.setCaption("Regenerate graph");
b.addListener(createListener());
return b;
}
private Button.ClickListener createListener() {
return new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
graphLayout.removeAllComponents();
VerticalLayout vl = createLayout();
graphLayout.addComponent(vl);
}
};
}
private VerticalLayout createLayout() {
Chart chart = createChart();
VerticalLayout vl = new VerticalLayout();
vl.setSizeFull();
vl.setSpacing(true);
vl.addComponent(chart);
return vl;
}
private Chart createChart() {
Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = new Configuration();
configuration.getChart().setType(ChartType.LINE);
configuration.getChart().setMarginRight(130);
configuration.getChart().setMarginBottom(25);
configuration.getTitle().setText("Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
Axis yAxis = configuration.getyAxis();
yAxis.setMin(-5d);
yAxis.setTitle(new Title("Temperature (°C)"));
yAxis.getTitle().setVerticalAlign(VerticalAlign.HIGH);
configuration
.getTooltip()
.setFormatter(
"''+ this.series.name + '' + this.x +': '+ this.y +'°C'");
PlotOptionsLine plotOptions = new PlotOptionsLine();
plotOptions.setDataLabels(new Labels(true));
configuration.setPlotOptions(plotOptions);
Legend legend = configuration.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setHorizontalAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(-10d);
legend.setY(100d);
legend.setBorderWidth(0);
ListSeries ls = new ListSeries();
ls.setName("Tokyo");
ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3,
13.9, 9.6);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("New York");
ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1,
8.6, 2.5);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("Berlin");
ls.setData(-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9,
1.0);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("London");
ls.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6,
4.8);
configuration.addSeries(ls);
configuration.getChart().setZoomType(ZoomType.XY);
chart.drawChart(configuration);
return chart;
}
}
[/code]Thanks in advance!
Szilvi