use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class SplineInverted method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setWidth("500px");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getChart().setInverted(true);
configuration.getTitle().setText("Atmosphere Temperature by Altitude");
configuration.getSubTitle().setText("According to the Standard Atmosphere Model");
XAxis xAxis = configuration.getxAxis();
xAxis.setReversed(false);
xAxis.setTitle(new AxisTitle("Altitude"));
Labels labels = new Labels();
labels.setFormatter("this.value + 'km'");
labels.setEnabled(true);
xAxis.setLabels(labels);
xAxis.setMaxPadding(0.05);
xAxis.setShowLastLabel(true);
YAxis yAxis = configuration.getyAxis();
yAxis.setLineWidth(2);
yAxis.setTitle(new AxisTitle("Temperature"));
yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
Labels labelsy = new Labels();
labelsy.setEnabled(true);
labelsy.setFormatter("this.value + '°'");
yAxis.setLabels(labelsy);
configuration.getTooltip().setFormatter("this.x +' km: '+this.y +'°C'");
PlotOptionsSpline plotOptions = new PlotOptionsSpline();
plotOptions.setMarker(new Marker(true));
configuration.setPlotOptions(plotOptions);
Legend legend = configuration.getLegend();
legend.setEnabled(false);
DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsSpline());
series.setName("Temperature");
series.addData(new Number[][] { { 0, 15 }, { 10, -50 }, { 20, -56.5 }, { 30, -46.5 }, { 40, -22.1 }, { 50, -2.5 }, { 60, -27.7 }, { 70, -55.7 }, { 80, -76.5 } });
configuration.setSeries(series);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class SplineUpdatingEachSecond method getChart.
@Override
protected Component getChart() {
final Random random = new Random();
final Chart chart = new Chart();
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getTitle().setText("Live random data");
XAxis xAxis = configuration.getxAxis();
xAxis.setType(AxisType.DATETIME);
xAxis.setTickPixelInterval(150);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
configuration.getTooltip().setEnabled(false);
configuration.getLegend().setEnabled(false);
final DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsSpline());
series.setName("Random data");
for (int i = -19; i <= 0; i++) {
series.add(new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble()));
}
runWhileAttached(chart, new Runnable() {
@Override
public void run() {
final long x = System.currentTimeMillis();
final double y = random.nextDouble();
series.add(new DataSeriesItem(x, y), true, true);
}
}, 1000, 1000);
configuration.setSeries(series);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class SplineUpdatingEachSecondWithCustomizedNewPoints method getChart.
@Override
protected Component getChart() {
final Random random = new Random();
final Chart chart = new Chart();
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getTitle().setText("Live random data");
XAxis xAxis = configuration.getxAxis();
xAxis.setType(AxisType.DATETIME);
xAxis.setTickPixelInterval(150);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
configuration.getTooltip().setEnabled(false);
configuration.getLegend().setEnabled(false);
final DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsSpline());
series.setName("Random data");
for (int i = -19; i <= 0; i++) {
DataSeriesItem item = new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble());
series.add(item);
}
runWhileAttached(chart, new Runnable() {
@Override
public void run() {
final long x = System.currentTimeMillis();
final double y = random.nextDouble();
DataSeriesItem item = new DataSeriesItem(x, y);
item.setName("Diipaiapa");
Marker marker = new Marker();
marker.setEnabled(true);
boolean b = (new Random().nextInt(5) % 4 == 0);
marker.setFillColor(new SolidColor(b ? "#ff0000" : "#000000"));
item.setMarker(marker);
series.add(item, true, true);
}
}, 1000, 1000);
configuration.setSeries(series);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class PolarChart method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
conf.getChart().setPolar(true);
conf.setTitle("Polar Chart");
Pane pane = new Pane(0, 360);
conf.addPane(pane);
pane.setBackground(new Background[] {});
XAxis axis = new XAxis();
axis.setTickInterval(45);
axis.setMin(0);
axis.setMax(360);
Labels labels = new Labels();
labels.setFormatter("function() {return this.value + '°';}");
axis.setLabels(labels);
YAxis yaxs = new YAxis();
yaxs.setMin(0);
conf.addxAxis(axis);
conf.addyAxis(yaxs);
PlotOptionsSeries series = new PlotOptionsSeries();
PlotOptionsColumn column = new PlotOptionsColumn();
series.setPointStart(0);
series.setPointInterval(45);
column.setPointPadding(0);
column.setGroupPadding(0);
conf.setPlotOptions(series, column);
ListSeries col = new ListSeries(8, 7, 6, 5, 4, 3, 2, 1);
ListSeries line = new ListSeries(1, 2, 3, 4, 5, 6, 7, 8);
ListSeries area = new ListSeries(1, 8, 2, 7, 3, 6, 4, 5);
col.setPlotOptions(new PlotOptionsColumn());
col.setName(ChartType.COLUMN.toString());
line.setPlotOptions(new PlotOptionsLine());
line.setName(ChartType.LINE.toString());
area.setPlotOptions(new PlotOptionsArea());
area.setName(ChartType.AREA.toString());
conf.setSeries(col, line, area);
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.model.XAxis in project charts by vaadin.
the class BasicLineWithRedGridLines method getChart.
@Override
protected Component getChart() {
Chart 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);
yAxis.setGridLineColor(new SolidColor("red"));
yAxis.setGridLineDashStyle(DashStyle.DASHDOT);
yAxis.setGridLineWidth(3);
XAxis xAxis = configuration.getxAxis();
xAxis.setGridLineColor(new SolidColor(0, 255, 0, 0.5));
xAxis.setGridLineWidth(4);
PlotOptionsLine plotOptions = new PlotOptionsLine();
plotOptions.setDataLabels(new DataLabels(true));
configuration.setPlotOptions(plotOptions);
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;
}
Aggregations