Search in sources :

Example 6 with Labels

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

the class AngularGauge method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setWidth("500px");
    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("Speedometer");
    GradientColor gradient1 = GradientColor.createLinear(0, 0, 0, 1);
    gradient1.addColorStop(0, new SolidColor("#FFF"));
    gradient1.addColorStop(1, new SolidColor("#333"));
    GradientColor gradient2 = GradientColor.createLinear(0, 0, 0, 1);
    gradient2.addColorStop(0, new SolidColor("#333"));
    gradient2.addColorStop(1, new SolidColor("#FFF"));
    Background[] background = new Background[3];
    background[0] = new Background();
    background[0].setBackgroundColor(gradient1);
    background[0].setBorderWidth(0);
    background[0].setOuterRadius("109%");
    background[1] = new Background();
    background[1].setBackgroundColor(gradient2);
    background[1].setBorderWidth(1);
    background[1].setOuterRadius("107%");
    background[2] = new Background();
    background[2].setBackgroundColor(new SolidColor("#DDD"));
    background[2].setBorderWidth(0);
    background[2].setInnerRadius("103%");
    background[2].setOuterRadius("105%");
    configuration.getPane().setStartAngle(-150);
    configuration.getPane().setEndAngle(150);
    configuration.getPane().setBackground(background);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("km/h"));
    yAxis.setMin(0);
    yAxis.setMax(200);
    yAxis.setMinorTickInterval("auto");
    yAxis.setMinorTickWidth(1);
    yAxis.setMinorTickLength(10);
    yAxis.setMinorTickPosition(TickPosition.INSIDE);
    yAxis.setMinorTickColor(new SolidColor("#666"));
    yAxis.setGridLineWidth(0);
    yAxis.setTickPixelInterval(30);
    yAxis.setTickWidth(2);
    yAxis.setTickPosition(TickPosition.INSIDE);
    yAxis.setTickLength(10);
    yAxis.setTickColor(new SolidColor("#666"));
    Labels labels = new Labels();
    labels.setStep(2);
    labels.setRotationPerpendicular();
    yAxis.setLabels(labels);
    PlotBand[] plotBands = new PlotBand[3];
    plotBands[0] = new PlotBand(0, 120, new SolidColor("#55BF3B"));
    plotBands[1] = new PlotBand(120, 160, new SolidColor("#DDDF0D"));
    plotBands[2] = new PlotBand(160, 200, new SolidColor("#DF5353"));
    yAxis.setPlotBands(plotBands);
    final ListSeries series = new ListSeries("Speed", 80);
    PlotOptionsGauge plotOptions = new PlotOptionsGauge();
    plotOptions.setTooltip(new SeriesTooltip());
    plotOptions.getTooltip().setValueSuffix(" km/h");
    series.setPlotOptions(plotOptions);
    configuration.setSeries(series);
    runWhileAttached(chart, new Runnable() {

        Random r = new Random(0);

        @Override
        public void run() {
            Integer oldValue = series.getData()[0].intValue();
            Integer newValue = (int) (oldValue + (r.nextDouble() - 0.5) * 20.0);
            series.updatePoint(0, newValue);
        }
    }, 3000, 12000);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Background(com.vaadin.addon.charts.model.Background) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels) PlotOptionsGauge(com.vaadin.addon.charts.model.PlotOptionsGauge) Random(java.util.Random) ListSeries(com.vaadin.addon.charts.model.ListSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) PlotBand(com.vaadin.addon.charts.model.PlotBand) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis) SeriesTooltip(com.vaadin.addon.charts.model.SeriesTooltip)

Example 7 with Labels

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

the class ChartExportDemo method createChartConf.

private static Configuration createChartConf() {
    Configuration conf = new Configuration();
    conf.getChart().setType(ChartType.PIE);
    conf.setTitle("Browser market shares at a specific website, 2010");
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.setCursor(Cursor.POINTER);
    Labels dataLabels = new Labels();
    dataLabels.setEnabled(true);
    dataLabels.setColor(new SolidColor(0, 0, 0));
    dataLabels.setConnectorColor(new SolidColor(0, 0, 0));
    dataLabels.setFormatter("'<b>'+ this.point.name +'</b>: '+ this.percentage +' %'");
    plotOptions.setDataLabels(dataLabels);
    conf.setPlotOptions(plotOptions);
    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);
    return conf;
}
Also used : PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels) DataSeries(com.vaadin.addon.charts.model.DataSeries) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 8 with Labels

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

the class LabelsJSONSerializationTest method toJSON_enabledSet_labelsSerializedWithEnabled.

@Test
public void toJSON_enabledSet_labelsSerializedWithEnabled() {
    Labels labels = new Labels(false);
    String json = toJSON(labels);
    String expected = "{\"enabled\":false}";
    assertEquals(expected, json);
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) Test(org.junit.Test)

Example 9 with Labels

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

the class ChartConfiguration method labelsSnippet3.

public void labelsSnippet3(XAxis xaxis) {
    Labels xlabels = xaxis.getLabels();
    // Every 2 major tick
    xlabels.setStep(2);
}
Also used : Labels(com.vaadin.addon.charts.model.Labels)

Example 10 with Labels

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

the class ChartConfiguration method labelsSnippet1.

public void labelsSnippet1(Configuration conf) {
    XAxis xaxis = new XAxis();
    // ...
    Labels xlabels = xaxis.getLabels();
    // Default
    xlabels.setAlign(HorizontalAlign.CENTER);
    xlabels.getStyle().setColor(SolidColor.GREEN);
    xlabels.getStyle().setFontWeight(FontWeight.BOLD);
    xlabels.setRotation(-45);
    // Every 2 major tick
    xlabels.setStep(2);
}
Also used : Labels(com.vaadin.addon.charts.model.Labels) XAxis(com.vaadin.addon.charts.model.XAxis)

Aggregations

Labels (com.vaadin.addon.charts.model.Labels)29 Configuration (com.vaadin.addon.charts.model.Configuration)19 YAxis (com.vaadin.addon.charts.model.YAxis)19 Chart (com.vaadin.addon.charts.Chart)18 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)12 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)12 ListSeries (com.vaadin.addon.charts.model.ListSeries)11 DataLabels (com.vaadin.addon.charts.model.DataLabels)9 XAxis (com.vaadin.addon.charts.model.XAxis)9 DataSeries (com.vaadin.addon.charts.model.DataSeries)8 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)5 Tooltip (com.vaadin.addon.charts.model.Tooltip)5 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)5 Style (com.vaadin.addon.charts.model.style.Style)5 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)4 Marker (com.vaadin.addon.charts.model.Marker)4 Pane (com.vaadin.addon.charts.model.Pane)4 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)4 PlotOptionsGauge (com.vaadin.addon.charts.model.PlotOptionsGauge)4 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)4