use of com.vaadin.addon.charts.Chart in project charts by vaadin.
the class ColumnSite method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.COLUMN);
Configuration conf = chart.getConfiguration();
conf.setTitle("Earnings");
conf.setSubTitle("2011 - 2014");
XAxis xAxis = conf.getxAxis();
xAxis.setCategories("2011", "2012", "2013", "2014");
YAxis yAxis = conf.getyAxis();
yAxis.setTitle("B€");
Tooltip tooltip = conf.getTooltip();
tooltip.setPointFormat("{series.name}: {point.y} B€");
conf.addSeries(new ListSeries("Revenue", 1.5, 1.8, 1.2, 2.3));
conf.addSeries(new ListSeries("Expenses", 1.2, 1.1, 1.3, 0.9));
conf.addSeries(new ListSeries("Net income", -0.3, 0.7, -0.1, 1.4));
return chart;
}
use of com.vaadin.addon.charts.Chart in project charts by vaadin.
the class PieSite method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.PIE);
Configuration conf = chart.getConfiguration();
conf.setTitle("Revenue by industry");
conf.setSubTitle("2015");
Tooltip tooltip = conf.getTooltip();
tooltip.setPointFormat("<b>{point.percentage:.1f}%</b>");
PlotOptionsPie plotOptions = new PlotOptionsPie();
plotOptions.setAllowPointSelect(true);
plotOptions.setCursor(Cursor.POINTER);
plotOptions.setShowInLegend(true);
DataLabels dataLabels = plotOptions.getDataLabels();
dataLabels.setEnabled(true);
dataLabels.setFormat("{point.name}: {point.y:.1f} M€");
conf.setPlotOptions(plotOptions);
DataSeries series = new DataSeries("Revenue");
series.add(new DataSeriesItem("Aerospace", 90.0));
series.add(new DataSeriesItem("Medical", 53.6));
series.add(new DataSeriesItem("Agriculture", 25.6));
series.add(new DataSeriesItem("Automotive", 17.0));
series.add(new DataSeriesItem("Consumers", 12.4));
series.add(new DataSeriesItem("Subsidies", 1.4));
conf.setSeries(series);
return chart;
}
use of com.vaadin.addon.charts.Chart 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.Chart in project charts by vaadin.
the class AreaRange method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.AREARANGE);
Configuration conf = chart.getConfiguration();
conf.setTitle("Temperature variation by day");
conf.getxAxis().setType(DATETIME);
conf.getxAxis().setCrosshair(new Crosshair());
conf.addyAxis(new YAxis());
Tooltip tooltip = new Tooltip();
tooltip.setShared(true);
tooltip.setValueSuffix("°C");
conf.setTooltip(tooltip);
RangeSeries data = new RangeSeries("Temperatures", getRawData());
conf.setSeries(data);
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.Chart in project charts by vaadin.
the class LargeDataSet method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.getConfiguration().setTitle("Large data set");
// Force zoom and enable scrollbar
chart.getConfiguration().getxAxis().setMin(5000);
chart.getConfiguration().getScrollbar().setEnabled(true);
DataSeries series = new DataSeries();
Number[] data = TimeSeriesZoomable.USD_TO_EUR_EXCHANGE_RATES;
Random r = new Random(0);
int x = 0;
for (int j = 0; j < ROUNDS; j++) {
for (Number number : data) {
DataSeriesItem item;
if (xyPairs()) {
x += r.nextInt(4);
item = new DataSeriesItem(x, number);
} else {
// interval data (x == index of data point), performs better
// and consumes less memory/bandwidth
item = new DataSeriesItem();
item.setY(number);
}
/*
* Note, with large datasets, avoid settings like
* item.setColor(myColorX), or item.setName(myName) for data
* items. Without them the framework is able to optimize the
* rendering and can survive from rather large datasets.
*
* Also note, that if data set is very large, the library might
* ignore it if there are custom settings for data items. This
* threshold is called turboThreshHold in plot options. See
* example below.
*/
// item.setName("x " + x);
series.add(item);
}
}
/*
* If you play with this example your might try uncomment next line to
* keep the amount of transfered data sane. You might also try to
* increase the ROUNDS to increase the input data. By default commented
* out to stress client side performance
*/
// reduce(series, 1000);
/*
* If data can contain high/low peaks, one can use more sophisticated
* algorithms
*/
// ramerDouglasPeuckerReduce(series, 300);
chart.getConfiguration().setSeries(series);
PlotOptionsLine plotOptionsLine = new PlotOptionsLine();
// Showing points with thousands of data items looks odd (on top of each
// other), also renders faster without markers
plotOptionsLine.setMarker(new Marker(false));
// To render shadow, library must create additional element, without it
// performance will be better
plotOptionsLine.setShadow(false);
plotOptionsLine.setAnimation(false);
/*
* If developers need to use large data sets and point specific
* settings, they can override the default turbo threshold. Here we set
* it to 200000 (default 1000). Turbo threshold is configuration that
* works as a "sanity threshold" so that old browsers wont drop to their
* knees under load. Without this Vaadin Charts might not render chart
* if data items have e.g. name set.
*/
plotOptionsLine.setTurboThreshold(200000);
chart.getConfiguration().setPlotOptions(plotOptionsLine);
return chart;
}
Aggregations