Exemplo n.º 1
0
  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);
  }
Exemplo n.º 2
0
 public void redoChart(PieChart pieChart) {
   pieChart.getModel().setTitle(new Text(valueLabel + " by " + groupLabel, chartTitleStyle));
   PieDataProvider provider = (PieDataProvider) pieChart.getDataProvider();
   provider.setLabelProperty(groupCol);
   provider.setValueProperty(valueCol);
   provider.setTextProperty(labelCol);
   provider.bind(store);
   provider.populateData(pieChart);
 }