Search in sources :

Example 36 with YAxis

use of com.vaadin.flow.component.charts.model.YAxis in project flow-components by vaadin.

the class CompareMultipleSeries method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart();
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    YAxis yAxis = new YAxis();
    Labels label = new Labels();
    label.setFormatter("function() { return (this.value > 0 ? ' + ' : '') + this.value + '%'; }");
    yAxis.setLabels(label);
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setPointFormat("<span>{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>");
    tooltip.setValueDecimals(2);
    configuration.setTooltip(tooltip);
    DataSeries aaplSeries = new DataSeries();
    aaplSeries.setName("AAPL");
    for (StockPrices.PriceData data : StockPrices.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        aaplSeries.add(item);
    }
    DataSeries googSeries = new DataSeries();
    googSeries.setName("GOOG");
    for (StockPrices.PriceData data : StockPrices.fetchGoogPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        googSeries.add(item);
    }
    DataSeries msftSeries = new DataSeries();
    msftSeries.setName("MSFT");
    for (StockPrices.PriceData data : StockPrices.fetchMsftPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        msftSeries.add(item);
    }
    configuration.setSeries(aaplSeries, googSeries, msftSeries);
    PlotOptionsSeries plotOptionsSeries = new PlotOptionsSeries();
    plotOptionsSeries.setCompare(Compare.PERCENT);
    configuration.setPlotOptions(plotOptionsSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    configuration.setRangeSelector(rangeSelector);
    add(chart);
}
Also used : StockPrices(com.vaadin.flow.component.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.flow.component.charts.model.Configuration) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Labels(com.vaadin.flow.component.charts.model.Labels) PlotLine(com.vaadin.flow.component.charts.model.PlotLine) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 37 with YAxis

use of com.vaadin.flow.component.charts.model.YAxis in project flow-components by vaadin.

the class SVGGeneratorTest method createAreaChartConfiguration.

private Configuration createAreaChartConfiguration() {
    Configuration configuration = new Configuration();
    configuration.setTitle("First Chart for Flow");
    configuration.getChart().setType(ChartType.AREA);
    Tooltip tooltip = configuration.getTooltip();
    tooltip.setEnabled(true);
    tooltip.setShared(true);
    PlotOptionsSeries options = new PlotOptionsSeries();
    options.setPointStart(0);
    options.setPointIntervalUnit(IntervalUnit.DAY);
    configuration.setPlotOptions(options);
    configuration.addSeries(new ListSeries("Tokyo", 20, 12, 34, 23, 65, 8, 4, 7, 76, 19, 20, 8));
    configuration.addSeries(new ListSeries("Miami", 34, 29, 23, 65, 8, 4, 7, 7, 59, 8, 9, 19));
    XAxis x = new XAxis();
    x.setType(AxisType.DATETIME);
    x.getLabels().setFormat("{value:%a}");
    configuration.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    y.setTitle("Rainfall (mm)");
    configuration.addyAxis(y);
    return configuration;
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Aggregations

YAxis (com.vaadin.flow.component.charts.model.YAxis)37 Configuration (com.vaadin.flow.component.charts.model.Configuration)32 Chart (com.vaadin.flow.component.charts.Chart)31 XAxis (com.vaadin.flow.component.charts.model.XAxis)27 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)21 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)17 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)15 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)11 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)10 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)10 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)9 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)8 Legend (com.vaadin.flow.component.charts.model.Legend)8 Labels (com.vaadin.flow.component.charts.model.Labels)7 Pane (com.vaadin.flow.component.charts.model.Pane)4 PlotOptionsArea (com.vaadin.flow.component.charts.model.PlotOptionsArea)4 PlotOptionsLine (com.vaadin.flow.component.charts.model.PlotOptionsLine)4 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)4 Crosshair (com.vaadin.flow.component.charts.model.Crosshair)3 PlotBand (com.vaadin.flow.component.charts.model.PlotBand)3