Exemplo n.º 1
0
  @Test
  @Ignore("Phantomjs not installed on our build server")
  public void testWide() throws InterruptedException, URISyntaxException {

    Configuration conf = new Configuration();
    conf.getChart().setType(ChartType.COLUMN);
    conf.getChart().setMarginRight(200);
    Legend legend = conf.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setHorizontalAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.MIDDLE);
    legend.setBorderWidth(0);

    Random r = new Random();

    for (int i = 0; i < 20; i++) {
      String name = RandomStringUtils.randomAlphabetic(r.nextInt(20));
      DataSeries dataSeries = new DataSeries(name);
      dataSeries.add(new DataSeriesItem(name, r.nextInt(100)));
      conf.addSeries(dataSeries);
    }

    SVGGenerator instance = SVGGenerator.getInstance();
    String generatedSVG = instance.generate(conf, 1200, 400);

    Assert.assertTrue(generatedSVG.contains("width=\"1200\""));
    Assert.assertTrue(generatedSVG.contains("height=\"400\""));

    SVGGenerator.getInstance().destroy();
  }
Exemplo n.º 2
0
  private Chart createChart(int points) {
    Chart chart = new Chart(ChartType.SCATTER);
    Configuration conf = chart.getConfiguration();

    conf.getChart().setZoomType(ZoomType.XY);
    conf.disableCredits();
    conf.setTitle("Height vs Weight");
    conf.setSubTitle("Polygon series in Vaadin Charts.");

    Tooltip tooltip = conf.getTooltip();
    tooltip.setHeaderFormat("{series.name}");
    tooltip.setPointFormat("{point.x} cm, {point.y} kg");

    XAxis xAxis = conf.getxAxis();
    xAxis.setStartOnTick(true);
    xAxis.setEndOnTick(true);
    xAxis.setShowLastLabel(true);
    xAxis.setTitle("Height (cm)");

    YAxis yAxis = conf.getyAxis();
    yAxis.setTitle("Weight (kg)");

    AbstractLinePlotOptions plotOptions = new PlotOptionsScatter();
    plotOptions.setThreshold(0);
    DataSeries scatter = new DataSeries();
    scatter.setPlotOptions(plotOptions);
    scatter.setName("Observations");
    fillScatter(scatter, points);
    conf.addSeries(scatter);
    return chart;
  }
Exemplo n.º 3
0
  private Configuration createConf() {
    Configuration conf = new Configuration();

    conf.setTitle("Historic World Population by Region");
    conf.setSubTitle("Source: Wikipedia.org");

    XAxis x = new XAxis();
    x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
    x.setTitle((String) null);
    conf.addxAxis(x);

    YAxis y = new YAxis();
    y.setMin(0);
    Title title = new Title("Population (millions)");
    title.setVerticalAlign(VerticalAlign.HIGH);
    y.setTitle(title);
    conf.addyAxis(y);

    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.series.name +': '+ this.y +' millions'");
    conf.setTooltip(tooltip);

    PlotOptionsBar plot = new PlotOptionsBar();
    plot.setDataLabels(new Labels(true));
    conf.setPlotOptions(plot);

    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setHorizontalAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-100);
    legend.setY(100);
    legend.setFloating(true);
    legend.setBorderWidth(1);
    legend.setBackgroundColor("#FFFFFF");
    legend.setShadow(true);
    conf.setLegend(legend);

    conf.disableCredits();

    List<Series> series = new ArrayList<Series>();
    series.add(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
    series.add(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
    series.add(new ListSeries("Year 2008", 973, 914, 4054, 732, 34));
    conf.setSeries(series);
    return conf;
  }
Exemplo n.º 4
0
  @Override
  protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");

    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("Logarithmic axis demo");

    configuration.getxAxis().setTickInterval(1);

    YAxis yAxis = configuration.getyAxis();
    yAxis.setType(AxisType.LOGARITHMIC);
    yAxis.setMinorTickInterval("0.1");

    configuration.getTooltip().setHeaderFormat("<b>{series.name}</b><br />");
    configuration.getTooltip().setPointFormat("x = {point.x}, y = {point.y}");
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setPointStart(1);
    configuration.setPlotOptions(plotOptions);

    ListSeries ls = new ListSeries(1, 2, 4, 8, 16, 32, 64, 128, 256, 512);
    configuration.setSeries(ls);

    chart.drawChart(configuration);
    return chart;
  }
