use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class StackedPercentageColumn method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.COLUMN);
Configuration conf = chart.getConfiguration();
conf.setTitle(new Title("Total fruit consumption, grouped by gender"));
XAxis xAxis = new XAxis();
xAxis.setCategories(new String[] { "Apples", "Oranges", "Pears", "Grapes", "Bananas" });
conf.addxAxis(xAxis);
YAxis yAxis = new YAxis();
yAxis.setMin(0);
yAxis.setTitle(new AxisTitle("Total fruit consumption"));
conf.addyAxis(yAxis);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("this.series.name +': '+ this.y +' ('+ Math.round(this.percentage) +'%)'");
conf.setTooltip(tooltip);
PlotOptionsColumn plotOptions = new PlotOptionsColumn();
plotOptions.setStacking(Stacking.PERCENT);
conf.setPlotOptions(plotOptions);
conf.addSeries(new ListSeries("John", new Number[] { 5, 3, 4, 7, 2 }));
conf.addSeries(new ListSeries("Jane", new Number[] { 2, 2, 3, 2, 1 }));
conf.addSeries(new ListSeries("Joe", new Number[] { 3, 4, 4, 2, 5 }));
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class AreaSpline method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.AREASPLINE);
chart.setHeight("450px");
Configuration conf = chart.getConfiguration();
conf.setTitle(new Title("Average fruit consumption during one week"));
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.LEFT);
legend.setFloating(true);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(150);
legend.setY(100);
conf.setLegend(legend);
XAxis xAxis = new XAxis();
xAxis.setCategories(new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" });
// add blue background for the weekend
PlotBand plotBand = new PlotBand(4.5, 6.5, LIGHT_BLUE);
plotBand.setZIndex(1);
xAxis.setPlotBands(plotBand);
conf.addxAxis(xAxis);
YAxis yAxis = new YAxis();
yAxis.setTitle(new AxisTitle("Fruit units"));
conf.addyAxis(yAxis);
Tooltip tooltip = new Tooltip();
// Customize tooltip formatting
tooltip.setHeaderFormat("");
tooltip.setPointFormat("{series.name}: {point.y} units");
// Same could be achieved by defining following JS formatter funtion:
// tooltip.setFormatter("function(){ return this.x +': '+ this.y +' units';}");
// ... or its shorthand form:
// tooltip.setFormatter("this.x +': '+ this.y +' units'");
conf.setTooltip(tooltip);
PlotOptionsArea plotOptions = new PlotOptionsArea();
plotOptions.setFillOpacity(0.5);
conf.setPlotOptions(plotOptions);
ListSeries o = new ListSeries("John", 3, 4, 3, 5, 4, 10);
// Add last value separately
o.addData(12);
conf.addSeries(o);
conf.addSeries(new ListSeries("Jane", 1, 3, 4, 3, 3, 5, 4));
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class ConfigurationTest method setSeries_containerDataSeriesWithName_NameAppearsInLegend.
@Test
public void setSeries_containerDataSeriesWithName_NameAppearsInLegend() {
Configuration conf = new Configuration();
conf.getChart().setType(ChartType.AREA);
XAxis xAxis = new XAxis();
xAxis.setCategories("A", "B", "C", "D", "E");
conf.addxAxis(xAxis);
YAxis yAxis = new YAxis();
AxisTitle title = new AxisTitle();
title.setText("Numbers");
yAxis.setTitle(title);
conf.addyAxis(yAxis);
DataProviderSeries<Pair> ds = new DataProviderSeries<>(createDataProvider());
ds.setName("Test Series1");
ds.setY(Pair::getValue);
ds.setPointName(Pair::getName);
// if a 'plotOptionsArea' is not set, the name of this series will not
// be shown in legend
// containerDataSeries1.setPlotOptions(new PlotOptionsArea());
conf.setSeries(ds);
Assert.assertTrue(toJSON(conf).contains("Test Series1"));
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class ChartDesignWriterTest method writeConfiguration_yAxisWithTitle_theYAxisWithTitleIsInTheElement.
@Test
public void writeConfiguration_yAxisWithTitle_theYAxisWithTitleIsInTheElement() {
DesignContext designContext = new DesignContext();
Configuration configuration = new Configuration();
AxisTitle title = new AxisTitle("Temperature");
configuration.getyAxis().setTitle(title);
Element parent = new Element(Tag.valueOf("test"), "");
ChartDesignWriter.writeConfigurationToElement(configuration, parent, designContext);
assertEquals("<y-axis><chart-title text=\"Temperature\"></chart-title></y-axis>", removeWhitespacesBetweenTags(parent.child(0).toString()));
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class BasicLineWithCallouts 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.getTitle().setText("CALLOUT: Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Temperature (°C)"));
configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
PlotOptionsLine plotOptions = new PlotOptionsLine();
Labels dataLabels = new Labels(false);
plotOptions.setEnableMouseTracking(false);
configuration.setPlotOptions(plotOptions);
DataSeries ds = new DataSeries();
ds.setName("Tokyo");
ds.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
DataLabels callout = new DataLabels(true);
callout.setShape(Shape.CALLOUT);
callout.setBackgroundColor(SolidColor.BLANCHEDALMOND);
callout.setY(-12);
ds.get(5).setDataLabels(callout);
configuration.addSeries(ds);
ds = new DataSeries();
ds.setName("London");
ds.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
ds.get(7).setDataLabels(callout);
configuration.addSeries(ds);
chart.drawChart(configuration);
return chart;
}
Aggregations