Hi.
I’m trying to visualize a lot of data using Vaadin Charts.
The problem is that some specific charts started to disapeer. The area for the chart is showing a loading symbol for 10ms or something, and then goes to white, though the component is added.
When I try to add the chart, i tried to sysout the Caption, and as expected the chart was created, and all the data seems legit.
Sometimes all the charts are showing, other times not - but the first two charts are showing alle the time.
I first thought it was threading-issue, so I removed ALL threading, and tried again. No dice. Then I though maybe I had too many charts in one vertical layout, so I added two charts per tabsheet, though it still failed 95% of the time. The I tried setting a delay on 1 sec between the creations - still no luck.
What is happening? It’s the same data all the time, but sometimes the charts (only theese specific ones), wont be shown for the user.
First itteration gives a working sheet with charts:
All other tabs (itterations)
The code generating the tabsheet with the charts. Beware that the error existed before the tab-sheets were introduced, so that is not the problem.
private void initTabsheet() {
Date from = fromDate.getValue();
Date to = toDate.getValue();
ChartMaker chartMaker = new ChartMaker(from, to, new ArrayList<String>(hardwares));
TabSheet hwSheet = new TabSheet();
VerticalLayout sumTab = new VerticalLayout();
VerticalLayout statisticsTab = new VerticalLayout();
VerticalLayout firmwareTab = new VerticalLayout();
// These works just fine
sumTab.addComponent(chartMaker.getBarAccumulationHardwareDeviceTime(from, to, new ArrayList<String>(hardwares)));
sumTab.addComponent(chartMaker.getBarAccumulationHardwareBoots(from, to, new ArrayList<String>(hardwares)));
sumTab.addComponent(chartMaker.getBarAccumulationHardwareTickets(from, to, new ArrayList<String>(hardwares)));
sumTab.addComponent(chartMaker.getHistoricAccumulationHardwareDevicetime(from, to, new ArrayList<String>(hardwares)));
sumTab.addComponent(chartMaker.getHistoricAccumulationHardwareBoots(from, to, new ArrayList<String>(hardwares)));
sumTab.addComponent(chartMaker.getHistoricAccumulationHardwareTickets(from, to, new ArrayList<String>(hardwares)));
statisticsTab.addComponent(chartMaker.getHistoricStatisticsHardwareBootrate(from, to, new ArrayList<String>(hardwares)));
statisticsTab.addComponent(chartMaker.getHistoricStatisticsHardwareErrorrate(from, to, new ArrayList<String>(hardwares)));
// It is this loop that generates the charts, where only the first itteration actually
// works (Or they do work, the charts are created, but no
for (String hw : hardwares) {
VerticalLayout tab = new VerticalLayout();
tab.addComponent(chartMaker.getHistoricStatisticsFirmwareBootrate(from, to, hw));
tab.addComponent(chartMaker.getHistoricStatisticsFirmwareErrorrate(from, to, hw));
hwSheet.addTab(tab).setCaption(hw);
}
firmwareTab.addComponent(hwSheet);
subdata.addTab(sumTab).setCaption("Accumulations | Hardware");
subdata.addTab(statisticsTab).setCaption("Statistics | Hardware");
subdata.addTab(firmwareTab).setCaption("Staticstics | Firmware");
this.subdata.setVisible(true);
}
The code that generates the charts:
private Chart makeInitialChart(String title, String subtitle, String yt) {
// Create chart
Chart chart = new Chart(ChartType.LINE);
Configuration conf = chart.getConfiguration();
conf.setTitle(title);
conf.setSubTitle(subtitle);
// Add the dates to the x-axis
conf.getxAxis().setType(AxisType.DATETIME);
// Set y-axis
YAxis y = new YAxis();
y.setMin(0);
y.setTitle(yt);
conf.addyAxis(y);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("this.y");
conf.setTooltip(tooltip);
return chart;
}
public Chart getHistoricStatisticsFirmwareBootrate(Date from, Date to, String hardware) {
Chart chart = makeInitialChart("Bootrate by " + hardware + "'s firmware", "Between " + from + " and " + to, "Bootrate");
Configuration conf = chart.getConfiguration();
for (String fw : dao.getDistinctFirmwareBasedOnHardware(hardware)) {
DataSeries ls = new DataSeries();
ls.setPlotOptions(new PlotOptionsLine());
ls.setName(fw);
Calendar calend = Calendar.getInstance();
calend.setTime(from);
Calendar beginCalendar = new GregorianCalendar(calend.get(Calendar.YEAR), calend.get(Calendar.MONTH), calend.get(Calendar.DATE));
calend.setTime(to);
Calendar endCalendar = new GregorianCalendar(calend.get(Calendar.YEAR), calend.get(Calendar.MONTH), calend.get(Calendar.DATE));
while (beginCalendar.compareTo(endCalendar) <= 0) {
DataSeriesItem item = new DataSeriesItem(beginCalendar.getTime(), getBootRateFirm(hardware, fw, beginCalendar.getTime()));
ls.add(item);
beginCalendar.add(Calendar.DATE, 1);
}
conf.addSeries(ls);
}
chart.drawChart(conf);
return chart;
}