Search in sources :

Example 1 with PlotLine

use of com.vaadin.addon.charts.model.PlotLine in project charts by vaadin.

the class RangeSelectorCustomDateParser method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    YAxis yAxis = new YAxis();
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    plotLine.setColor(SolidColor.SILVER);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    DataSeries aaplSeries = new DataSeries();
    for (StockPrices.PriceData data : StockPrices.fetchAaplPriceWithTime()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        aaplSeries.add(item);
    }
    configuration.setSeries(aaplSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    ButtonTheme theme = new ButtonTheme();
    Style style = new Style();
    style.setColor(new SolidColor("#0766d8"));
    style.setFontWeight(FontWeight.BOLD);
    theme.setStyle(style);
    rangeSelector.setButtonTheme(theme);
    Style inputStyle = new Style();
    inputStyle.setColor(new SolidColor("#0766d8"));
    inputStyle.setFontWeight(FontWeight.BOLD);
    rangeSelector.setInputStyle(inputStyle);
    rangeSelector.setInputDateFormat("%H:%M:%S.%L");
    rangeSelector.setInputEditDateFormat("%H:%M:%S.%L");
    // All the data is for 2009 Jan 28, so we don't bother to parse date only parse time
    rangeSelector.setInputDateParser("function(value) {" + "value = value.split(/[:\\.]/);\n" + "return Date.UTC(\n" + "   2009,\n" + "   0,\n" + "   28,\n" + "   parseInt(value[0], 10),\n" + "   parseInt(value[1], 10),\n" + "   parseInt(value[2], 10),\n" + "   parseInt(value[3], 10)" + ");}");
    configuration.setRangeSelector(rangeSelector);
    chart.drawChart(configuration);
    return chart;
}
Also used : StockPrices(com.vaadin.addon.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.addon.charts.model.Configuration) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) Style(com.vaadin.addon.charts.model.style.Style) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) ButtonTheme(com.vaadin.addon.charts.model.style.ButtonTheme) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 2 with PlotLine

use of com.vaadin.addon.charts.model.PlotLine in project charts by vaadin.

the class CompareMultipleSeries method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    YAxis yAxis = new YAxis();
    Labels label = new Labels();
    label.setFormatter("(this.value > 0 ? ' + ' : '') + this.value + '%'");
    yAxis.setLabels(label);
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    plotLine.setColor(SolidColor.SILVER);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setPointFormat("<span style=\"color:{series.color}\">{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(PERCENT);
    configuration.setPlotOptions(plotOptionsSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    configuration.setRangeSelector(rangeSelector);
    chart.drawChart(configuration);
    return chart;
}
Also used : StockPrices(com.vaadin.addon.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.addon.charts.model.Configuration) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) Tooltip(com.vaadin.addon.charts.model.Tooltip) Labels(com.vaadin.addon.charts.model.Labels) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 3 with PlotLine

use of com.vaadin.addon.charts.model.PlotLine in project charts by vaadin.

the class SplineUpdatingEachSecondWithTwoLines method getChart.

@Override
protected Component getChart() {
    final Random random = new Random();
    final Chart chart = new Chart();
    chart.setWidth("500px");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Live random data");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setType(AxisType.DATETIME);
    xAxis.setTickPixelInterval(150);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Value"));
    yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
    configuration.getTooltip().setEnabled(false);
    configuration.getLegend().setEnabled(false);
    final DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsSpline());
    series.setName("Random data");
    for (int i = -19; i <= 0; i++) {
        series.add(new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble()));
    }
    final DataSeries series2 = new DataSeries();
    series2.setPlotOptions(new PlotOptionsSpline());
    series2.setName("Random data");
    for (int i = -19; i <= 0; i++) {
        series2.add(new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble()));
    }
    runWhileAttached(chart, new Runnable() {

        @Override
        public void run() {
            long x = System.currentTimeMillis();
            series.add(new DataSeriesItem(x, random.nextDouble()), true, true);
            series2.add(new DataSeriesItem(x, random.nextDouble()), true, true);
        }
    }, 1000, 1000);
    configuration.setSeries(series, series2);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) XAxis(com.vaadin.addon.charts.model.XAxis) Random(java.util.Random) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 4 with PlotLine