Exemplo n.º 5
0
  @Before
  public void setUp() throws Exception {
    chart = mock(Chart.class);
    conf = new Configuration();
    yAxis = new YAxis();
    conf.addyAxis(yAxis);
    when(chart.getConfiguration()).thenReturn(conf);

    initTimingMetricsMap();
  }
  @Override
  protected Component getChart() {
    Chart mychart = new Chart();

    Configuration configuration = mychart.getConfiguration();
    configuration.getChart().setType(ChartType.COLUMN);
    configuration.getxAxis().setType(AxisType.CATEGORY);

    // series have points for different categories, no series is complete
    // (#13050)
    configuration.setSeries(
        new DataSeries(new DataSeriesItem("X", 6)),
        new DataSeries(new DataSeriesItem("X", 5)),
        new DataSeries(new DataSeriesItem("Y", 4)),
        new DataSeries(new DataSeriesItem("X", 3)),
        new DataSeries(new DataSeriesItem("X", 2)),
        new DataSeries(new DataSeriesItem("X", 1)));

    return mychart;
  }
Exemplo n.º 7
0
 @Test
 public void testSetCounts() throws Exception {
   IndicatorsModel model = new IndicatorsModel();
   model.setTimingMetricsMap(timingMetricsMap);
   ChartManager.setCounts(chart, model);
   List<Series> series = conf.getSeries();
   assertEquals(2, series.size());
   assertEquals(TimingsType.QUERIES.getName(), series.get(0).getName());
   assertEquals(TimingsType.ERRORS.getName(), series.get(1).getName());
   assertEquals(metricItem.getCount(), ((DataSeries) series.get(0)).get(1).getY());
   assertEquals(metricItem.getErrorCount(), ((DataSeries) series.get(1)).get(1).getY());
 }
  @Override
  protected Component getChart() {
    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.setStartAngle(45);
    plotOptions.setEndAngle(180);
    plotOptions.setCursor(Cursor.POINTER);
    Labels dataLabels = new Labels(true);
    dataLabels.setFormatter("'<b>'+ this.point.name +'</b>: '+ this.percentage +' %'");
    plotOptions.setDataLabels(dataLabels);
    conf.setPlotOptions(plotOptions);

    conf.setSeries(getBrowserMarketShareSeries());

    chart.drawChart();
    return chart;
  }
  protected Component getChart() {
    final Chart chart = new Chart();
    chart.setWidth("500px");

    final Configuration configuration = new Configuration();
    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("Temperature");

    configuration.getPane().setStartAngle(-150);
    configuration.getPane().setEndAngle(150);

    YAxis yAxis = new YAxis();
    yAxis.setMin(-30);
    yAxis.setMax(50);
    yAxis.setLineColor(new SolidColor("#339"));
    yAxis.setTickColor(new SolidColor("#339"));
    yAxis.setMinorTickColor(new SolidColor("#339"));
    yAxis.setOffset(-25);
    yAxis.setLineWidth(2);
    yAxis.setLabels(new Labels());
    yAxis.getLabels().setDistance(-20);
    yAxis.getLabels().setRotationPerpendicular();
    yAxis.setTickLength(5);
    yAxis.setMinorTickLength(5);
    yAxis.setEndOnTick(false);

    configuration.addyAxis(yAxis);

    final ListSeries series = new ListSeries("Temperature", 12);

    PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
    plotOptionsGauge.setDataLabels(new Labels());
    plotOptionsGauge.getDataLabels().setFormatter("function() {return '' + this.y +  ' °C';}");
    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.getTooltip().setValueSuffix(" °C");
    series.setPlotOptions(plotOptionsGauge);
    configuration.setSeries(series);
    chart.drawChart(configuration);

    return chart;
  }
Exemplo n.º 10
0
  @Override
  protected Component getChart() {
    Chart chart = new Chart(ChartType.AREA);

    Configuration conf = chart.getConfiguration();

    conf.getChart().setInverted(true);

    conf.setTitle(new Title("Average fruit consumption during one week"));

    XAxis xAxis = new XAxis();
    xAxis.setCategories(
        "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
    conf.addxAxis(xAxis);

    YAxis yAxis = new YAxis();
    yAxis.setTitle(new Title("Number of units"));
    yAxis.setMin(0);
    conf.addyAxis(yAxis);

    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setHorizontalAlign(HorizontalAlign.LEFT);
    legend.setFloating(true);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-150);
    legend.setY(100);
    legend.setBorderWidth(1);
    legend.setBackgroundColor("#ffffff");
    conf.setLegend(legend);

    PlotOptionsArea plotOptions = new PlotOptionsArea();
    plotOptions.setFillOpacity(0.5);
    conf.setPlotOptions(plotOptions);

    conf.addSeries(new ListSeries("John", 3, 4, 3, 5, 4, 10, 12));
    conf.addSeries(new ListSeries("Jane", 1, 3, 4, 3, 3, 5, 4));

    chart.drawChart(conf);

    return chart;
  }
