use of com.vaadin.addon.charts.model.DataSeriesItem 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.DataSeriesItem 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.DataSeriesItem in project charts by vaadin.
the class FunnelChartExample method getChart.
@Override
protected Component getChart() {
DataSeries dataSeries = new DataSeries("Unique users");
dataSeries.add(new DataSeriesItem("Website visits", 15654));
dataSeries.add(new DataSeriesItem("Downloads", 4064));
dataSeries.add(new DataSeriesItem("Requested price list", 1987));
dataSeries.add(new DataSeriesItem("Invoice sent", 976));
dataSeries.add(new DataSeriesItem("Finalized", 846));
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
conf.setTitle("Sales funnel");
conf.getLegend().setEnabled(false);
PlotOptionsFunnel options = new PlotOptionsFunnel();
options.setReversed(false);
options.setNeckWidth("30%");
options.setNeckHeight("30%");
options.setWidth("70%");
DataLabelsFunnel dataLabels = new DataLabelsFunnel();
dataLabels.setFormat("<b>{point.name}</b> ({point.y:,.0f})");
options.setDataLabels(dataLabels);
dataSeries.setPlotOptions(options);
conf.addSeries(dataSeries);
return chart;
}
use of com.vaadin.addon.charts.model.DataSeriesItem in project charts by vaadin.
the class PartialUpdateConflicts method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setHeight("200px");
final ListSeries listSeries = new ListSeries(data);
chart.getConfiguration().addSeries(listSeries);
Button button = new Button("Do stuff", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
listSeries.addData(100, true, true);
ArrayUtils.reverse(data);
chart.getConfiguration().setSeries(new ListSeries(data));
chart.drawChart();
}
});
button.setId("b1");
final Chart chart2 = new Chart();
chart2.setHeight("200px");
final DataSeries ds = new DataSeries();
int i = 0;
for (Integer value : data) {
ds.add(new DataSeriesItem(i++, value));
}
chart2.getConfiguration().addSeries(ds);
Button button2 = new Button("Do stuff DataSeries", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
final DataSeriesItem dataSeriesItem = new DataSeriesItem(ds.size(), new Random().nextInt(10));
ds.add(dataSeriesItem);
ArrayUtils.reverse(data);
chart2.getConfiguration().setSeries(new ListSeries(data));
chart2.drawChart();
}
});
button2.setId("b2");
VerticalLayout verticalLayout = new VerticalLayout(chart, button, chart2, button2);
verticalLayout.setSpacing(false);
verticalLayout.setMargin(false);
return verticalLayout;
}
use of com.vaadin.addon.charts.model.DataSeriesItem 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;
}
Aggregations