private Chart createChart(int points) { Chart chart = new Chart(ChartType.SCATTER); Configuration conf = chart.getConfiguration(); conf.getChart().setZoomType(ZoomType.XY); conf.disableCredits(); conf.setTitle("Height vs Weight"); conf.setSubTitle("Polygon series in Vaadin Charts."); Tooltip tooltip = conf.getTooltip(); tooltip.setHeaderFormat("{series.name}"); tooltip.setPointFormat("{point.x} cm, {point.y} kg"); XAxis xAxis = conf.getxAxis(); xAxis.setStartOnTick(true); xAxis.setEndOnTick(true); xAxis.setShowLastLabel(true); xAxis.setTitle("Height (cm)"); YAxis yAxis = conf.getyAxis(); yAxis.setTitle("Weight (kg)"); AbstractLinePlotOptions plotOptions = new PlotOptionsScatter(); plotOptions.setThreshold(0); DataSeries scatter = new DataSeries(); scatter.setPlotOptions(plotOptions); scatter.setName("Observations"); fillScatter(scatter, points); conf.addSeries(scatter); return chart; }
@Override protected Component getChart() { chart = new Chart(); chart.getConfiguration().setTitle("Box Plot Example"); Legend legend = new Legend(); legend.setEnabled(false); chart.getConfiguration().setLegend(legend); XAxis xaxis = chart.getConfiguration().getxAxis(); xaxis.setTitle("Experiment No."); xaxis.setCategories("1", "2", "3", "4", "5"); YAxis yAxis = chart.getConfiguration().getyAxis(); yAxis.setTitle("Observations"); PlotLine plotLine = new PlotLine(); plotLine.setColor(new SolidColor("red")); plotLine.setValue(932); plotLine.setWidth(1); PlotBandLabel label = new PlotBandLabel("Theoretical mean: 932"); label.setAlign(HorizontalAlign.CENTER); Style style = new Style(); style.setColor(new SolidColor("gray")); label.setStyle(style); plotLine.setLabel(label); yAxis.setPlotLines(plotLine); observations = new DataSeries(); observations.setName("Observations"); // Add PlotBoxItems contain all fields relevant for plot box chart observations.add(new BoxPlotItem(760, 801, 848, 895, 965)); // Example with no arg constructor BoxPlotItem plotBoxItem = new BoxPlotItem(); plotBoxItem.setLow(733); plotBoxItem.setLowerQuartile(853); plotBoxItem.setMedian(939); plotBoxItem.setUpperQuartile(980); plotBoxItem.setHigh(1080); observations.add(plotBoxItem); observations.add(new BoxPlotItem(714, 762, 817, 870, 918)); observations.add(new BoxPlotItem(724, 802, 806, 871, 950)); observations.add(new BoxPlotItem(834, 836, 864, 882, 910)); observations.setPlotOptions(getPlotBoxOptions()); chart.getConfiguration().addSeries(observations); return chart; }
private Configuration createConf() { Configuration conf = new Configuration(); conf.setTitle("Historic World Population by Region"); conf.setSubTitle("Source: Wikipedia.org"); XAxis x = new XAxis(); x.setCategories("Africa", "America", "Asia", "Europe", "Oceania"); x.setTitle((String) null); conf.addxAxis(x); YAxis y = new YAxis(); y.setMin(0); Title title = new Title("Population (millions)"); title.setVerticalAlign(VerticalAlign.HIGH); y.setTitle(title); conf.addyAxis(y); Tooltip tooltip = new Tooltip(); tooltip.setFormatter("this.series.name +': '+ this.y +' millions'"); conf.setTooltip(tooltip); PlotOptionsBar plot = new PlotOptionsBar(); plot.setDataLabels(new Labels(true)); conf.setPlotOptions(plot); Legend legend = new Legend(); legend.setLayout(LayoutDirection.VERTICAL); legend.setHorizontalAlign(HorizontalAlign.RIGHT); legend.setVerticalAlign(VerticalAlign.TOP); legend.setX(-100); legend.setY(100); legend.setFloating(true); legend.setBorderWidth(1); legend.setBackgroundColor("#FFFFFF"); legend.setShadow(true); conf.setLegend(legend); conf.disableCredits(); List<Series> series = new ArrayList<Series>(); series.add(new ListSeries("Year 1800", 107, 31, 635, 203, 2)); series.add(new ListSeries("Year 1900", 133, 156, 947, 408, 6)); series.add(new ListSeries("Year 2008", 973, 914, 4054, 732, 34)); conf.setSeries(series); return conf; }