Exemplo n.º 11
0
 @Test
 public void testSetMetrics() throws Exception {
   IndicatorsModel model = new IndicatorsModel();
   model.setTimingMetricsMap(timingMetricsMap);
   ChartManager.setMetrics(chart, model);
   List<Series> series = conf.getSeries();
   assertEquals(2, series.size());
   DataSeries dataSeries1 = (DataSeries) series.get(0);
   DataSeries dataSeries2 = (DataSeries) series.get(1);
   assertEquals(METRIC1.getDescription(), dataSeries1.getName());
   assertEquals(METRIC2.getDescription(), dataSeries2.getName());
   DataSeriesItem item1 = dataSeries1.get(1);
   assertEquals(metricItem.getT95(), item1.getY());
   assertEquals(DATE_TIME2, new LocalDateTime(item1.getX(), DateTimeZone.UTC));
 }
Exemplo n.º 12
0
 @Test
 public void testSetTimings() throws Exception {
   IndicatorsModel model = new IndicatorsModel();
   model.setTimingMetricsMap(timingMetricsMap);
   ChartManager.setTimings(chart, model);
   List<Series> series = conf.getSeries();
   assertEquals(6, series.size());
   assertEquals(TimingsType.MIN.getName(), series.get(0).getName());
   assertEquals(TimingsType.MAX.getName(), series.get(1).getName());
   assertEquals(TimingsType.AVG.getName(), series.get(2).getName());
   assertEquals(TimingsType.P90.getName(), series.get(3).getName());
   assertEquals(TimingsType.P95.getName(), series.get(4).getName());
   assertEquals(TimingsType.P99.getName(), series.get(5).getName());
   assertEquals(metricItem.getMin(), ((DataSeries) series.get(0)).get(1).getY());
   assertEquals(metricItem.getMax(), ((DataSeries) series.get(1)).get(1).getY());
   assertEquals(metricItem.getAvg(), ((DataSeries) series.get(2)).get(1).getY());
   assertEquals(metricItem.getT90(), ((DataSeries) series.get(3)).get(1).getY());
   assertEquals(metricItem.getT95(), ((DataSeries) series.get(4)).get(1).getY());
   assertEquals(metricItem.getT99(), ((DataSeries) series.get(5)).get(1).getY());
 }