use of com.vaadin.addon.charts.model.PlotLine in project charts by vaadin.

the class ChartDesignWriterTest method writeConfiguration_plotLines_thePlotLinesAreTheElement.

@Test
public void writeConfiguration_plotLines_thePlotLinesAreTheElement() {
    DesignContext designContext = new DesignContext();
    Configuration configuration = new Configuration();
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(0);
    plotLine.setWidth(2);
    configuration.getyAxis().setPlotLines(plotLine);
    Element parent = new Element(Tag.valueOf("test"), "");
    ChartDesignWriter.writeConfigurationToElement(configuration, parent, designContext);
    assertEquals("<y-axis><plot-lines value=\"0\" width=\"2\"></plot-lines></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) PlotLine(com.vaadin.addon.charts.model.PlotLine) Test(org.junit.Test)

Example 5 with PlotLine

use of com.vaadin.addon.charts.model.PlotLine in project charts by vaadin.

the class RangeSelectorButtons method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    YAxis yAxis = new YAxis();
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    plotLine.setColor(SolidColor.SILVER);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    DataSeries aaplSeries = new DataSeries();
    for (StockPrices.PriceData data : StockPrices.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        aaplSeries.add(item);
    }
    configuration.setSeries(aaplSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(1);
    RangeSelectorButton button = new RangeSelectorButton(MONTH, 3, "D");
    DataGrouping grouping = new DataGrouping();
    grouping.setForced(true);
    grouping.setUnits(new TimeUnitMultiples(TimeUnit.DAY, 1));
    button.setDataGrouping(grouping);
    rangeSelector.addButton(button);
    button = new RangeSelectorButton(YEAR, 1, "W");
    grouping = new DataGrouping();
    grouping.setForced(true);
    grouping.setUnits(new TimeUnitMultiples(TimeUnit.WEEK, 1));
    button.setDataGrouping(grouping);
    rangeSelector.addButton(button);
    button = new RangeSelectorButton(ALL, "M");
    grouping = new DataGrouping();
    grouping.setForced(true);
    grouping.setUnits(new TimeUnitMultiples(TimeUnit.MONTH, 1));
    button.setDataGrouping(grouping);
    rangeSelector.addButton(button);
    configuration.setRangeSelector(rangeSelector);
    chart.drawChart(configuration);
    return chart;
}
Also used : StockPrices(com.vaadin.addon.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.addon.charts.model.Configuration) TimeUnitMultiples(com.vaadin.addon.charts.model.TimeUnitMultiples) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) DataGrouping(com.vaadin.addon.charts.model.DataGrouping) RangeSelectorButton(com.vaadin.addon.charts.model.RangeSelectorButton) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

PlotLine (com.vaadin.addon.charts.model.PlotLine)10 Chart (com.vaadin.addon.charts.Chart)9 Configuration (com.vaadin.addon.charts.model.Configuration)9 DataSeries (com.vaadin.addon.charts.model.DataSeries)9 YAxis (com.vaadin.addon.charts.model.YAxis)9 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)7 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)7 XAxis (com.vaadin.addon.charts.model.XAxis)6 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)5 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)3 PlotOptionsSeries (com.vaadin.addon.charts.model.PlotOptionsSeries)3 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)3 RangeSelector (com.vaadin.addon.charts.model.RangeSelector)3 Random (java.util.Random)3 Legend (com.vaadin.addon.charts.model.Legend)2 Tooltip (com.vaadin.addon.charts.model.Tooltip)2 Style (com.vaadin.addon.charts.model.style.Style)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 ChartClickEvent (com.vaadin.addon.charts.ChartClickEvent)1 ChartClickListener (com.vaadin.addon.charts.ChartClickListener)1