Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Vaadin chart not showing
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;
}
I didn't see any problem in your chart code. Did you manage to get this working already? I would need a smaller self-contained project to try to debug the issue. Can you provide such?
Hi Johannes.
Thank you! I couldn't find the problem at first either.
The problem was divison by zero, wich is apparently not thrown, when using doubles - http://grouper.ieee.org/groups/754/
I had a method deeper down looking like:
public Double getErrorRateByFWAndDate(String fw, String hw, Date date) {
if (!knownDates.contains(date)) return 0.0;
double tt = 0.0;
double dt = 0.0;
for (Errorstatistic errorstatistic : esMap.get(date)) {
if (errorstatistic.getFirmware().equals(fw) && errorstatistic.getHardware().equals(hw)) {
tt += errorstatistic.getTicketstotal() == null ? 0.0 : errorstatistic.getTicketstotal();
dt += errorstatistic.getDevicetime() == null ? 0.0 : errorstatistic.getDevicetime();
}
}
return tt / dt;
}
So there was a chance the database would return zero, hence giving a division-by-zero error.
Simply fixed it with:
if(dt == 0.0) return 0.0;
It sure does suck not seing that!
Anyway - you're help a second set of eyes are much appreciated.
Best regards,
Ben
Wow what an annoying bug. Well, I'm glad you found the reason.