Exemplo n.º 13
0
  @Override
  protected Component getChart() {
    Chart chart = new Chart(ChartType.LINE);

    Configuration conf = chart.getConfiguration();
    conf.getChart().setPolar(true);
    conf.setTitle("Budget vs spending");
    // conf.getTitle().setX(-80);

    Pane pane = new Pane();
    pane.setSize("80%");
    conf.addPane(pane);
    // FIXME missing generated API
    // pane.setBackground(new Background[] {});

    XAxis axis = new XAxis();
    axis.setCategories(
        new String[] {
          "Sales",
          "Marketing",
          "Development",
          "Customer Support",
          "Information Technology",
          "Administration"
        });
    // FIXME remove toString() once enums are used in model (CHARTS-159)
    axis.setTickmarkPlacement(TickmarkPlacement.ON.toString());
    axis.setLineWidth(0);

    YAxis yaxs = new YAxis();
    yaxs.setGridLineInterpolation("polygon");
    yaxs.setMin(0);
    yaxs.setLineWidth(0);
    conf.addxAxis(axis);
    conf.addyAxis(yaxs);

    // conf.getTooltip().setShared(true);
    conf.getTooltip().setValuePrefix("$");

    conf.getLegend().setAlign(HorizontalAlign.RIGHT.toString());
    conf.getLegend().setVerticalAlign(VerticalAlign.TOP.toString());
    conf.getLegend().setY(100);
    conf.getLegend().setLayout(LayoutDirection.VERTICAL.toString());

    ListSeries line1 = new ListSeries(43000, 19000, 60000, 35000, 17000, 10000);
    ListSeries line2 = new ListSeries(50000, 39000, 42000, 31000, 26000, 14000);
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setPointPlacement(PointPlacement.ON);
    line1.setPlotOptions(plotOptions);
    line1.setName("Allocated Budget");

    plotOptions = new PlotOptionsLine();
    plotOptions.setPointPlacement(PointPlacement.ON);
    line2.setPlotOptions(plotOptions);
    line2.setName("Actual Spending");

    conf.setSeries(line1, line2);

    chart.drawChart(conf);

    return chart;
  }
  @Override
  protected Component getChart() {
    final Chart chart = new Chart(ChartType.COLUMN);
    chart.setId("chart");

    final Configuration conf = chart.getConfiguration();

    conf.setTitle("Browser market share, April, 2011");
    conf.setSubTitle("Click the columns to view versions. Click again to view brands.");
    conf.getLegend().setEnabled(false);

    XAxis x = new XAxis();
    x.setType(AxisType.CATEGORY);
    conf.addxAxis(x);

    YAxis y = new YAxis();
    y.setTitle("Total percent market share");
    conf.addyAxis(y);

    PlotOptionsColumn column = new PlotOptionsColumn();
    column.setCursor(Cursor.POINTER);
    column.setDataLabels(new Labels(true));
    column.getDataLabels().setFormatter("this.y +'%'");

    conf.setPlotOptions(column);

    Tooltip tooltip = new Tooltip();
    tooltip.setHeaderFormat("<span style=\"font-size:11px\">{series.name}</span><br>");
    tooltip.setPointFormat(
        "<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>");
    conf.setTooltip(tooltip);

    DataSeries series = new DataSeries();
    series.setName("Browser brands");
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setColorByPoint(true);
    series.setPlotOptions(plotOptionsColumn);

    DataSeriesItem item = new DataSeriesItem("MSIE", 55.11);
    DataSeries drillSeries = new DataSeries("MSIE versions");
    drillSeries.setId("MSIE");
    String[] categories = new String[] {"MSIE 6.0", "MSIE 7.0", "MSIE 8.0", "MSIE 9.0"};
    Number[] ys = new Number[] {10.85, 7.35, 33.06, 2.81};
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);

    item = new DataSeriesItem("Firefox", 21.63);
    drillSeries = new DataSeries("Firefox versions");
    drillSeries.setId("Firefox");
    categories =
        new String[] {"Firefox 2.0", "Firefox 3.0", "Firefox 3.5", "Firefox 3.6", "Firefox 4.0"};
    ys = new Number[] {0.20, 0.83, 1.58, 13.12, 5.43};
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);

    item = new DataSeriesItem("Chrome", 11.94);
    drillSeries = new DataSeries("Chrome versions");
    drillSeries.setId("Chrome");
    categories =
        new String[] {
          "Chrome 5.0",
          "Chrome 6.0",
          "Chrome 7.0",
          "Chrome 8.0",
          "Chrome 9.0",
          "Chrome 10.0",
          "Chrome 11.0",
          "Chrome 12.0"
        };
    ys = new Number[] {0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22};
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);

    item = new DataSeriesItem("Safari", 7.15);
    drillSeries = new DataSeries("Safari versions");
    drillSeries.setId("Safari");
    categories =
        new String[] {
          "Safari 5.0",
          "Safari 4.0",
          "Safari Win 5.0",
          "Safari 4.1",
          "Safari/Maxthon",
          "Safari 3.1",
          "Safari 4.1"
        };
    ys = new Number[] {4.55, 1.42, 0.23, 0.21, 0.20, 0.19, 0.14};
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);

    item = new DataSeriesItem("Opera", 2.14);
    drillSeries = new DataSeries("Opera versions");
    drillSeries.setId("Opera");
    categories = new String[] {"Opera 9.x", "Opera 10.x", "Opera 11.x"};
    ys = new Number[] {0.12, 0.37, 1.65};
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    conf.addSeries(series);

    return chart;
  }
  @Override
  protected Component getChart() {
    VerticalLayout layout = new VerticalLayout();
    final Chart chart = new Chart(ChartType.COLUMN);
    chart.setId("chart");

    conf = chart.getConfiguration();

    conf.setTitle("Global happiness index");
    conf.setSubTitle("Source: www.happyplanetindex.org");
    conf.getLegend().setEnabled(false);

    XAxis x = new XAxis();
    // FIXME remove toString() once enums are used in model (CHARTS-159)
    x.setType(AxisType.CATEGORY.toString());
    conf.addxAxis(x);

    YAxis y = new YAxis();
    y.setTitle(new Title("Total"));
    conf.addyAxis(y);

    PlotOptionsColumn column = new PlotOptionsColumn();
    column.setCursor(Cursor.POINTER.toString());
    column.setDataLabels(new DataLabels(true));

    conf.setPlotOptions(column);

    DataSeries series = new DataSeries();
    series.setName("Regions");
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setColorByPoint(true);
    series.setPlotOptions(plotOptionsColumn);

    DataSeriesItem item = new DataSeriesItem("Latin America and Carribean", 60);
    item.setId("Latin America and Carribean");
    series.addItemWithDrilldown(item);

    item = new DataSeriesItem("Western Nations", 50);
    item.setId("Western Nations");
    series.addItemWithDrilldown(item);

    conf.addSeries(series);

    drillSeries = new HashMap<String, DataSeries>();

    DataSeries drill = new DataSeries("Latin America and Carribean Countries");

    item = new DataSeriesItem("Costa Rica", 64);
    item.setId("Costa Rica");
    drill.addItemWithDrilldown(item);

    item = new DataSeriesItem("Colombia", 59.8);
    item.setId("Colombia");
    drill.addItemWithDrilldown(item);

    item = new DataSeriesItem("Belize", 59.3);
    item.setId("Belize");
    drill.addItemWithDrilldown(item);

    drillSeries.put("Latin America and Carribean", drill);

    drill = new DataSeries("Western Nations Countries");

    item = new DataSeriesItem("New Zealand", 51.6);
    item.setId("New Zealand");
    drill.addItemWithDrilldown(item);

    item = new DataSeriesItem("Norway", 51.4);
    item.setId("Norway");
    drill.addItemWithDrilldown(item);

    item = new DataSeriesItem("Switzerland", 50.3);
    item.setId("Switzerland");
    drill.addItemWithDrilldown(item);

    drillSeries.put("Western Nations", drill);

    drill = new DataSeries("Details Costa Rica");
    drill.setId("Details Costa Rica");
    String[] categories =
        new String[] {"Life Expectancy", "Well-being (0-10)", "Footprint (gha/capita)"};
    Number[] ys = new Number[] {79.3, 7.3, 2.5};
    drill.setData(categories, ys);
    drillSeries.put("Costa Rica", drill);

    drill = new DataSeries("Details Colombia");
    drill.setId("Details Colombia");
    ys = new Number[] {73.7, 6.4, 1.8};
    drill.setData(categories, ys);
    drillSeries.put("Colombia", drill);

    drill = new DataSeries("Details Belize");
    drill.setId("Details Belize");
    ys = new Number[] {76.1, 6.5, 2.1};
    drill.setData(categories, ys);
    drillSeries.put("Belize", drill);

    drill = new DataSeries("Details New Zealand");
    drill.setId("Details New Zealand");
    ys = new Number[] {80.7, 7.2, 4.3};

    drill.setData(categories, ys);
    drillSeries.put("New Zealand", drill);

    drill = new DataSeries("Details Norway");
    drill.setId("Details Norway");
    ys = new Number[] {81.1, 7.6, 4.8};
    drill.setData(categories, ys);
    drillSeries.put("Norway", drill);

    drill = new DataSeries("Details Switzerland");
    drill.setId("Details Switzerland");
    ys = new Number[] {82.3, 7.5, 5.0};
    drill.setData(categories, ys);
    drillSeries.put("Switzerland", drill);

    chart.setDrilldownCallback(
        new DrilldownCallback() {

          @Override
          public Series handleDrilldown(DrilldownEvent event) {
            log("DrilldownEvent: " + event.getItem().getId());
            return getPointDrilldown(event.getItem());
          }
        });

    chart.addPointClickListener(
        new PointClickListener() {

          @Override
          public void onClick(PointClickEvent event) {
            log(
                "PointClickEvent: "
                    + event.getSeries().getName()
                    + " index :"
                    + event.getPointIndex());
          }
        });

    chart.addChartDrillupListener(
        new ChartDrillupListener() {

          @Override
          public void onDrillup(ChartDrillupEvent event) {
            log("ChartDrillupEvent");
          }
        });

    layout.addComponent(chart);
    layout.addComponent(log);
    return layout;
  }
