Search in sources :

Example 66 with DataSeriesItem

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

the class Clock method getChart.

@Override
protected Chart getChart() {
    final Chart chart = new Chart();
    chart.setWidth("500px");
    chart.setHeight("200px");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.GAUGE);
    configuration.getChart().setPlotBackgroundColor(null);
    configuration.getChart().setPlotBackgroundImage(null);
    configuration.getChart().setPlotBorderWidth(0);
    configuration.getChart().setPlotShadow(false);
    configuration.setTitle("The Vaadin Charts clock");
    configuration.getCredits().setEnabled(false);
    GradientColor gradient1 = GradientColor.createRadial(0.5, -0.4, 1.9);
    gradient1.addColorStop(0.5, new SolidColor(255, 255, 255, 0.2));
    gradient1.addColorStop(0.5, new SolidColor(200, 200, 200, 0.2));
    Background[] background = new Background[2];
    background[0] = new Background();
    background[1] = new Background();
    background[1].setBackgroundColor(gradient1);
    background[1].setBorderWidth(1);
    background[1].setOuterRadius("107%");
    configuration.getPane().setBackground(background);
    YAxis yAxis = configuration.getyAxis();
    Labels labels = new Labels();
    labels.setDistance(-20);
    yAxis.setLabels(labels);
    yAxis.setMin(0);
    yAxis.setMax(12);
    yAxis.setLineWidth(0);
    yAxis.setShowFirstLabel(false);
    yAxis.setMinorTickInterval("auto");
    yAxis.setMinorTickWidth(1);
    yAxis.setMinorTickLength(5);
    yAxis.setMinorTickPosition(TickPosition.INSIDE);
    yAxis.setMinorGridLineWidth(0);
    yAxis.setMinorTickColor(new SolidColor("#666"));
    yAxis.setTickInterval(1);
    yAxis.setTickWidth(2);
    yAxis.setTickPosition(TickPosition.INSIDE);
    yAxis.setTickLength(10);
    yAxis.setTickColor(new SolidColor("#666"));
    yAxis.setTitle(new AxisTitle("Powered by<br/>Vaadin Charts"));
    yAxis.getTitle().setStyle(new Style());
    yAxis.getTitle().getStyle().setColor(new SolidColor("#BBB"));
    yAxis.getTitle().getStyle().setFontWeight(FontWeight.BOLD);
    yAxis.getTitle().getStyle().setFontSize("8px");
    yAxis.getTitle().getStyle().setLineHeight("10px");
    yAxis.getTitle().setY(10);
    final DataSeries series = new DataSeries();
    final DataSeriesItem hour = new DataSeriesItem();
    final DataSeriesItem minute = new DataSeriesItem();
    final DataSeriesItem second = new DataSeriesItem();
    hour.setId("hour");
    hour.setY(10);
    hour.setDial(new Dial());
    hour.getDial().setRadius("60%");
    hour.getDial().setBaseWidth(4);
    hour.getDial().setRearLength("0%");
    hour.getDial().setBaseLength("95%");
    minute.setId("minute");
    minute.setY(10);
    minute.setDial(new Dial());
    minute.getDial().setBaseLength("95%");
    minute.getDial().setRearLength("0%");
    second.setId("second");
    second.setY(30);
    second.setDial(new Dial());
    second.getDial().setRadius("100%");
    second.getDial().setBaseWidth(1);
    second.getDial().setRearLength("20%");
    series.add(hour);
    series.add(minute);
    series.add(second);
    PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
    plotOptionsGauge.setDataLabels(new DataLabels(false));
    configuration.setPlotOptions(plotOptionsGauge);
    configuration.setSeries(series);
    final Calendar cal = Calendar.getInstance();
    runWhileAttached(chart, new Runnable() {

        @Override
        public void run() {
            cal.setTimeInMillis(System.currentTimeMillis());
            double hours = cal.get(Calendar.HOUR);
            double mins = cal.get(Calendar.MINUTE);
            double secs = cal.get(Calendar.SECOND);
            // disable animation when the second dial reaches 0
            boolean animation = secs == 0 ? false : true;
            configuration.getChart().setAnimation(animation);
            hour.setY(hours + (mins / 60.0));
            minute.setY(mins * (12.0 / 60.0) + secs * (12.0 / 3600.0));
            second.setY(secs * (12.0 / 60.0));
            series.update(hour);
            series.update(minute);
            series.update(second);
        }
    }, 1000, 15000);
    chart.drawChart(configuration);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) Background(com.vaadin.addon.charts.model.Background) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) Calendar(java.util.Calendar) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) Dial(com.vaadin.addon.charts.model.Dial) PlotOptionsGauge(com.vaadin.addon.charts.model.PlotOptionsGauge) Style(com.vaadin.addon.charts.model.style.Style) 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 67 with DataSeriesItem

use of com.vaadin.addon.charts.model.DataSeriesItem 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)

Example 68 with DataSeriesItem

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

the class PyramidChartExample method getChart.

