Search in sources :

Example 16 with GradientColor

use of com.vaadin.addon.charts.model.style.GradientColor in project charts by vaadin.

the class PieWithGradientFill method createRadialGradient.

/**
 * Creates a radial gradient with the specified start and end colors.
 */
private GradientColor createRadialGradient(SolidColor start, SolidColor end) {
    GradientColor color = GradientColor.createRadial(0.5, 0.3, 0.7);
    color.addColorStop(0, start);
    color.addColorStop(1, end);
    return color;
}
Also used : GradientColor(com.vaadin.addon.charts.model.style.GradientColor)

Example 17 with GradientColor

use of com.vaadin.addon.charts.model.style.GradientColor in project charts by vaadin.

the class ChartDesignWriter method writeGradientColor.

private static void writeGradientColor(GradientColor color, Element parent, Field field) {
    Element colorProperty = parent.appendElement(toNodeName(field.getName()));
    if (color.getLinearGradient() != null) {
        Element element = colorProperty.appendElement("linear-gradient");
        element.attr("x1", formatNumber(color.getLinearGradient().getX1()));
        element.attr("y1", formatNumber(color.getLinearGradient().getY1()));
        element.attr("x2", formatNumber(color.getLinearGradient().getX2()));
        element.attr("y2", formatNumber(color.getLinearGradient().getY2()));
    } else if (color.getRadialGradient() != null) {
        Element element = colorProperty.appendElement("radial-gradient");
        element.attr("cx", formatNumber(color.getRadialGradient().getCx()));
        element.attr("cy", formatNumber(color.getRadialGradient().getCy()));
        element.attr("r", formatNumber(color.getRadialGradient().getR()));
    }
    for (GradientColor.Stop stop : color.getStops()) {
        Element stops = colorProperty.appendElement("stops");
        stops.attr("position", formatNumber(stop.getPosition()));
        stops.attr("color", stop.getColor().toString());
    }
}
Also used : GradientColor(com.vaadin.addon.charts.model.style.GradientColor) Element(org.jsoup.nodes.Element)

Example 18 with GradientColor

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

Example 19 with GradientColor

use of com.vaadin.addon.charts.model.style.GradientColor 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 20 with GradientColor

use of com.vaadin.addon.charts.model.style.GradientColor in project charts by vaadin.

the class Basic3DColumnWithGradientBackground method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Monthly Average Rainfall");
    conf.setSubTitle("Source: WorldClimate.com");
    XAxis x = new XAxis();
    x.setCategories(new String[] { "Jan", "Feb", "Mar", "Apr" });
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    y.setTitle("Rainfall (mm)");
    conf.addyAxis(y);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.x +': '+ this.y +' mm'");
    conf.setTooltip(tooltip);
    PlotOptionsColumn plot = new PlotOptionsColumn();
    plot.setPointPadding(0.2);
    plot.setBorderWidth(0);
    plot.setGroupZPadding(10);
    conf.setPlotOptions(plot);
    Options3d options3d = new Options3d();
    options3d.setEnabled(true);
    options3d.setAlpha(5);
    options3d.setBeta(30);
    options3d.setDepth(100);
    options3d.setViewDistance(200);
    Frame frame = new Frame();
    options3d.setFrame(frame);
    frame.setBack(new Back());
    GradientColor c = GradientColor.createLinear(0, 0, 1, 0);
    c.addColorStop(0, SolidColor.RED);
    c.addColorStop(1, SolidColor.AQUAMARINE);
    frame.getBack().setColor(c);
    frame.getBack().setSize(1);
    conf.getChart().setOptions3d(options3d);
    conf.addSeries(new ListSeries("Tokyo", 49.9, 71.5, 106.4, 129.2));
    chart.drawChart(conf);
    return chart;
}
Also used : Frame(com.vaadin.addon.charts.model.Frame) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) Back(com.vaadin.addon.charts.model.Back) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) Options3d(com.vaadin.addon.charts.model.Options3d) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

GradientColor (com.vaadin.addon.charts.model.style.GradientColor)29 Configuration (com.vaadin.addon.charts.model.Configuration)18 Chart (com.vaadin.addon.charts.Chart)15 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)15 YAxis (com.vaadin.addon.charts.model.YAxis)13 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)9 Test (org.junit.Test)9 ListSeries (com.vaadin.addon.charts.model.ListSeries)8 Marker (com.vaadin.addon.charts.model.Marker)8 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)7 Element (org.jsoup.nodes.Element)7 Hover (com.vaadin.addon.charts.model.Hover)6 DataLabels (com.vaadin.addon.charts.model.DataLabels)5 DataSeries (com.vaadin.addon.charts.model.DataSeries)5 Labels (com.vaadin.addon.charts.model.Labels)5 PlotOptionsGauge (com.vaadin.addon.charts.model.PlotOptionsGauge)5 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)4 States (com.vaadin.addon.charts.model.States)4 Background (com.vaadin.addon.charts.model.Background)3 Dial (com.vaadin.addon.charts.model.Dial)3