Exemplo n.º 16
0
  @Override
  protected Component getChart() {
    final Chart chart = new Chart();
    chart.setWidth(500, Unit.PIXELS);

    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SOLIDGAUGE);

    configuration.getTitle().setText("Speed");

    Pane pane = new Pane();

    pane.setCenter("50%", "85%");
    pane.setSize("140%");
    pane.setStartAngle(-90);
    pane.setEndAngle(90);
    configuration.addPane(pane);

    configuration.getTooltip().setEnabled(false);

    Background bkg = new Background();
    bkg.setBackgroundColor(new SolidColor("#eeeeee"));
    bkg.setInnerRadius("60%");
    bkg.setOuterRadius("100%");
    bkg.setShape("arc");
    bkg.setBorderWidth(0);
    pane.setBackground(new Background[] {bkg});

    YAxis yaxis = configuration.getyAxis();
    yaxis.setLineWidth(0);
    yaxis.setTickInterval(200);
    yaxis.setTickWidth(0);
    yaxis.setMin(0);
    yaxis.setMax(200);
    yaxis.setTitle(new AxisTitle(""));
    yaxis.getTitle().setY(-70);
    yaxis.setLabels(new Labels());
    yaxis.getLabels().setY(16);
    Stop stop1 = new Stop(0.1f, SolidColor.GREEN);
    Stop stop2 = new Stop(0.5f, SolidColor.YELLOW);
    Stop stop3 = new Stop(0.9f, SolidColor.RED);
    yaxis.setStops(new Stop[] {stop1, stop2, stop3});

    PlotOptionsSolidGauge plotOptions = new PlotOptionsSolidGauge();
    plotOptions.setTooltip(new SeriesTooltip());
    plotOptions.getTooltip().setValueSuffix(" km/h");
    DataLabels labels = new DataLabels();
    labels.setY(5);
    labels.setBorderWidth(0);
    labels.setUseHTML(true);
    labels.setFormat(
        "<div style=\"text-align:center\"><span style=\"font-size:25px;\">{y}</span><br/>"
            + "                       <span style=\"font-size:12pxg\">km/h</span></div>");
    plotOptions.setDataLabels(labels);
    configuration.setPlotOptions(plotOptions);

    final ListSeries series = new ListSeries("Speed", 80);
    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);
            if (newValue > 200) {
              newValue = 200;
            } else if (newValue < 0) {
              newValue = 0;
            }
            series.updatePoint(0, newValue);
          }
        },
        3000,
        12000);

    chart.drawChart(configuration);
    return chart;
  }
