Search in sources :

Example 31 with AxisTitle

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;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Title(com.vaadin.addon.charts.model.Title) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 32 with AxisTitle

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;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Title(com.vaadin.addon.charts.model.Title) PlotBand(com.vaadin.addon.charts.model.PlotBand) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 33 with AxisTitle

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"));
}
Also used : DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis) Test(org.junit.Test)

Example 34 with AxisTitle

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()));
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Element(org.jsoup.nodes.Element) DesignContext(com.vaadin.ui.declarative.DesignContext) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Test(org.junit.Test)

Example 35 with AxisTitle

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;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) DataSeries(com.vaadin.addon.charts.model.DataSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

AxisTitle (com.vaadin.addon.charts.model.AxisTitle)53 Configuration (com.vaadin.addon.charts.model.Configuration)52 YAxis (com.vaadin.addon.charts.model.YAxis)50 Chart (com.vaadin.addon.charts.Chart)49 ListSeries (com.vaadin.addon.charts.model.ListSeries)30 XAxis (com.vaadin.addon.charts.model.XAxis)26 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)25 DataLabels (com.vaadin.addon.charts.model.DataLabels)18 DataSeries (com.vaadin.addon.charts.model.DataSeries)18 Tooltip (com.vaadin.addon.charts.model.Tooltip)16 Legend (com.vaadin.addon.charts.model.Legend)15 Marker (com.vaadin.addon.charts.model.Marker)14 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)12 Labels (com.vaadin.addon.charts.model.Labels)12 Title (com.vaadin.addon.charts.model.Title)12 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)11 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)11 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)10 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)10 Hover (com.vaadin.addon.charts.model.Hover)9