use of com.vaadin.addon.charts.model.AxisTitle 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.AxisTitle in project charts by vaadin.
the class BasicLineWithNavigator 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().setType(AxisType.DATETIME);
YAxis yAxis = configuration.getyAxis();
yAxis.setMin(-5d);
yAxis.setTitle(new AxisTitle("Temperature (°C)"));
yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
DataSeries ds = new DataSeries();
ds.setName("Tokyo");
List<Double> values = Arrays.asList(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
Calendar calendar = getCalendar();
for (Double value : values) {
DataSeriesItem item = new DataSeriesItem(calendar.getTime(), value);
ds.add(item);
calendar.add(Calendar.MONTH, 1);
}
configuration.addSeries(ds);
ds = new DataSeries();
ds.setName("New York");
values = Arrays.asList(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
calendar = getCalendar();
for (Double value : values) {
DataSeriesItem item = new DataSeriesItem(calendar.getTime(), value);
ds.add(item);
calendar.add(Calendar.MONTH, 1);
}
configuration.addSeries(ds);
Navigator navigator = configuration.getNavigator();
navigator.setMargin(75);
navigator.setEnabled(true);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.AxisTitle 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