Exemplo n.º 17
0
  @Override
  protected Component getChart() {

    Chart chart = new Chart();

    Configuration config = chart.getConfiguration();
    config.getChart().setType(ChartType.HEATMAP);
    config.getChart().setMarginTop(40);
    config.getChart().setMarginBottom(40);

    config.getTitle().setText("Sales per employee per weekday");

    config
        .getxAxis()
        .setCategories(
            "Marta",
            "Mysia",
            "Misiek",
            "Maniek",
            "Miki",
            "Guillermo",
            "Jonatan",
            "Zdzisław",
            "Antoni",
            "Zygmunt");
    config.getyAxis().setCategories("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");

    config.getColorAxis().setMin(0);
    config.getColorAxis().setMinColor(SolidColor.WHITE);
    config.getColorAxis().setMaxColor(getThemeColors()[0]);

    config.getLegend().setLayout(LayoutDirection.VERTICAL);
    config.getLegend().setAlign(HorizontalAlign.RIGHT);
    config.getLegend().setMargin(0);
    config.getLegend().setVerticalAlign(VerticalAlign.TOP);
    config.getLegend().setY(25);
    config.getLegend().setSymbolHeight(320);

    HeatSeries rs = new HeatSeries("Sales per employee", getRawData());

    PlotOptionsHeatmap plotOptionsHeatmap = new PlotOptionsHeatmap();
    plotOptionsHeatmap.setDataLabels(new DataLabels());
    plotOptionsHeatmap.getDataLabels().setEnabled(true);

    SeriesTooltip tooltip = new SeriesTooltip();
    tooltip.setHeaderFormat("{series.name}<br/>");
    tooltip.setPointFormat("Amount: <b>{point.value}</b> ");
    plotOptionsHeatmap.setTooltip(tooltip);
    config.setPlotOptions(plotOptionsHeatmap);

    config.setSeries(rs);

    chart.drawChart(config);

    return chart;
  }