use of com.vaadin.addon.charts.model.Background in project charts by vaadin.
the class CustomClock method getChart.
@Override
protected Chart getChart() {
final Chart chart = new Chart();
chart.setWidth("500px");
chart.setHeight("200px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.GAUGE);
configuration.getChart().setPlotBackgroundColor(null);
configuration.getChart().setPlotBackgroundImage(null);
configuration.getChart().setPlotBorderWidth(0);
configuration.getChart().setPlotShadow(false);
configuration.setTitle("The Vaadin Charts customised clock");
configuration.getCredits().setEnabled(false);
GradientColor gradient1 = GradientColor.createRadial(0.5, -0.4, 1.9);
gradient1.addColorStop(0.5, new SolidColor(255, 255, 255, 0.2));
gradient1.addColorStop(0.5, new SolidColor(200, 200, 200, 0.2));
Background[] background = new Background[2];
background[0] = new Background();
background[1] = new Background();
background[1].setBackgroundColor(gradient1);
background[1].setBorderWidth(1);
background[1].setOuterRadius("107%");
configuration.getPane().setBackground(background);
YAxis yAxis = configuration.getyAxis();
yAxis.getLabels().setDistance(-20);
yAxis.setMin(0);
yAxis.setMax(12);
yAxis.setLineWidth(0);
yAxis.setShowFirstLabel(false);
yAxis.setMinorTickInterval("auto");
yAxis.setMinorTickWidth(1);
yAxis.setMinorTickLength(5);
yAxis.setMinorTickPosition(TickPosition.INSIDE);
yAxis.setMinorGridLineWidth(0);
yAxis.setMinorTickColor(new SolidColor("#666"));
yAxis.setTickInterval(1);
yAxis.setTickWidth(2);
yAxis.setTickPosition(TickPosition.INSIDE);
yAxis.setTickLength(10);
yAxis.setTickColor(new SolidColor("#666"));
yAxis.setTitle(new AxisTitle("Powered by<br/>Vaadin Charts 2"));
yAxis.getTitle().setStyle(new Style());
yAxis.getTitle().getStyle().setColor(new SolidColor("#BBB"));
yAxis.getTitle().getStyle().setFontWeight(FontWeight.BOLD);
yAxis.getTitle().getStyle().setFontSize("8px");
yAxis.getTitle().getStyle().setLineHeight("10px");
yAxis.getTitle().setY(10);
final DataSeries series = new DataSeries();
final DataSeriesItem second = new DataSeriesItem();
second.setId("second");
second.setY(30);
second.setDial(new Dial());
second.getDial().setRadius("100%");
second.getDial().setBaseWidth(1);
second.getDial().setRearLength("20%");
second.getDial().setBackgroundColor(SolidColor.AQUA);
second.getDial().setBorderColor(SolidColor.RED);
second.getDial().setBorderWidth(10);
second.getDial().setTopWidth(8);
series.add(second);
PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
plotOptionsGauge.setDataLabels(new DataLabels(false));
configuration.setPlotOptions(plotOptionsGauge);
configuration.setSeries(series);
final Calendar cal = Calendar.getInstance();
runWhileAttached(chart, new Runnable() {
@Override
public void run() {
cal.setTimeInMillis(System.currentTimeMillis());
double secs = cal.get(Calendar.SECOND);
// disable animation when the second dial reaches 0
boolean animation = secs == 0 ? false : true;
configuration.getChart().setAnimation(animation);
second.setY(secs * (12.0 / 60.0));
series.update(second);
}
}, 1000, 15000);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.Background in project charts by vaadin.
the class AngularGauge method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.GAUGE);
configuration.getChart().setPlotBackgroundColor(null);
configuration.getChart().setPlotBackgroundImage(null);
configuration.getChart().setPlotBorderWidth(0);
configuration.getChart().setPlotShadow(false);
configuration.setTitle("Speedometer");
GradientColor gradient1 = GradientColor.createLinear(0, 0, 0, 1);
gradient1.addColorStop(0, new SolidColor("#FFF"));
gradient1.addColorStop(1, new SolidColor("#333"));
GradientColor gradient2 = GradientColor.createLinear(0, 0, 0, 1);
gradient2.addColorStop(0, new SolidColor("#333"));
gradient2.addColorStop(1, new SolidColor("#FFF"));
Background[] background = new Background[3];
background[0] = new Background();
background[0].setBackgroundColor(gradient1);
background[0].setBorderWidth(0);
background[0].setOuterRadius("109%");
background[1] = new Background();
background[1].setBackgroundColor(gradient2);
background[1].setBorderWidth(1);
background[1].setOuterRadius("107%");
background[2] = new Background();
background[2].setBackgroundColor(new SolidColor("#DDD"));
background[2].setBorderWidth(0);
background[2].setInnerRadius("103%");
background[2].setOuterRadius("105%");
configuration.getPane().setStartAngle(-150);
configuration.getPane().setEndAngle(150);
configuration.getPane().setBackground(background);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("km/h"));
yAxis.setMin(0);
yAxis.setMax(200);
yAxis.setMinorTickInterval("auto");
yAxis.setMinorTickWidth(1);
yAxis.setMinorTickLength(10);
yAxis.setMinorTickPosition(TickPosition.INSIDE);
yAxis.setMinorTickColor(new SolidColor("#666"));
yAxis.setGridLineWidth(0);
yAxis.setTickPixelInterval(30);
yAxis.setTickWidth(2);
yAxis.setTickPosition(TickPosition.INSIDE);
yAxis.setTickLength(10);
yAxis.setTickColor(new SolidColor("#666"));
Labels labels = new Labels();
labels.setStep(2);
labels.setRotationPerpendicular();
yAxis.setLabels(labels);
PlotBand[] plotBands = new PlotBand[3];
plotBands[0] = new PlotBand(0, 120, new SolidColor("#55BF3B"));
plotBands[1] = new PlotBand(120, 160, new SolidColor("#DDDF0D"));
plotBands[2] = new PlotBand(160, 200, new SolidColor("#DF5353"));
yAxis.setPlotBands(plotBands);
final ListSeries series = new ListSeries("Speed", 80);
PlotOptionsGauge plotOptions = new PlotOptionsGauge();
plotOptions.setTooltip(new SeriesTooltip());
plotOptions.getTooltip().setValueSuffix(" km/h");
series.setPlotOptions(plotOptions);
configuration.setSeries(series);
runWhileAttached(chart, new Runnable() {
Random r = new Random(0);
@Override
public void run() {
Integer oldValue = series.getData()[0].intValue();
Integer newValue = (int) (oldValue + (r.nextDouble() - 0.5) * 20.0);
series.updatePoint(0, newValue);
}
}, 3000, 12000);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.Background in project charts by vaadin.
the class SolidGauge method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setWidth(500, Unit.PIXELS);
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SOLIDGAUGE);
configuration.getTitle().setText("Speed");
Pane pane = new Pane();
pane.setCenter("50%", "85%");
pane.setSize("140%");
pane.setStartAngle(-90);
pane.setEndAngle(90);
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(0);
yaxis.setTickInterval(200);
yaxis.setTickWidth(0);
yaxis.setMin(0);
yaxis.setMax(200);
yaxis.setTitle("");
yaxis.getTitle().setY(-70);
yaxis.setLabels(new Labels());
yaxis.getLabels().setY(16);
Stop stop1 = new Stop(0.1f, SolidColor.GREEN);
Stop stop2 = new Stop(0.5f, SolidColor.YELLOW);
Stop stop3 = new Stop(0.9f, SolidColor.RED);
yaxis.setStops(stop1, stop2, stop3);
PlotOptionsSolidgauge plotOptions = new PlotOptionsSolidgauge();
plotOptions.setTooltip(new SeriesTooltip());
plotOptions.getTooltip().setValueSuffix(" km/h");
DataLabels labels = new DataLabels();
labels.setY(5);
labels.setBorderWidth(0);
labels.setUseHTML(true);
labels.setFormat("<div style=\"text-align:center\"><span style=\"font-size:25px;\">{y}</span><br/>" + " <span style=\"font-size:12pxg\">km/h</span></div>");
plotOptions.setDataLabels(labels);
configuration.setPlotOptions(plotOptions);
final ListSeries series = new ListSeries("Speed", 80);
configuration.setSeries(series);
runWhileAttached(chart, new Runnable() {
Random r = new Random(0);
@Override
public void run() {
Integer oldValue = series.getData()[0].intValue();
Integer newValue = (int) (oldValue + (r.nextDouble() - 0.5) * 20.0);
if (newValue > 200) {
newValue = 200;
} else if (newValue < 0) {
newValue = 0;
}
series.updatePoint(0, newValue);
}
}, 3000, 12000);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.Background in project charts by vaadin.
the class ChartTypes method chartTypesSolidGaugeConfSnippet2.
public void chartTypesSolidGaugeConfSnippet2() {
Chart chart = new Chart(ChartType.SOLIDGAUGE);
Configuration conf = chart.getConfiguration();
Pane pane = conf.getPane();
Background bkg = new Background();
// Gray
bkg.setBackgroundColor(new SolidColor("#eeeeee"));
// To make it an arc and not circle
bkg.setInnerRadius("60%");
// Default - not necessary
bkg.setOuterRadius("100%");
// solid or arc
bkg.setShape("arc");
pane.setBackground(bkg);
}
use of com.vaadin.addon.charts.model.Background in project charts by vaadin.
the class Clock method getChart.
@Override
protected Chart getChart() {
final Chart chart = new Chart();
chart.setWidth("500px");
chart.setHeight("200px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.GAUGE);
configuration.getChart().setPlotBackgroundColor(null);
configuration.getChart().setPlotBackgroundImage(null);
configuration.getChart().setPlotBorderWidth(0);
configuration.getChart().setPlotShadow(false);
configuration.setTitle("The Vaadin Charts clock");
configuration.getCredits().setEnabled(false);
GradientColor gradient1 = GradientColor.createRadial(0.5, -0.4, 1.9);
gradient1.addColorStop(0.5, new SolidColor(255, 255, 255, 0.2));
gradient1.addColorStop(0.5, new SolidColor(200, 200, 200, 0.2));
Background[] background = new Background[2];
background[0] = new Background();
background[1] = new Background();
background[1].setBackgroundColor(gradient1);
background[1].setBorderWidth(1);
background[1].setOuterRadius("107%");
configuration.getPane().setBackground(background);
YAxis yAxis = configuration.getyAxis();
Labels labels = new Labels();
labels.setDistance(-20);
yAxis.setLabels(labels);
yAxis.setMin(0);
yAxis.setMax(12);
yAxis.setLineWidth(0);
yAxis.setShowFirstLabel(false);
yAxis.setMinorTickInterval("auto");
yAxis.setMinorTickWidth(1);
yAxis.setMinorTickLength(5);
yAxis.setMinorTickPosition(TickPosition.INSIDE);
yAxis.setMinorGridLineWidth(0);
yAxis.setMinorTickColor(new SolidColor("#666"));
yAxis.setTickInterval(1);
yAxis.setTickWidth(2);
yAxis.setTickPosition(TickPosition.INSIDE);
yAxis.setTickLength(10);
yAxis.setTickColor(new SolidColor("#666"));
yAxis.setTitle(new AxisTitle("Powered by<br/>Vaadin Charts"));
yAxis.getTitle().setStyle(new Style());
yAxis.getTitle().getStyle().setColor(new SolidColor("#BBB"));
yAxis.getTitle().getStyle().setFontWeight(FontWeight.BOLD);
yAxis.getTitle().getStyle().setFontSize("8px");
yAxis.getTitle().getStyle().setLineHeight("10px");
yAxis.getTitle().setY(10);
final DataSeries series = new DataSeries();
final DataSeriesItem hour = new DataSeriesItem();
final DataSeriesItem minute = new DataSeriesItem();
final DataSeriesItem second = new DataSeriesItem();
hour.setId("hour");
hour.setY(10);
hour.setDial(new Dial());
hour.getDial().setRadius("60%");
hour.getDial().setBaseWidth(4);
hour.getDial().setRearLength("0%");
hour.getDial().setBaseLength("95%");
minute.setId("minute");
minute.setY(10);
minute.setDial(new Dial());
minute.getDial().setBaseLength("95%");
minute.getDial().setRearLength("0%");
second.setId("second");
second.setY(30);
second.setDial(new Dial());
second.getDial().setRadius("100%");
second.getDial().setBaseWidth(1);
second.getDial().setRearLength("20%");
series.add(hour);
series.add(minute);
series.add(second);
PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
plotOptionsGauge.setDataLabels(new DataLabels(false));
configuration.setPlotOptions(plotOptionsGauge);
configuration.setSeries(series);
final Calendar cal = Calendar.getInstance();
runWhileAttached(chart, new Runnable() {
@Override
public void run() {
cal.setTimeInMillis(System.currentTimeMillis());
double hours = cal.get(Calendar.HOUR);
double mins = cal.get(Calendar.MINUTE);
double secs = cal.get(Calendar.SECOND);
// disable animation when the second dial reaches 0
boolean animation = secs == 0 ? false : true;
configuration.getChart().setAnimation(animation);
hour.setY(hours + (mins / 60.0));
minute.setY(mins * (12.0 / 60.0) + secs * (12.0 / 3600.0));
second.setY(secs * (12.0 / 60.0));
series.update(hour);
series.update(minute);
series.update(second);
}
}, 1000, 15000);
chart.drawChart(configuration);
return chart;
}
Aggregations