Search in sources :

Example 11 with DataSeriesItem

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

the class PieWithCustomBorder method getBrowserMarketShareSeries.

private DataSeries getBrowserMarketShareSeries() {
    DataSeriesItem firefox = new DataSeriesItem("Firefox", 45.0);
    firefox.setColor(createRadialGradient(new SolidColor(255, 128, 0), new SolidColor(128, 64, 0)));
    DataSeriesItem ie = new DataSeriesItem("IE", 26.8);
    ie.setColor(createRadialGradient(new SolidColor(0, 255, 255), new SolidColor(0, 128, 128)));
    DataSeriesItem chrome = new DataSeriesItem("Chrome", 12.8);
    chrome.setColor(createRadialGradient(new SolidColor(255, 255, 0), new SolidColor(128, 128, 0)));
    chrome.setSliced(true);
    chrome.setSelected(true);
    DataSeriesItem safari = new DataSeriesItem("Safari", 8.5);
    safari.setColor(createRadialGradient(new SolidColor(0, 128, 255), new SolidColor(0, 64, 128)));
    DataSeriesItem opera = new DataSeriesItem("Opera", 6.2);
    opera.setColor(createRadialGradient(new SolidColor(255, 0, 0), new SolidColor(128, 0, 0)));
    DataSeriesItem others = new DataSeriesItem("Others", 0.7);
    others.setColor(createRadialGradient(new SolidColor(0, 128, 0), new SolidColor(0, 64, 0)));
    return new DataSeries(firefox, ie, chrome, safari, opera, others);
}
Also used : SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataSeries(com.vaadin.addon.charts.model.DataSeries) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 12 with DataSeriesItem

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

the class Basic3DPie method createChart.

public static Chart createChart() {
    Chart chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market shares at a specific website, 2010");
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.setCursor(Cursor.POINTER);
    DataLabels dataLabels = new DataLabels(true);
    dataLabels.setFormatter("'<b>'+ this.point.name +'</b>: '+ this.percentage +' %'");
    plotOptions.setDataLabels(dataLabels);
    plotOptions.setDepth(45);
    conf.setPlotOptions(plotOptions);
    final DataSeries series = new DataSeries();
    series.add(new DataSeriesItem("Firefox", 45.0));
    series.add(new DataSeriesItem("IE", 26.8));
    DataSeriesItem chrome = new DataSeriesItem("Chrome", 12.8);
    chrome.setSliced(true);
    chrome.setSelected(true);
    series.add(chrome);
    series.add(new DataSeriesItem("Safari", 8.5));
    series.add(new DataSeriesItem("Opera", 6.2));
    series.add(new DataSeriesItem("Others", 0.7));
    conf.setSeries(series);
    Options3d options3d = new Options3d();
    options3d.setEnabled(true);
    options3d.setAlpha(60);
    conf.getChart().setOptions3d(options3d);
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            Notification.show("Click: " + series.get(event.getPointIndex()).getName());
        }
    });
    chart.drawChart(conf);
    return chart;
}
Also used : PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) PointClickListener(com.vaadin.addon.charts.PointClickListener) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) Options3d(com.vaadin.addon.charts.model.Options3d)

Example 13 with DataSeriesItem

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

the class SerializationTest method serializeChart_configurationWithDrilldown_drilldownConfigurationLinkSerializedCorrectly.

@Test
public void serializeChart_configurationWithDrilldown_drilldownConfigurationLinkSerializedCorrectly() throws IOException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    Chart input = new Chart();
    DataSeries dataSeries = new DataSeries();
    ListSeries drilldownSeries = new ListSeries();
    drilldownSeries.setId("id");
    dataSeries.addItemWithDrilldown(new DataSeriesItem("foobar", 42), drilldownSeries);
    input.getConfiguration().addSeries(dataSeries);
    Chart output = serializeObject(input);
    Drilldown outputDrilldown = output.getConfiguration().getDrilldown();
    assertNotNull("Drilldown configuration link was null after serialization", outputDrilldown.getConfiguration());
}
Also used : Drilldown(com.vaadin.addon.charts.model.Drilldown) ListSeries(com.vaadin.addon.charts.model.ListSeries) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) Test(org.junit.Test)

Example 14 with DataSeriesItem

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

