I have a simple chart implementation where I need to control the y-axis min and max values. I have added calls to Axis.setMin() and Axis.setMax(), but the displayed min / max values seems to be a bit random.
I have provided a complete example to demonstrate this. All you need to do is:
- Download the attached file (vaadin-charts-dashboard.tgz)
- tar xvfz vaadin-charts-dashboard.tgz
- cd vaadin-charts-dashboard
- mvn clean install
- mvn jetty:run
- localhost:8080/dashboard (in browser)
I have tested 3 scenarios (with reference to the Dashboard class shown below):
- Only ‘Chart 1’ added to vertical layout: OK, with min/max shown as 0/22 respectively
- Only ‘Chart 2’ added to vertical layout: NOK, with min/max shown as 0/24 respectively (instead of the specified 1/23)
- Both charts added to vertical layout: NOK, with min/max shown as 0/25 respectively for both charts
Any clues on what is going on here?
public class Dashboard extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
setSizeFull();
VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.setSizeFull();
verticalLayout.setSpacing(true);
// Create first chart
SampleChart sampleChart1 = new SampleChart("Chart 1", 0d, 22d);
verticalLayout.addComponent(sampleChart1);
// Create second chart
SampleChart sampleChart2 = new SampleChart("Chart 2", 1d, 23d);
verticalLayout.addComponent(sampleChart2);
setContent(verticalLayout);
}
class SampleChart extends Chart {
public SampleChart(final String chartTitle, final Double axisMinValue, final Double axisMaxValue) {
setSizeFull();
// Set chart type
Configuration configuration = new Configuration();
configuration.getChart().setType(ChartType.LINE);
// Set chart title
configuration.getTitle().setText(chartTitle);
// Set type for x-axis
configuration.getxAxis().setType(AxisType.DATETIME);
// Set min / max y-axis value
Axis yAxis = configuration.getyAxis();
yAxis.setMin(axisMinValue);
yAxis.setMax(axisMaxValue);
// Create sample series
DataSeries chartSeries = new DataSeries();
// Add series to chart
configuration.addSeries(chartSeries);
drawChart(configuration);
}
}
}
12946.tgz (10.9 KB)