use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class LineWithDashSelector method getChart.
@Override
protected Component getChart() {
chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.LINE);
configuration.getChart().setMarginRight(130);
configuration.getChart().setMarginBottom(25);
configuration.getTitle().setText("Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
YAxis yAxis = configuration.getyAxis();
yAxis.setMin(-5d);
yAxis.setTitle(new AxisTitle("Temperature (°C)"));
yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
plotOptions = new PlotOptionsLine();
plotOptions.setDataLabels(new DataLabels(true));
plotOptions.setDashStyle(DashStyle.DOT);
configuration.setPlotOptions(plotOptions);
Legend legend = configuration.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(-10d);
legend.setY(100d);
legend.setBorderWidth(0);
ListSeries ls = new ListSeries();
ls.setName("Tokyo");
ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("New York");
ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("Berlin");
ls.setData(-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("London");
ls.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
configuration.addSeries(ls);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class SplineWithSymbols method getChart.
@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("Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Temperature"));
Labels labels = new Labels();
labels.setFormatter("this.value +'°'");
yAxis.setLabels(labels);
configuration.getTooltip().setShared(true);
configuration.getxAxis().setCrosshair(new Crosshair());
PlotOptionsSpline plotOptions = new PlotOptionsSpline();
configuration.setPlotOptions(plotOptions);
plotOptions.setMarker(new Marker(true));
plotOptions.getMarker().setRadius(4);
plotOptions.getMarker().setLineColor(new SolidColor("#666666"));
plotOptions.getMarker().setLineWidth(1);
DataSeries ls = new DataSeries();
plotOptions = new PlotOptionsSpline();
Marker marker = new Marker();
marker.setSymbol(MarkerSymbolEnum.SQUARE);
plotOptions.setMarker(marker);
ls.setPlotOptions(plotOptions);
ls.setName("Tokyo");
ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
ls.get("26.5").getMarker().setSymbol(new MarkerSymbolUrl("http://www.highcharts.com/demo/gfx/sun.png"));
configuration.addSeries(ls);
ls = new DataSeries();
plotOptions = new PlotOptionsSpline();
marker = new Marker();
marker.setSymbol(MarkerSymbolEnum.DIAMOND);
plotOptions.setMarker(marker);
ls.setPlotOptions(plotOptions);
ls.setName("London");
ls.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
ls.get("3.9").getMarker().setSymbol(new MarkerSymbolUrl("http://www.highcharts.com/demo/gfx/snow.png"));
configuration.addSeries(ls);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class TimeDataWithIrregularIntervals method getChart.
@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("Snow depth in the Vikjafjellet mountain, Norway");
configuration.getSubTitle().setText("An example of irregular time data in Highcharts JS");
configuration.getTooltip().setFormatter("");
configuration.getxAxis().setType(AxisType.DATETIME);
configuration.getxAxis().setDateTimeLabelFormats(new DateTimeLabelFormats("%e. %b", "%b"));
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Snow depth (m)"));
yAxis.setMin(0);
configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>\'+ Highcharts.dateFormat('%e. %b', this.x) +': '+ this.y +' m'");
DataSeries ls = new DataSeries();
ls.setPlotOptions(new PlotOptionsSpline());
ls.setName("Winter 2007-2008");
Object[][] data1 = getData1();
for (int i = 0; i < data1.length; i++) {
Object[] ds = data1[i];
DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
ls.add(item);
}
configuration.addSeries(ls);
ls = new DataSeries();
ls.setPlotOptions(new PlotOptionsSpline());
ls.setName("Winter 2008-2009");
Object[][] data2 = getData2();
for (int i = 0; i < data2.length; i++) {
Object[] ds = data2[i];
DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
ls.add(item);
}
configuration.addSeries(ls);
ls = new DataSeries();
ls.setPlotOptions(new PlotOptionsSpline());
ls.setName("Winter 2009-2010");
Object[][] data3 = getData3();
for (int i = 0; i < data3.length; i++) {
Object[] ds = data3[i];
DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
ls.add(item);
}
configuration.addSeries(ls);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.AxisTitle 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.AxisTitle in project charts by vaadin.
the class TimeDataWithIrregularIntervalsAndLocalizedTexts method getChart.
@Override
protected Component getChart() {
// localizations
final Lang fi = new Lang();
fi.setDecimalPoint(",");
fi.setShortMonths(new String[] { "Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu" });
fi.setMonths(new String[] { "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu" });
fi.setWeekdays(new String[] { "Ma", "Ti", "Ke", "To", "Pe", "La", "Su" });
final Lang en = new Lang();
en.setDecimalPoint(".");
en.setShortMonths(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" });
en.setMonths(new String[] { "January", "February", "March", "April", "May", "June", "Jule", "August", "September", "October", "November", "December" });
en.setWeekdays(new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" });
final Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getTitle().setText("Lumen syvyys Vikjafjellet-tunturilla, Norja");
configuration.getSubTitle().setText("Lokalisointiesimerkki");
configuration.getTooltip().setFormatter("");
configuration.getxAxis().setType(AxisType.DATETIME);
configuration.getxAxis().setDateTimeLabelFormats(new DateTimeLabelFormats());
configuration.getxAxis().getDateTimeLabelFormats().setMonth("%B");
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Lumen syvyys (m)"));
yAxis.setMin(0);
DataSeries ls = new DataSeries();
PlotOptionsSpline plotOptionsSpline = new PlotOptionsSpline();
plotOptionsSpline.setDataLabels(new DataLabels(true));
plotOptionsSpline.setEnableMouseTracking(false);
plotOptionsSpline.getDataLabels().setFormatter("return Highcharts.dateFormat('%a %d %B',this.x);");
ls.setPlotOptions(plotOptionsSpline);
ls.setName("Talvi 2009-2010");
Object[][] data3 = getData3();
for (int i = 0; i < data3.length; i++) {
Object[] ds = data3[i];
DataSeriesItem item = new DataSeriesItem((Date) ds[0], (Double) ds[1]);
ls.add(item);
}
configuration.addSeries(ls);
chart.drawChart(configuration);
final Button enButton = new Button("English");
enButton.setId("en-button");
enButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
ChartOptions.get().setLang(en);
}
});
final Button fiButton = new Button("Finnish");
fiButton.setId("fi-button");
fiButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
ChartOptions.get().setLang(fi);
}
});
HorizontalLayout horizontalLayout = new HorizontalLayout(enButton, fiButton);
horizontalLayout.setSpacing(false);
VerticalLayout verticalLayout = new VerticalLayout(horizontalLayout, chart);
verticalLayout.setSpacing(false);
verticalLayout.setMargin(false);
return verticalLayout;
}
Aggregations