use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class PieWithGradientFill method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.PIE);
Configuration conf = chart.getConfiguration();
conf.setTitle("Browser market shares at a specific website, 2010");
PlotOptionsPie plotOptions = new PlotOptionsPie();
plotOptions.setCursor(Cursor.POINTER);
DataLabels dataLabels = new DataLabels();
dataLabels.setEnabled(true);
dataLabels.setColor(SolidColor.BLACK);
dataLabels.setConnectorColor(SolidColor.BLACK);
dataLabels.setFormatter("'<b>'+ this.point.name +'</b>: '+ this.percentage +' %'");
plotOptions.setDataLabels(dataLabels);
conf.setPlotOptions(plotOptions);
final DataSeries series = getBrowserMarketShareSeries();
conf.setSeries(series);
chart.drawChart();
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(false);
layout.setMargin(false);
layout.addComponent(chart);
CheckBox button = new CheckBox("Slice one part");
button.addValueChangeListener(e -> {
series.setItemSliced(1, e.getValue());
});
layout.addComponent(button);
return layout;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class PieWithLegend method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.PIE);
Configuration conf = chart.getConfiguration();
conf.setTitle("Browser market shares at a specific website, 2010");
Tooltip tooltip = new Tooltip();
tooltip.setValueDecimals(1);
tooltip.setPointFormat("{series.name}: <b>{point.percentage}%</b>");
conf.setTooltip(tooltip);
PlotOptionsPie plotOptions = new PlotOptionsPie();
plotOptions.setAllowPointSelect(true);
plotOptions.setCursor(Cursor.POINTER);
plotOptions.setShowInLegend(true);
conf.setPlotOptions(plotOptions);
DataSeries series = new DataSeries();
series.add(new DataSeriesItem("Firefox", 45.0));
series.add(new DataSeriesItem("IE", 26.8));
DataSeriesItem chrome = new DataSeriesItem("Chrome", 12.8);
chrome.setSliced(true);
chrome.setSelected(true);
series.add(chrome);
series.add(new DataSeriesItem("Safari", 8.5));
series.add(new DataSeriesItem("Opera", 6.2));
series.add(new DataSeriesItem("Others", 0.7));
conf.setSeries(series);
chart.addLegendItemClickListener(new LegendItemClickListener() {
@Override
public void onClick(LegendItemClickEvent event) {
Notification.show("Legend item click" + " : " + event.getSeriesItemIndex() + " : " + ((DataSeries) event.getSeries()).get(event.getSeriesItemIndex()).getName());
}
});
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class PieWithNativeDrilldown method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.PIE);
Configuration conf = chart.getConfiguration();
conf.setTitle("Browser market share, April, 2011");
conf.setSubTitle("Click the columns to view versions. Click again to view brands.");
conf.getLegend().setEnabled(false);
PlotOptionsPie column = new PlotOptionsPie();
column.setCursor(Cursor.POINTER);
column.setDataLabels(new DataLabels(true));
conf.setPlotOptions(column);
Tooltip tooltip = new Tooltip();
tooltip.setHeaderFormat("<span style=\"font-size:11px\">{series.name}</span><br>");
tooltip.setPointFormat("<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>");
conf.setTooltip(tooltip);
DataSeries series = new DataSeries();
series.setName("Browser brands");
DataSeriesItem item = new DataSeriesItem("MSIE", 55.11);
DataSeries drillSeries = new DataSeries("MSIE versions");
drillSeries.setId("MSIE");
String[] categories = new String[] { "MSIE 6.0", "MSIE 7.0", "MSIE 8.0", "MSIE 9.0" };
Number[] ys = new Number[] { 10.85, 7.35, 33.06, 2.81 };
drillSeries.setData(categories, ys);
series.addItemWithDrilldown(item, drillSeries);
item = new DataSeriesItem("Firefox", 21.63);
drillSeries = new DataSeries("Firefox versions");
drillSeries.setId("Firefox");
categories = new String[] { "Firefox 2.0", "Firefox 3.0", "Firefox 3.5", "Firefox 3.6", "Firefox 4.0" };
ys = new Number[] { 0.20, 0.83, 1.58, 13.12, 5.43 };
drillSeries.setData(categories, ys);
series.addItemWithDrilldown(item, drillSeries);
item = new DataSeriesItem("Chrome", 11.94);
drillSeries = new DataSeries("Chrome versions");
drillSeries.setId("Chrome");
categories = new String[] { "Chrome 5.0", "Chrome 6.0", "Chrome 7.0", "Chrome 8.0", "Chrome 9.0", "Chrome 10.0", "Chrome 11.0", "Chrome 12.0" };
ys = new Number[] { 0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22 };
drillSeries.setData(categories, ys);
series.addItemWithDrilldown(item, drillSeries);
item = new DataSeriesItem("Safari", 7.15);
series.add(item);
item = new DataSeriesItem("Opera", 2.14);
drillSeries = new DataSeries("Opera versions");
drillSeries.setId("Opera");
categories = new String[] { "Opera 9.x", "Opera 10.x", "Opera 11.x" };
ys = new Number[] { 0.12, 0.37, 1.65 };
drillSeries.setData(categories, ys);
series.addItemWithDrilldown(item, drillSeries);
conf.addSeries(series);
Drilldown drilldown = conf.getDrilldown();
Style style = new Style();
style.setFontWeight(BOLD);
style.setColor(FIREBRICK);
style.setFontSize("16px");
drilldown.setActiveDataLabelStyle(style);
DrillUpButton button = drilldown.getDrillUpButton();
button.setRelativeTo(SPACINGBOX);
DrillUpButtonTheme theme = new DrillUpButtonTheme();
GradientColor gradient1 = GradientColor.createLinear(0, 0, 0, 1);
gradient1.addColorStop(0, ALICEBLUE);
gradient1.addColorStop(1, ANTIQUEWHITE);
theme.setFill(gradient1);
button.setTheme(theme);
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class SVGGeneratorTest method testWide.
@Test
public void testWide() throws InterruptedException, URISyntaxException {
Configuration conf = new Configuration();
conf.getChart().setType(ChartType.COLUMN);
conf.getChart().setMarginRight(200);
Legend legend = conf.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.MIDDLE);
legend.setBorderWidth(0);
Random r = new Random();
for (int i = 0; i < 20; i++) {
String name = RandomStringUtils.randomAlphabetic(r.nextInt(20));
DataSeries dataSeries = new DataSeries(name);
dataSeries.add(new DataSeriesItem(name, r.nextInt(100)));
conf.addSeries(dataSeries);
}
SVGGenerator instance = SVGGenerator.getInstance();
String generatedSVG = instance.withHeight(400).withWidth(1200).generate(conf);
Assert.assertTrue(generatedSVG.contains("width=\"1200\""));
Assert.assertTrue(generatedSVG.contains("height=\"400\""));
SVGGenerator.getInstance().destroy();
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class ServerSideEvents method getChart.
@Override
protected Component getChart() {
eventDetails.setId("eventDetails");
lastEvent.setId("lastEvent");
historyLayout.setId("history");
chart = new Chart();
chart.setId("chart");
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SCATTER);
configuration.getTitle().setText("Test server side events.");
configuration.getSubTitle().setText("When an event occurs, the details are shown below the chart");
configuration.setExporting(true);
configuration.getChart().setAnimation(false);
configuration.getChart().setZoomType(ZoomType.XY);
XAxis xAxis = configuration.getxAxis();
xAxis.setMinPadding(0.2);
xAxis.setMaxPadding(0.2);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
PlotLine plotline = new PlotLine();
plotline.setValue(0);
plotline.setWidth(1);
plotline.setColor(new SolidColor("#808080"));
yAxis.setPlotLines(new PlotLine[] { plotline });
yAxis.setMinPadding(0.2);
yAxis.setMaxPadding(0.2);
YAxis yAxis1 = new YAxis();
yAxis1.setTitle("Another axis");
yAxis1.setOpposite(true);
configuration.addyAxis(yAxis1);
PlotOptionsSeries opt = new PlotOptionsSeries();
opt.setLineWidth(1);
opt.setShowCheckbox(true);
opt.setAllowPointSelect(true);
configuration.setPlotOptions(opt);
configuration.setTooltip(new Tooltip(false));
final DataSeries series1 = createDataSeries(0);
final DataSeries series2 = createDataSeries(20);
DataSeries series3 = createDataSeries(100);
series3.get(0).setY(105);
series3.get(3).setY(95);
series3.setName("Another axis");
series3.setyAxis(1);
firstDataPoint = series1.get(0);
firstDataPoint.setSelected(true);
configuration.setSeries(series1, series2, series3);
chart.drawChart(configuration);
final Layout toggles = createControls();
Layout eventListeners = addEventListeners();
chart.setSeriesVisibilityTogglingDisabled(false);
visibilityToggling.setValue(false);
lastEvent.setCaption("Last event");
eventDetails.setCaption("Details");
historyLayout.setCaption("History");
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.addComponent(toggles);
HorizontalLayout chartAndListeners = new HorizontalLayout(chart, eventListeners);
chartAndListeners.setSizeUndefined();
chartAndListeners.setSpacing(true);
layout.addComponent(chartAndListeners);
layout.addComponent(lastEvent);
layout.addComponent(eventDetails);
layout.addComponent(historyLayout);
return layout;
}
Aggregations