Example #1
0
  private ChartModel getPieChartData() {

    ChartModel cm =
        new ChartModel(
            "Most contacted friends", "font-size: 14px; font-family: Verdana; text-align: center;");
    cm.setBackgroundColour("#fffff5");
    Legend lg = new Legend(Position.RIGHT, true);
    lg.setPadding(10);
    cm.setLegend(lg);

    PieChart pie = new PieChart();
    pie.setAlpha(0.5f);
    pie.setNoLabels(true);
    //		pie.setTooltip("#label# $#val#M<br>#percent#");
    pie.setColours("#ff0000", "#00aa00", "#0000ff", "#ff9900", "#ff00ff");
    pie.addSlices(new PieChart.Slice(100, "A", "Alice"));
    pie.addSlices(new PieChart.Slice(200, "H", "John"));
    pie.addSlices(new PieChart.Slice(150, "B", "Barack"));
    pie.addSlices(new PieChart.Slice(120, "H", "Hilary"));
    pie.addSlices(new PieChart.Slice(60, "F", "Franz"));
    pie.addChartListener(listener);

    cm.addChartConfig(pie);
    return cm;
  }
  public void setNewPieChartModel() {

    ChartModel model = new ChartModel(valueLabel + " by " + groupLabel, chartTitleStyle);
    model.setBackgroundColour("#fefaee");
    model.setLegend(new Legend(Position.TOP, true));
    model.setScaleProvider(ScaleProvider.ROUNDED_NEAREST_SCALE_PROVIDER);

    //	    BarChart bar = new BarChart(BarStyle.GLASS);
    //	    bar.setColour("#ff0000");
    //	    bar.setAnimateOnShow(true);
    //	    BarDataProvider barProvider = new BarDataProvider("dollarValue", "productCode");
    //	    barProvider.bind(gridStore);
    //	    bar.setDataProvider(barProvider);
    //	    model.addChartConfig(bar);

    PieChart pie = new PieChart();
    pie.setColours(chartColors);
    PieDataProvider pieProvider =
        new PieDataProvider(valueCol, groupCol) {
          @Override
          public void populateData(ChartConfig config) {
            PieChart chart = (PieChart) config;
            chart.getValues().clear();

            TreeMap<String, Number> valueMap = new TreeMap<String, Number>();
            TreeMap<String, String> textMap = new TreeMap<String, String>();

            for (ModelData m : store.getModels()) {
              Number n = (valueCol == null || valueCol.equals("count")) ? 1 : getValue(m);
              String label = getLabel(m);
              String text = getText(m);
              if (text == null || text.length() == 0) text = label;
              textMap.put(label, text);
              if (valueMap.containsKey(label))
                valueMap.put(
                    label, new Double(valueMap.get(label).doubleValue() + n.doubleValue()));
              else valueMap.put(label, n);
            }

            for (String label : valueMap.keySet()) {
              chart.addSlices(new Slice(valueMap.get(label), label, textMap.get(label)));
            }
          }
        };
    pieProvider.setTextProperty(labelCol);
    pieProvider.bind(store);
    pie.setDataProvider(pieProvider);
    model.addChartConfig(pie);

    chart.setChartModel(model);
  }
Example #3
0
    public ChartModel getChartModel(int segments) {
      ChartModel cd = new ChartModel("Sales per Month", "font-size: 14px; font-family: Verdana;");
      cd.setBackgroundColour("#fffff0");
      PieChart pie = new PieChart();
      pie.setAlpha(0.5f);
      pie.setTooltip("#label# $#val#<br>#percent#");
      pie.setAnimate(false);
      pie.setAlphaHighlight(true);
      pie.setGradientFill(true);
      pie.setColours("#ff0000", "#00aa00", "#0000ff", "#ff9900", "#ff00ff");

      for (int n = 0; n < segments; n++) {
        pie.addSlices(new PieChart.Slice(Random.nextInt(110) * 100, TestData.getMonths()[n]));
      }
      cd.addChartConfig(pie);
      return cd;
    }