use of com.vaadin.flow.component.charts.model.PlotOptionsScatter in project flow-components by vaadin.
the class ScatterAndPolygon method initDemo.
@Override
public void initDemo() {
final Chart chart = new Chart(ChartType.SCATTER);
Configuration conf = chart.getConfiguration();
chart.setId("chart");
conf.getChart().setZoomType(Dimension.XY);
conf.disableCredits();
conf.setTitle("Height vs Weight");
conf.setSubTitle("Polygon series in Vaadin Charts.");
Tooltip tooltip = conf.getTooltip();
tooltip.setHeaderFormat("<b>{series.name}</b><br>");
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)");
PlotOptionsScatter plotOptionsScatter = new PlotOptionsScatter();
DataSeries scatter = new DataSeries();
scatter.setPlotOptions(plotOptionsScatter);
scatter.setName("Observations");
fillScatter(scatter);
DataSeries polygon = new DataSeries();
PlotOptionsPolygon plotOptionsPolygon = new PlotOptionsPolygon();
plotOptionsPolygon.setEnableMouseTracking(false);
polygon.setPlotOptions(plotOptionsPolygon);
polygon.setName("Target");
polygon.add(new DataSeriesItem(153, 42));
polygon.add(new DataSeriesItem(149, 46));
polygon.add(new DataSeriesItem(149, 55));
polygon.add(new DataSeriesItem(152, 60));
polygon.add(new DataSeriesItem(159, 70));
polygon.add(new DataSeriesItem(170, 77));
polygon.add(new DataSeriesItem(180, 70));
polygon.add(new DataSeriesItem(180, 60));
polygon.add(new DataSeriesItem(173, 52));
polygon.add(new DataSeriesItem(166, 45));
conf.addSeries(polygon);
conf.addSeries(scatter);
add(chart);
}
use of com.vaadin.flow.component.charts.model.PlotOptionsScatter in project flow-components by vaadin.
the class Scatter method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart(ChartType.SCATTER);
Configuration configuration = chart.getConfiguration();
configuration.setTitle("Height Versus Weight of 507 Individuals by Gender");
configuration.setSubTitle("Source: Heinz 2003");
XAxis xAxis = configuration.getxAxis();
xAxis.setTitle("Height (cm)");
xAxis.setStartOnTick(true);
xAxis.setEndOnTick(true);
xAxis.setShowLastLabel(true);
Legend legend = configuration.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.LEFT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(100);
legend.setY(70);
legend.setFloating(true);
PlotOptionsScatter plotOptionsScatter = new PlotOptionsScatter();
SeriesTooltip scatterTooltip = plotOptionsScatter.getTooltip();
scatterTooltip.setHeaderFormat("<b>{series.name}</b><br>\",\"pointFormat\":\"{point.x} cm, {point.y} kg");
DataSeries femaleSeries = new DataSeries();
femaleSeries.setName("Female");
PlotOptionsScatter femalePlotOptions = new PlotOptionsScatter();
femalePlotOptions.setClassName("femaleSeries");
femaleSeries.setPlotOptions(femalePlotOptions);
Number[][] femaleData = getFemaleData();
for (int i = 0; i < femaleData.length; i++) {
DataSeriesItem item = new DataSeriesItem(femaleData[i][1], femaleData[i][0]);
femaleSeries.add(item);
}
configuration.addSeries(femaleSeries);
DataSeries maleSeries = new DataSeries();
maleSeries.setName("Male");
PlotOptionsScatter malePlotOptions = new PlotOptionsScatter();
malePlotOptions.setClassName("maleSeries");
maleSeries.setPlotOptions(malePlotOptions);
Number[][] maleData = getMaleData();
for (int i = 0; i < maleData.length; i++) {
DataSeriesItem item = new DataSeriesItem(maleData[i][1], maleData[i][0]);
maleSeries.add(item);
}
configuration.addSeries(maleSeries);
add(chart);
}
use of com.vaadin.flow.component.charts.model.PlotOptionsScatter in project flow-components by vaadin.
the class BoxPlot method initDemo.
@Override
public void initDemo() {
final Chart 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.setValue(932);
plotLine.setZIndex(0);
Label label = new Label("Theoretical mean: 932");
label.setAlign(HorizontalAlign.CENTER);
plotLine.setLabel(label);
yAxis.setPlotLines(plotLine);
final DataSeries 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));
PlotOptionsBoxplot plotOptions = new PlotOptionsBoxplot();
SeriesTooltip observationsTooltip = new SeriesTooltip();
observationsTooltip.setHeaderFormat("<em>Experiment No {point.key}</em><br/>");
plotOptions.setTooltip(observationsTooltip);
observations.setPlotOptions(plotOptions);
chart.getConfiguration().addSeries(observations);
final DataSeries outlier = new DataSeries();
outlier.setName("Outlier");
outlier.add(new DataSeriesItem(0, 644));
outlier.add(new DataSeriesItem(4, 718));
outlier.add(new DataSeriesItem(4, 951));
outlier.add(new DataSeriesItem(4, 969));
PlotOptionsScatter outlierOptions = new PlotOptionsScatter();
SeriesTooltip outlierTooltip = new SeriesTooltip();
outlierTooltip.setPointFormat("Observation: {point.y}");
outlierOptions.setTooltip(outlierTooltip);
outlier.setPlotOptions(outlierOptions);
chart.getConfiguration().addSeries(outlier);
Checkbox useCustomStyles = new Checkbox("Use custom styling");
useCustomStyles.addValueChangeListener(e -> {
PlotOptionsBoxplot options = new PlotOptionsBoxplot();
if (e.getValue()) {
options.setClassName("custom-style");
options.setWhiskerLength("70");
}
observations.setPlotOptions(options);
chart.drawChart(true);
});
add(chart, useCustomStyles);
}
Aggregations