use of com.vaadin.addon.charts.model.PlotBand in project charts by vaadin.
the class SplineWithPlotBands method getChart.
@SuppressWarnings("deprecation")
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getTitle().setText("Wind speed during two days");
configuration.getSubTitle().setText("October 6th and 7th 2009 at two locations in Vik i Sogn, Norway");
configuration.getxAxis().setType(AxisType.DATETIME);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Wind speed (m/s)"));
yAxis.setMin(0);
yAxis.setMinorGridLineWidth(0);
yAxis.setGridLineWidth(0);
// disable alternate grid color from Vaadin theme, disturbs
// demonstrating plotbands
yAxis.setAlternateGridColor(TRANSPARENT);
Style style = new Style();
style.setColor(LIGHT_GRAY);
final PlotBand lightAir = new PlotBand();
lightAir.setFrom(0.3);
lightAir.setTo(1.5);
lightAir.setColor(LIGHT_BLUE);
lightAir.setLabel(new Label("Light air"));
lightAir.getLabel().setStyle(style);
final PlotBand lightBreeze = new PlotBand();
lightBreeze.setFrom(1.5);
lightBreeze.setTo(3.3);
lightBreeze.setColor(TRANSPARENT);
lightBreeze.setLabel(new Label("Light breeze"));
lightBreeze.getLabel().setStyle(style);
final PlotBand gentleBreeze = new PlotBand();
gentleBreeze.setFrom(3.3);
gentleBreeze.setTo(5.5);
gentleBreeze.setColor(LIGHT_BLUE);
gentleBreeze.setLabel(new Label("Gentle breeze"));
gentleBreeze.getLabel().setStyle(style);
final PlotBand moderateBreeze = new PlotBand();
moderateBreeze.setFrom(5.5);
moderateBreeze.setTo(8);
moderateBreeze.setColor(TRANSPARENT);
moderateBreeze.setLabel(new Label("Moderate breeze"));
moderateBreeze.getLabel().setStyle(style);
final PlotBand freshBreeze = new PlotBand();
freshBreeze.setFrom(8);
freshBreeze.setTo(11);
freshBreeze.setColor(LIGHT_BLUE);
freshBreeze.setLabel(new Label("Fresh breeze"));
freshBreeze.getLabel().setStyle(style);
final PlotBand strongBreeze = new PlotBand();
strongBreeze.setFrom(11);
strongBreeze.setTo(14);
strongBreeze.setColor(TRANSPARENT);
strongBreeze.setLabel(new Label("Strong breeze"));
strongBreeze.getLabel().setStyle(style);
final PlotBand highWind = new PlotBand();
highWind.setFrom(14);
highWind.setTo(15);
highWind.setColor(LIGHT_BLUE);
highWind.setLabel(new Label("High wind"));
highWind.getLabel().setStyle(style);
yAxis.setPlotBands(lightAir, lightBreeze, gentleBreeze, moderateBreeze, freshBreeze, strongBreeze, highWind);
configuration.getTooltip().setFormatter("Highcharts.dateFormat('%e. %b %Y, %H:00', this.x) +': '+ this.y +' m/s'");
PlotOptionsSpline plotOptions = new PlotOptionsSpline();
configuration.setPlotOptions(plotOptions);
plotOptions.setMarker(new Marker(false));
plotOptions.getMarker().setLineWidth(4);
plotOptions.getMarker().setSymbol(MarkerSymbolEnum.CIRCLE);
States states = new States();
Hover hover = new Hover(true);
hover.setRadius(5);
hover.setLineWidth(1);
states.setHover(hover);
plotOptions.getMarker().setStates(states);
plotOptions.setPointInterval(ONE_HOUR);
LocalDate date = LocalDate.of(2009, 9, 6);
plotOptions.setPointStart(date.atStartOfDay().toInstant(ZoneOffset.UTC));
ListSeries ls = new ListSeries();
ls.setName("Hestavollane");
ls.setData(4.3, 5.1, 4.3, 5.2, 5.4, 4.7, 3.5, 4.1, 5.6, 7.4, 6.9, 7.1, 7.9, 7.9, 7.5, 6.7, 7.7, 7.7, 7.4, 7.0, 7.1, 5.8, 5.9, 7.4, 8.2, 8.5, 9.4, 8.1, 10.9, 10.4, 10.9, 12.4, 12.1, 9.5, 7.5, 7.1, 7.5, 8.1, 6.8, 3.4, 2.1, 1.9, 2.8, 2.9, 1.3, 4.4, 4.2, 3.0, 3.0);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("Voll");
ls.setData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0, 0.0, 0.4, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6, 1.2, 1.7, 0.7, 2.9, 4.1, 2.6, 3.7, 3.9, 1.7, 2.3, 3.0, 3.3, 4.8, 5.0, 4.8, 5.0, 3.2, 2.0, 0.9, 0.4, 0.3, 0.5, 0.4);
configuration.addSeries(ls);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.PlotBand 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.PlotBand in project charts by vaadin.
the class SplineWithPlotBandRemoveFunctionality method createPlotBand.
private void createPlotBand(YAxis yAxis) {
Style style = new Style();
style.setColor(LIGHT_GRAY);
final PlotBand lightAir = new PlotBand();
lightAir.setFrom(0.3);
lightAir.setTo(1.5);
lightAir.setColor(LIGHT_BLUE);
lightAir.setLabel(new Label("Light air"));
lightAir.getLabel().setStyle(style);
final PlotBand lightBreeze = new PlotBand();
lightBreeze.setFrom(1.5);
lightBreeze.setTo(3.3);
lightBreeze.setColor(TRANSPARENT);
lightBreeze.setLabel(new Label("Light breeze"));
lightBreeze.getLabel().setStyle(style);
final PlotBand gentleBreeze = new PlotBand();
gentleBreeze.setFrom(3.3);
gentleBreeze.setTo(5.5);
gentleBreeze.setColor(LIGHT_BLUE);
gentleBreeze.setLabel(new Label("Gentle breeze"));
gentleBreeze.getLabel().setStyle(style);
final PlotBand moderateBreeze = new PlotBand();
moderateBreeze.setFrom(5.5);
moderateBreeze.setTo(8);
moderateBreeze.setColor(TRANSPARENT);
moderateBreeze.setLabel(new Label("Moderate breeze"));
moderateBreeze.getLabel().setStyle(style);
final PlotBand freshBreeze = new PlotBand();
freshBreeze.setFrom(8);
freshBreeze.setTo(11);
freshBreeze.setColor(LIGHT_BLUE);
freshBreeze.setLabel(new Label("Fresh breeze"));
freshBreeze.getLabel().setStyle(style);
final PlotBand strongBreeze = new PlotBand();
strongBreeze.setFrom(11);
strongBreeze.setTo(14);
strongBreeze.setColor(TRANSPARENT);
strongBreeze.setLabel(new Label("Strong breeze"));
strongBreeze.getLabel().setStyle(style);
final PlotBand highWind = new PlotBand();
highWind.setFrom(14);
highWind.setTo(15);
highWind.setColor(LIGHT_BLUE);
highWind.setLabel(new Label("High wind"));
highWind.getLabel().setStyle(style);
yAxis.setPlotBands(lightAir, lightBreeze, gentleBreeze, moderateBreeze, freshBreeze, strongBreeze, highWind);
}
use of com.vaadin.addon.charts.model.PlotBand in project charts by vaadin.
the class PlotBandTest method setup.
@Before
public void setup() {
Chart chart = new Chart(ChartType.PIE);
Configuration conf = chart.getConfiguration();
axis = new XAxis();
conf.addxAxis(axis);
plotBand1 = new PlotBand();
plotBand1.setFrom(1);
plotBand1.setTo(2);
plotBand1.setColor(SolidColor.ALICEBLUE);
plotBand2 = new PlotBand();
plotBand2.setFrom(2);
plotBand2.setTo(3);
plotBand2.setColor(SolidColor.ANTIQUEWHITE);
plotBand3 = new PlotBand();
plotBand3.setFrom(3);
plotBand3.setTo(4);
plotBand3.setColor(SolidColor.AQUA);
List<PlotBand> plotbands = new ArrayList<PlotBand>();
plotbands.add(plotBand1);
plotbands.add(plotBand2);
plotbands.add(plotBand3);
axis.setPlotBands(plotBand1, plotBand2, plotBand3);
}
use of com.vaadin.addon.charts.model.PlotBand in project charts by vaadin.
the class ChartTypes method chartTypesGaugeAxisSnippet1.
public void chartTypesGaugeAxisSnippet1() {
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
YAxis yaxis = new YAxis();
yaxis.setTitle("km/h");
// The limits are mandatory
yaxis.setMin(0);
yaxis.setMax(100);
// Other configuration
yaxis.getLabels().setStep(1);
yaxis.setTickInterval(10);
yaxis.setTickLength(10);
yaxis.setTickWidth(1);
yaxis.setMinorTickInterval("1");
yaxis.setMinorTickLength(5);
yaxis.setMinorTickWidth(1);
yaxis.setPlotBands(new PlotBand[] { new PlotBand(0, 60, SolidColor.GREEN), new PlotBand(60, 80, SolidColor.YELLOW), new PlotBand(80, 100, SolidColor.RED) });
// Disable grid
yaxis.setGridLineWidth(0);
conf.addyAxis(yaxis);
}
Aggregations