@Override
protected Component getChart() {
    DataSeries dataSeries = new DataSeries("Unique users");
    dataSeries.add(new DataSeriesItem("Website visits", 15654));
    dataSeries.add(new DataSeriesItem("Downloads", 4064));
    dataSeries.add(new DataSeriesItem("Requested price list", 1987));
    dataSeries.add(new DataSeriesItem("Invoice sent", 976));
    dataSeries.add(new DataSeriesItem("Finalized", 846));
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Sales pyramid");
    conf.getLegend().setEnabled(false);
    PlotOptionsPyramid options = new PlotOptionsPyramid();
    // With default (90%), long labels in this example may be cut
    options.setWidth(70, Unit.PERCENTAGE);
    // in pixels
    // options.setWidth(400);
    DataLabelsFunnel dataLabels = new DataLabelsFunnel();
    dataLabels.setFormat("<b>{point.name}</b> ({point.y:,.0f})");
    options.setDataLabels(dataLabels);
    dataSeries.setPlotOptions(options);
    conf.addSeries(dataSeries);
    return chart;
}
Also used : DataLabelsFunnel(com.vaadin.addon.charts.model.DataLabelsFunnel) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsPyramid(com.vaadin.addon.charts.model.PlotOptionsPyramid) DataSeries(com.vaadin.addon.charts.model.DataSeries) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) Chart(com.vaadin.addon.charts.Chart)

Example 69 with DataSeriesItem

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

the class DateAxisAndClickEvent method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Date axis and click events");
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getxAxis().setType(AxisType.DATETIME);
    Calendar c = Calendar.getInstance();
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.HOUR_OF_DAY, 12);
    c.set(2013, 2, 11);
    DataSeries dataSeries = new DataSeries();
    Number[] values = new Number[] { 71.5, 29.9, 106.4 };
    Random r = new Random(0);
    for (Number number : values) {
        c.add(Calendar.MINUTE, r.nextInt(5));
        DataSeriesItem item = new DataSeriesItem(c.getTime(), number);
        dataSeries.add(item);
    }
    configuration.addSeries(dataSeries);
    chart.drawChart(configuration);
    chart.addChartClickListener(new ChartClickListener() {

        @Override
        public void onClick(ChartClickEvent event) {
            /*
                 * The axis value is in client side library's raw format: unix
                 * timestamp, "shifted" to UTC time zone
                 */
            ;
            double timeStampShiftedToUc = event.getxAxisValue();
            /*
                 * When working with Date objects, developers probably want to
                 * convert it to Date object at their local time zone.
                 */
            Notification.show("Clicked @ " + Util.toServerInstant(timeStampShiftedToUc));
        }
    });
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            /*
                 * Same with point clicks...
                 */
            ;
            double timeStampShiftedToUc = event.getX();
            Notification.show("Clicked Point with Date value " + Util.toServerInstant(timeStampShiftedToUc));
        }
    });
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Calendar(java.util.Calendar) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) ChartClickEvent(com.vaadin.addon.charts.ChartClickEvent) ChartClickListener(com.vaadin.addon.charts.ChartClickListener) Random(java.util.Random) PointClickListener(com.vaadin.addon.charts.PointClickListener) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 70 with DataSeriesItem

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

the class LineWithMissingPoint method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.LINE);
    configuration.getChart().setMarginRight(130);
    configuration.getChart().setMarginBottom(25);
    configuration.getTitle().setText("Monthly Average Temperature");
    configuration.getSubTitle().setText("Source: WorldClimate.com");
    configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setMin(-5d);
    yAxis.setTitle(new AxisTitle("Temperature (°C)"));
    yAxis.getTitle().setAlign(VerticalAlign.HIGH);
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setDataLabels(new DataLabels(true));
    configuration.setPlotOptions(plotOptions);
    Legend legend = configuration.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-10d);
    legend.setY(100d);
    legend.setBorderWidth(0);
    DataSeries ds = new DataSeries();
    DataSeriesItem item = new DataSeriesItem(1, 2);
    item.setName("a");
    ds.add(item);
    item = new DataSeriesItem(2, 2);
    item.setName("b");
    ds.add(item);
    item = new DataSeriesItem(3, 2);
    item.setName("c");
    ds.add(item);
    item = new DataSeriesItem(4, null);
    item.setName("d");
    ds.add(item);
    item = new DataSeriesItem(5, 2);
    item.setName("e");
    ds.add(item);
    item = new DataSeriesItem(6, 2);
    item.setName("f");
    ds.add(item);
    configuration.addSeries(ds);
    chart.drawChart(configuration);
    System.out.println(configuration);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) 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)

Aggregations

DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)88 DataSeries (com.vaadin.addon.charts.model.DataSeries)81 Chart (com.vaadin.addon.charts.Chart)57 Configuration (com.vaadin.addon.charts.model.Configuration)51 YAxis (com.vaadin.addon.charts.model.YAxis)27 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)19 DataLabels (com.vaadin.addon.charts.model.DataLabels)17 XAxis (com.vaadin.addon.charts.model.XAxis)17 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)12 Random (java.util.Random)12 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)11 Test (org.junit.Test)11 Tooltip (com.vaadin.addon.charts.model.Tooltip)10 Marker (com.vaadin.addon.charts.model.Marker)9 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)8 PlotLine (com.vaadin.addon.charts.model.PlotLine)7 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)7 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)6 ListSeries (com.vaadin.addon.charts.model.ListSeries)6 Style (com.vaadin.addon.charts.model.style.Style)6