use of com.vaadin.addon.charts.model.TimeUnitMultiples in project charts by vaadin.
the class TimeUnitMultiplesJSONSerializationTest method toJSON_axisWithUnits_TimeUnitMultiplesCorrectlySerialized.
@Test
public void toJSON_axisWithUnits_TimeUnitMultiplesCorrectlySerialized() {
YAxis yaxis = new YAxis();
TimeUnitMultiples unitMillisecond = new TimeUnitMultiples(TimeUnit.MILLISECOND, 1, 2, 5, 10, 20, 25, 50, 100, 200, 500);
TimeUnitMultiples unitSecond = new TimeUnitMultiples(TimeUnit.SECOND, 1, 2, 5, 10, 15, 30);
TimeUnitMultiples unitMinute = new TimeUnitMultiples(TimeUnit.MINUTE, 1, 2, 5, 10, 15, 30);
TimeUnitMultiples unitHour = new TimeUnitMultiples(TimeUnit.HOUR, 1, 2, 3, 4, 6, 8, 12);
TimeUnitMultiples unitDay = new TimeUnitMultiples(TimeUnit.DAY, 1);
TimeUnitMultiples unitWeek = new TimeUnitMultiples(TimeUnit.WEEK, 1);
TimeUnitMultiples unitMonth = new TimeUnitMultiples(TimeUnit.MONTH, 1, 3, 6);
TimeUnitMultiples unitYear = new TimeUnitMultiples(TimeUnit.YEAR, null);
yaxis.setUnits(unitMillisecond, unitSecond, unitMinute, unitHour, unitDay, unitWeek, unitMonth, unitYear);
// units array should look like this
// units: [
// ['millisecond', [1, 2, 5, 10, 20, 25, 50, 100, 200, 500]],
// ['second', [1, 2, 5, 10, 15, 30]],
// ['minute',[1, 2, 5, 10, 15, 30]],
// ['hour',[1, 2, 3, 4, 6, 8, 12]],
// ['day',[1]],
// ['week',[1]],
// ['month',[1, 3, 6]],
// ['year',null]
// ]
String expected = "{\"units\":[[\"millisecond\",[1,2,5,10,20,25,50,100,200,500]],[\"second\",[1,2,5,10,15,30]],[\"minute\",[1,2,5,10,15,30]],[\"hour\",[1,2,3,4,6,8,12]],[\"day\",[1]],[\"week\",[1]],[\"month\",[1,3,6]],[\"year\",null]]}";
assertEquals(expected, toJSON(yaxis));
}
use of com.vaadin.addon.charts.model.TimeUnitMultiples in project charts by vaadin.
the class Candlestick method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart(ChartType.CANDLESTICK);
chart.setHeight("450px");
chart.setWidth("100%");
chart.setTimeline(true);
Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("AAPL Stock Price");
DataSeries dataSeries = new DataSeries();
PlotOptionsCandlestick plotOptionsCandlestick = new PlotOptionsCandlestick();
DataGrouping grouping = new DataGrouping();
grouping.addUnit(new TimeUnitMultiples(TimeUnit.WEEK, 1));
grouping.addUnit(new TimeUnitMultiples(TimeUnit.MONTH, 1, 2, 3, 4, 6));
plotOptionsCandlestick.setDataGrouping(grouping);
dataSeries.setPlotOptions(plotOptionsCandlestick);
for (StockPrices.OhlcData data : StockPrices.fetchAaplOhlcPrice()) {
OhlcItem item = new OhlcItem();
item.setX(data.getDate());
item.setLow(data.getLow());
item.setHigh(data.getHigh());
item.setClose(data.getClose());
item.setOpen(data.getOpen());
dataSeries.add(item);
}
configuration.setSeries(dataSeries);
RangeSelector rangeSelector = new RangeSelector();
rangeSelector.setSelected(4);
configuration.setRangeSelector(rangeSelector);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.TimeUnitMultiples in project charts by vaadin.
the class Ohlc method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart(ChartType.OHLC);
chart.setHeight("450px");
chart.setWidth("100%");
chart.setTimeline(true);
Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("AAPL Stock Price");
DataSeries dataSeries = new DataSeries();
PlotOptionsOhlc plotOptionsOhlc = new PlotOptionsOhlc();
DataGrouping grouping = new DataGrouping();
grouping.addUnit(new TimeUnitMultiples(TimeUnit.WEEK, 1));
grouping.addUnit(new TimeUnitMultiples(TimeUnit.MONTH, 1, 2, 3, 4, 6));
plotOptionsOhlc.setDataGrouping(grouping);
dataSeries.setPlotOptions(plotOptionsOhlc);
for (StockPrices.OhlcData data : StockPrices.fetchAaplOhlcPrice()) {
OhlcItem item = new OhlcItem();
item.setX(data.getDate());
item.setLow(data.getLow());
item.setHigh(data.getHigh());
item.setClose(data.getClose());
item.setOpen(data.getOpen());
dataSeries.add(item);
}
configuration.setSeries(dataSeries);
RangeSelector rangeSelector = new RangeSelector();
rangeSelector.setSelected(1);
configuration.setRangeSelector(rangeSelector);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.TimeUnitMultiples 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