コード例 #1
0
ファイル: MyScatterChart.java プロジェクト: Peppe/chart-tests
  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;
  }
コード例 #2
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;
  }
コード例 #3
0
ファイル: HeatMapExample.java プロジェクト: gazgrk/charts
  @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;
  }
コード例 #4
0
ファイル: SolidGauge.java プロジェクト: ace130-github/charts
  @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;
  }