Hi,
I have a problem with the autoimatic refresh of a gauge. I have tried to refresh automatically after 5 second with a thread, but after 5 seconds nothing happend. How can I make an automatic refresh?
package com.example.testgauge;
import java.text.NumberFormat;
import com.vaadin.addon.charts.Chart;
import com.vaadin.addon.charts.model.Background;
import com.vaadin.addon.charts.model.ChartType;
import com.vaadin.addon.charts.model.Configuration;
import com.vaadin.addon.charts.model.Labels;
import com.vaadin.addon.charts.model.ListSeries;
import com.vaadin.addon.charts.model.Pane;
import com.vaadin.addon.charts.model.PlotOptionsSolidGauge;
import com.vaadin.addon.charts.model.YAxis;
import com.vaadin.addon.charts.model.style.SolidColor;
import com.vaadin.addon.charts.model.YAxis.Stop;
public class ProcessGauge extends Chart
{
private static final long serialVersionUID = 8741598808436923567L;
public ProcessGauge(Integer totale,Integer errori)
{
String percentuale = getPercentuale(errori, totale);
this.setWidth("300px");
this.setHeight("200px");
Configuration configuration = this.getConfiguration();
configuration.getChart().setType(ChartType.SOLIDGAUGE);
configuration.getTitle().setText("");
Pane pane = new Pane();
pane.setCenterXY("50%", "50%");
pane.setSize("100%");
pane.setStartAngle(-180);
pane.setEndAngle(180);
configuration.addPane(pane);
configuration.getTooltip().setEnabled(false);
Background bkg = new Background();
bkg.setBackgroundColor(new SolidColor("#eeeeee"));
bkg.setInnerRadius("60%");
bkg.setOuterRadius("100%");
bkg.setShape("arc");
bkg.setBorderWidth(0);
pane.setBackground(bkg);
YAxis yaxis = configuration.getyAxis();
yaxis.setLineWidth(3);
yaxis.setTickInterval(1);
yaxis.setTickWidth(0);
yaxis.setMin(0);
yaxis.setMax(1);
yaxis.getLabels().setY(16);
yaxis.getLabels().setEnabled(false);
Stop stop1 = new Stop(0.85f, SolidColor.RED);
Stop stop2 = new Stop(0.9f, SolidColor.ORANGE);
Stop stop3 = new Stop(0.95f, SolidColor.GREEN);
yaxis.setStops(stop1, stop2, stop3);
PlotOptionsSolidGauge plotOptions = new PlotOptionsSolidGauge();
Labels labels = new Labels();
labels.setY(5);
labels.setBorderWidth(0);
labels.setUseHTML(true);
// labels.setFormat(percentuale);
labels.setFormat("<p style=\"text-align:center;margin:0;padding:0;font-size:14px\">" + percentuale + "</p>");
// labels.setEnabled(false);
plotOptions.setDataLabels(labels);
configuration.setPlotOptions(plotOptions);
final ListSeries series = new ListSeries("Speed", (1 - (double)errori/totale));
System.out.println(series.getData()[0]
);
configuration.setSeries(series);
this.drawChart(configuration);
MyRun run = new MyRun(series);
Thread t = new Thread(run);
t.start();
}
private static class MyRun implements Runnable{
ListSeries s;
public MyRun(ListSeries series){
s=series;
}
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
s.updatePoint(0, 0.3);
System.out.println(s.getData()[0]
);
}
}
private String getPercentuale(int errori, int totale)
{
NumberFormat percentFormat = NumberFormat.getPercentInstance();
percentFormat.setMaximumFractionDigits(1);
percentFormat.setMinimumFractionDigits(1);
if (errori>=totale)
return "0.0";
else
return percentFormat.format(1 -((double)errori/totale));
}
}