Search in sources :

Example 1 with DataLabelsRange

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

the class ColumnRange method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMNRANGE);
    Configuration conf = chart.getConfiguration();
    conf.getChart().setInverted(true);
    conf.setTitle("Temperature variation by month");
    conf.setSubTitle("Observed in Vik i Sogn, Norway, 2009");
    XAxis xAxis = new XAxis();
    xAxis.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle("Temperature ( °C )");
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setValueSuffix("°C");
    conf.setTooltip(tooltip);
    PlotOptionsColumnrange columnRange = new PlotOptionsColumnrange();
    columnRange.setDataLabels(new DataLabelsRange(true));
    columnRange.getDataLabels().setFormatter("function() {return this.y + '°C';}");
    conf.setPlotOptions(columnRange);
    conf.getLegend().setEnabled(false);
    // RangeSeries has some helper constructors of which example below, but
    // here we use the raw DataSeries API
    // RangeSeries data = new RangeSeries("Temperatures", getRawData());
    DataSeries data = new DataSeries();
    data.setName("Temperatures");
    for (Number[] minMaxPair : getRawData()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setLow(minMaxPair[0]);
        item.setHigh(minMaxPair[1]);
        data.add(item);
    }
    conf.setSeries(data);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumnrange(com.vaadin.addon.charts.model.PlotOptionsColumnrange) DataLabelsRange(com.vaadin.addon.charts.model.DataLabelsRange) Tooltip(com.vaadin.addon.charts.model.Tooltip) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 2 with DataLabelsRange

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

the class ContainerSeriesWithHighAndLow method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMNRANGE);
    Configuration conf = chart.getConfiguration();
    conf.getChart().setInverted(true);
    conf.setTitle("Temperature variation by month");
    conf.setSubTitle("Observed in Vik i Sogn, Norway, 2009");
    XAxis xAxis = new XAxis();
    xAxis.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle("Temperature ( °C )");
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setValueSuffix("°C");
    conf.setTooltip(tooltip);
    PlotOptionsColumnrange columnRange = new PlotOptionsColumnrange();
    columnRange.setDataLabels(new DataLabelsRange(true));
    columnRange.getDataLabels().setFormatter("function() {return this.y + '°C';}");
    conf.setPlotOptions(columnRange);
    conf.getLegend().setEnabled(false);
    IndexedContainer vaadinContainer = new IndexedContainer();
    vaadinContainer.addContainerProperty("min", Number.class, null);
    vaadinContainer.addContainerProperty("max", Number.class, null);
    for (Number[] minMaxPair : getRawData()) {
        Item item = vaadinContainer.getItem(vaadinContainer.addItem());
        item.getItemProperty("min").setValue(minMaxPair[0]);
        item.getItemProperty("max").setValue(minMaxPair[1]);
    }
    ContainerDataSeries data = new ContainerDataSeries(vaadinContainer);
    data.setLowPropertyId("min");
    data.setHighPropertyId("max");
    data.setName("Temperatures");
    conf.setSeries(data);
    return chart;
}
Also used : Item(com.vaadin.v7.data.Item) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumnrange(com.vaadin.addon.charts.model.PlotOptionsColumnrange) DataLabelsRange(com.vaadin.addon.charts.model.DataLabelsRange) Tooltip(com.vaadin.addon.charts.model.Tooltip) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) ContainerDataSeries(com.vaadin.v7.addon.charts.model.ContainerDataSeries) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 3 with DataLabelsRange

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

the class DataProviderSeriesWithHighAndLow method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMNRANGE);
    Configuration conf = chart.getConfiguration();
    conf.getChart().setInverted(true);
    conf.setTitle("Temperature variation by month");
    conf.setSubTitle("Observed in Vik i Sogn, Norway, 2009");
    XAxis xAxis = new XAxis();
    xAxis.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle("Temperature ( °C )");
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setValueSuffix("°C");
    conf.setTooltip(tooltip);
    PlotOptionsColumnrange columnRange = new PlotOptionsColumnrange();
    columnRange.setDataLabels(new DataLabelsRange(true));
    columnRange.getDataLabels().setFormatter("function() {return this.y + '°C';}");
    conf.setPlotOptions(columnRange);
    conf.getLegend().setEnabled(false);
    conf.setSeries(createChartDS());
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumnrange(com.vaadin.addon.charts.model.PlotOptionsColumnrange) DataLabelsRange(com.vaadin.addon.charts.model.DataLabelsRange) Tooltip(com.vaadin.addon.charts.model.Tooltip) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 4 with DataLabelsRange

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