the class TimeDataWithIrregularIntervals method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Snow depth in the Vikjafjellet mountain, Norway");
    configuration.getSubTitle().setText("An example of irregular time data in Highcharts JS");
    configuration.getTooltip().setFormatter("");
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setDateTimeLabelFormats(new DateTimeLabelFormats("%e. %b", "%b"));
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Snow depth (m)"));
    yAxis.setMin(0);
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>\'+ Highcharts.dateFormat('%e. %b', this.x) +': '+ this.y +' m'");
    DataSeries ls = new DataSeries();
    ls.setPlotOptions(new PlotOptionsSpline());
    ls.setName("Winter 2007-2008");
    Object[][] data1 = getData1();
    for (int i = 0; i < data1.length; i++) {
        Object[] ds = data1[i];
        DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    ls = new DataSeries();
    ls.setPlotOptions(new PlotOptionsSpline());
    ls.setName("Winter 2008-2009");
    Object[][] data2 = getData2();
    for (int i = 0; i < data2.length; i++) {
        Object[] ds = data2[i];
        DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    ls = new DataSeries();
    ls.setPlotOptions(new PlotOptionsSpline());
    ls.setName("Winter 2009-2010");
    Object[][] data3 = getData3();
    for (int i = 0; i < data3.length; i++) {
        Object[] ds = data3[i];
        DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) DataSeries(com.vaadin.addon.charts.model.DataSeries) DateTimeLabelFormats(com.vaadin.addon.charts.model.DateTimeLabelFormats) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) 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 15 with DataSeriesItem

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

the class TimeDataWithIrregularIntervalsAndLocalizedTexts method getChart.

@Override
protected Component getChart() {
    // localizations
    final Lang fi = new Lang();
    fi.setDecimalPoint(",");
    fi.setShortMonths(new String[] { "Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu" });
    fi.setMonths(new String[] { "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu" });
    fi.setWeekdays(new String[] { "Ma", "Ti", "Ke", "To", "Pe", "La", "Su" });
    final Lang en = new Lang();
    en.setDecimalPoint(".");
    en.setShortMonths(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" });
    en.setMonths(new String[] { "January", "February", "March", "April", "May", "June", "Jule", "August", "September", "October", "November", "December" });
    en.setWeekdays(new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" });
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Lumen syvyys Vikjafjellet-tunturilla, Norja");
    configuration.getSubTitle().setText("Lokalisointiesimerkki");
    configuration.getTooltip().setFormatter("");
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setDateTimeLabelFormats(new DateTimeLabelFormats());
    configuration.getxAxis().getDateTimeLabelFormats().setMonth("%B");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Lumen syvyys (m)"));
    yAxis.setMin(0);
    DataSeries ls = new DataSeries();
    PlotOptionsSpline plotOptionsSpline = new PlotOptionsSpline();
    plotOptionsSpline.setDataLabels(new DataLabels(true));
    plotOptionsSpline.setEnableMouseTracking(false);
    plotOptionsSpline.getDataLabels().setFormatter("return Highcharts.dateFormat('%a %d %B',this.x);");
    ls.setPlotOptions(plotOptionsSpline);
    ls.setName("Talvi 2009-2010");
    Object[][] data3 = getData3();
    for (int i = 0; i < data3.length; i++) {
        Object[] ds = data3[i];
        DataSeriesItem item = new DataSeriesItem((Date) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    final Button enButton = new Button("English");
    enButton.setId("en-button");
    enButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            ChartOptions.get().setLang(en);
        }
    });
    final Button fiButton = new Button("Finnish");
    fiButton.setId("fi-button");
    fiButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            ChartOptions.get().setLang(fi);
        }
    });
    HorizontalLayout horizontalLayout = new HorizontalLayout(enButton, fiButton);
    horizontalLayout.setSpacing(false);
    VerticalLayout verticalLayout = new VerticalLayout(horizontalLayout, chart);
    verticalLayout.setSpacing(false);
    verticalLayout.setMargin(false);
    return verticalLayout;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) ClickEvent(com.vaadin.ui.Button.ClickEvent) Lang(com.vaadin.addon.charts.model.Lang) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) DataSeries(com.vaadin.addon.charts.model.DataSeries) DateTimeLabelFormats(com.vaadin.addon.charts.model.DateTimeLabelFormats) 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