Search in sources :

Example 21 with Labels

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

the class ChartConfiguration method labelsSnippet4.

public void labelsSnippet4(XAxis xaxis) {
    Labels xlabels = xaxis.getLabels();
    Style xlabelsstyle = new Style();
    xlabelsstyle.setColor(SolidColor.GREEN);
    xlabels.setStyle(xlabelsstyle);
}
Also used : Style(com.vaadin.addon.charts.model.style.Style) Labels(com.vaadin.addon.charts.model.Labels)

Example 22 with Labels

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

the class LabelsJSONSerializationTest method toJSON_autoRotationLimitIsSet_labelsSerializedWithAutoRotationLimit.

@Test
public void toJSON_autoRotationLimitIsSet_labelsSerializedWithAutoRotationLimit() throws IOException {
    Labels labels = new Labels(true);
    labels.setAutoRotationLimit(40);
    ObjectMapper om = ChartSerialization.createObjectMapper();
    String json = toJSON(labels);
    Labels fromJson = om.readValue(json, Labels.class);
    assertEquals(40, fromJson.getAutoRotationLimit());
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 23 with Labels

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

the class Sparkline method configureYAxis.

protected void configureYAxis(YAxis axis) {
    axis.setLineWidth(0);
    axis.setMinorGridLineWidth(0);
    axis.setMinorTickLength(0);
    axis.setMinorTickWidth(0);
    axis.setGridLineWidth(0);
    axis.setMaxPadding(0.1);
    axis.setMinPadding(0.1);
    axis.setLabels(new Labels(false));
    axis.setLineColor(new SolidColor(0, 0, 0, 0));
    axis.setTitle("");
    axis.setStartOnTick(false);
    axis.setEndOnTick(false);
}
Also used : SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels)

Example 24 with Labels

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

the class SplineInverted method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setWidth("500px");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getChart().setInverted(true);
    configuration.getTitle().setText("Atmosphere Temperature by Altitude");
    configuration.getSubTitle().setText("According to the Standard Atmosphere Model");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setReversed(false);
    xAxis.setTitle(new AxisTitle("Altitude"));
    Labels labels = new Labels();
    labels.setFormatter("this.value + 'km'");
    labels.setEnabled(true);
    xAxis.setLabels(labels);
    xAxis.setMaxPadding(0.05);
    xAxis.setShowLastLabel(true);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setLineWidth(2);
    yAxis.setTitle(new AxisTitle("Temperature"));
    yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
    Labels labelsy = new Labels();
    labelsy.setEnabled(true);
    labelsy.setFormatter("this.value + '°'");
    yAxis.setLabels(labelsy);
    configuration.getTooltip().setFormatter("this.x +' km: '+this.y +'°C'");
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    plotOptions.setMarker(new Marker(true));
    configuration.setPlotOptions(plotOptions);
    Legend legend = configuration.getLegend();
    legend.setEnabled(false);
    DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsSpline());
    series.setName("Temperature");
    series.addData(new Number[][] { { 0, 15 }, { 10, -50 }, { 20, -56.5 }, { 30, -46.5 }, { 40, -22.1 }, { 50, -2.5 }, { 60, -27.7 }, { 70, -55.7 }, { 80, -76.5 } });
    configuration.setSeries(series);
    chart.drawChart(configuration);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) Labels(com.vaadin.addon.charts.model.Labels) DataSeries(com.vaadin.addon.charts.model.DataSeries) Marker(com.vaadin.addon.charts.model.Marker) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 25 with Labels

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

the class GaugeWithDualAxes 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().setAlignTicks(false);
    configuration.getChart().setPlotBackgroundColor(null);
    configuration.getChart().setPlotBackgroundImage(null);
    configuration.getChart().setPlotBorderWidth(0);
    configuration.getChart().setPlotShadow(false);
    configuration.setTitle("Speedometer with dual axes");
    configuration.getPane().setStartAngle(-150);
    configuration.getPane().setEndAngle(150);
    YAxis yAxis = new YAxis();
    yAxis.setMin(0);
    yAxis.setMax(200);
    yAxis.setLineColor(new SolidColor("#339"));
    yAxis.setTickColor(new SolidColor("#339"));
    yAxis.setMinorTickColor(new SolidColor("#339"));
    yAxis.setOffset(-25);
    yAxis.setLineWidth(2);
    Labels labels = new Labels();
    labels.setDistance(-20);
    labels.setRotationPerpendicular();
    labels.setRotation("auto");
    yAxis.setLabels(labels);
    yAxis.setTickLength(5);
    yAxis.setMinorTickLength(5);
    yAxis.setEndOnTick(false);
    YAxis yAxis2 = new YAxis();
    yAxis2.setMin(0);
    yAxis2.setMax(124);
    yAxis2.setLineColor(new SolidColor("#933"));
    yAxis2.setTickColor(new SolidColor("#933"));
    yAxis2.setMinorTickColor(new SolidColor("#933"));
    yAxis2.setOffset(-20);
    yAxis2.setLineWidth(2);
    labels = new Labels();
    labels.setDistance(12);
    labels.setRotationPerpendicular();
    yAxis2.setLabels(labels);
    yAxis2.setTickLength(5);
    yAxis2.setMinorTickLength(5);
    yAxis2.setEndOnTick(false);
    yAxis2.setTickPosition(TickPosition.OUTSIDE);
    yAxis2.setMinorTickPosition(TickPosition.OUTSIDE);
    configuration.addyAxis(yAxis);
    configuration.addyAxis(yAxis2);
    final ListSeries series = new ListSeries("Speed", 80);
    PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
    plotOptionsGauge.setDataLabels(new DataLabels());
    plotOptionsGauge.getDataLabels().setFormatter("function() {return '<span style=\"color:#339\">'+ this.y + ' km/h</span><br/>' + '<span style=\"color:#933\">' + Math.round(this.y * 0.621) + ' mph</span>';}");
    GradientColor gradient = GradientColor.createLinear(0, 0, 0, 1);
    gradient.addColorStop(0, new SolidColor("#DDD"));
    gradient.addColorStop(1, new SolidColor("#FFF"));
    plotOptionsGauge.getDataLabels().setBackgroundColor(gradient);
    plotOptionsGauge.setTooltip(new SeriesTooltip());
    plotOptionsGauge.getTooltip().setValueSuffix(" km/h");
    series.setPlotOptions(plotOptionsGauge);
    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);
        }
    }, 5000, 12000);
    chart.drawChart(configuration);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataLabels(com.vaadin.addon.charts.model.DataLabels) 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) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis) SeriesTooltip(com.vaadin.addon.charts.model.SeriesTooltip)

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