the class ColumnRangeResourceUsage method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMNRANGE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Resource usage");
    conf.getChart().setInverted(true);
    XAxis xAxis = new XAxis();
    xAxis.setCategories("Printer", "Coffee mahine");
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle("Time");
    yAxis.setType(AxisType.DATETIME);
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.series.name +': '+ Highcharts.dateFormat('%H:%M', this.point.low) + ' - ' + Highcharts.dateFormat('%H:%M', this.point.high)");
    conf.setTooltip(tooltip);
    PlotOptionsColumnrange columnRange = new PlotOptionsColumnrange();
    columnRange.setGrouping(false);
    DataLabelsRange dataLabels = new DataLabelsRange(true);
    dataLabels.setFormatter("this.y == this.point.low ? '' : this.series.name");
    dataLabels.setInside(true);
    dataLabels.setColor(new SolidColor("white"));
    columnRange.setDataLabels(dataLabels);
    conf.setPlotOptions(columnRange);
    Calendar instance = Calendar.getInstance();
    instance.set(Calendar.MILLISECOND, 0);
    instance.set(2013, 6, 7, 12, 00, 00);
    DataSeries a = new DataSeries();
    a.setName("Team Alpha");
    PlotOptionsColumnrange o = new PlotOptionsColumnrange();
    o.setColor(new SolidColor(255, 60, 125, 0.8));
    a.setPlotOptions(o);
    DataSeries b = new DataSeries();
    o = new PlotOptionsColumnrange();
    o.setColor(new SolidColor(60, 125, 255, 0.8));
    b.setPlotOptions(o);
    b.setName("Team Beta");
    DataSeriesItem item;
    item = new DataSeriesItem();
    item.setName("Printer");
    item.setLow(instance.getTimeInMillis());
    instance.roll(Calendar.HOUR_OF_DAY, 3);
    item.setHigh(instance.getTimeInMillis());
    a.add(item);
    item = new DataSeriesItem();
    item.setName("Printer");
    instance.roll(Calendar.HOUR_OF_DAY, 1);
    item.setLow(instance.getTimeInMillis());
    instance.roll(Calendar.HOUR_OF_DAY, 1);
    item.setHigh(instance.getTimeInMillis());
    b.add(item);
    instance.set(2013, 6, 7, 12, 00, 00);
    item = new DataSeriesItem();
    item.setName("Coffee mahine");
    item.setLow(instance.getTimeInMillis());
    instance.roll(Calendar.HOUR_OF_DAY, 2);
    item.setHigh(instance.getTimeInMillis());
    b.add(item);
    item = new DataSeriesItem();
    item.setName("Coffee mahine");
    instance.roll(Calendar.HOUR_OF_DAY, -1);
    item.setLow(instance.getTimeInMillis());
    instance.roll(Calendar.HOUR_OF_DAY, 4);
    item.setHigh(instance.getTimeInMillis());
    a.add(item);
    conf.setSeries(a, b);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumnrange(com.vaadin.addon.charts.model.PlotOptionsColumnrange) DataLabelsRange(com.vaadin.addon.charts.model.DataLabelsRange) Tooltip(com.vaadin.addon.charts.model.Tooltip) Calendar(java.util.Calendar) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

Chart (com.vaadin.addon.charts.Chart)4 Configuration (com.vaadin.addon.charts.model.Configuration)4 DataLabelsRange (com.vaadin.addon.charts.model.DataLabelsRange)4 PlotOptionsColumnrange (com.vaadin.addon.charts.model.PlotOptionsColumnrange)4 Tooltip (com.vaadin.addon.charts.model.Tooltip)4 XAxis (com.vaadin.addon.charts.model.XAxis)4 YAxis (com.vaadin.addon.charts.model.YAxis)4 DataSeries (com.vaadin.addon.charts.model.DataSeries)2 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)2 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)1 ContainerDataSeries (com.vaadin.v7.addon.charts.model.ContainerDataSeries)1 Item (com.vaadin.v7.data.Item)1 IndexedContainer (com.vaadin.v7.data.util.IndexedContainer)1 Calendar (java.util.Calendar)1