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;
}
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;
}
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;
}
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()));
}
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;
}
Aggregations