Example usage for org.jfree.data KeyToGroupMap mapKeyToGroup

List of usage examples for org.jfree.data KeyToGroupMap mapKeyToGroup

Introduction

In this page you can find the example usage for org.jfree.data KeyToGroupMap mapKeyToGroup.

Prototype

public void mapKeyToGroup(Comparable key, Comparable group) 

Source Link

Document

Maps a key to a group.

Usage

From source file:org.oscarehr.web.reports.ocan.NeedRatingOverTimeReportGenerator.java

private JFreeChart generateNeedsOverTimeChart() {

    CategoryDataset dataset = this.createDataset();

    JFreeChart chart = ChartFactory.createStackedBarChart("Needs over Time (Consumer and Staff)", // chart title
            "Assessments", // x axis label
            "# of Domain", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//from w ww. ja v a  2  s. c o  m

    chart.setBackgroundPaint(Color.LIGHT_GRAY);

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("Consumer (Unknown)", "G1");
    map.mapKeyToGroup("Consumer (No Needs)", "G1");
    map.mapKeyToGroup("Consumer (Met Needs)", "G1");
    map.mapKeyToGroup("Consumer (Unmet Needs)", "G1");

    map.mapKeyToGroup("Staff (Unknown)", "G2");
    map.mapKeyToGroup("Staff (No Needs)", "G2");
    map.mapKeyToGroup("Staff (Met Needs)", "G2");
    map.mapKeyToGroup("Staff (Unmet Needs)", "G2");

    renderer.setSeriesToGroupMap(map);
    renderer.setItemMargin(0.1);
    //renderer.setItemLabelsVisible(true);
    renderer.setMaximumBarWidth(15);

    Paint p1 = Color.GREEN;
    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(7, p1);

    Paint p2 = Color.BLUE;
    renderer.setSeriesPaint(1, p2);
    renderer.setSeriesPaint(5, p2);
    renderer.setSeriesPaint(8, p2);

    Paint p3 = new Color(255, 255, 153);
    renderer.setSeriesPaint(2, p3);
    renderer.setSeriesPaint(6, p3);
    renderer.setSeriesPaint(9, p3);

    Paint p4 = Color.ORANGE;
    renderer.setSeriesPaint(3, p4);
    renderer.setSeriesPaint(7, p4);
    renderer.setSeriesPaint(10, p4);

    SubCategoryAxis domainAxis = new SubCategoryAxis("Assessments");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.addSubCategory("Consumer");
    domainAxis.addSubCategory("Staff");
    domainAxis.setMinorTickMarkInsideLength(10);
    domainAxis.setMinorTickMarkInsideLength(10);
    domainAxis.setMinorTickMarksVisible(true);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    plot.setRenderer(renderer);

    LegendItemCollection result = new LegendItemCollection();
    LegendItem item1 = new LegendItem("Unknown", Color.GREEN);
    LegendItem item2 = new LegendItem("No Needs", Color.BLUE);
    LegendItem item3 = new LegendItem("Met Needs", new Color(255, 255, 153));
    LegendItem item4 = new LegendItem("Unmet Needs", Color.ORANGE);

    result.add(item1);
    result.add(item2);
    result.add(item3);
    result.add(item4);

    plot.setFixedLegendItems(result);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.black);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(new Range(0, 24), true, false);
    rangeAxis.setTickUnit(new NumberTickUnit(4));

    plot.getDomainAxis().setCategoryMargin(0.35);

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));

    return chart;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.StackedBarGroup.java

/**
 * Inherited by IChart./*from   w w  w  . j a v  a  2 s.  com*/
 * 
 * @param chartTitle the chart title
 * @param dataset the dataset
 * 
 * @return the j free chart
 */

public JFreeChart createChart(DatasetMap datasets) {

    logger.debug("IN");
    CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1");

    logger.debug("Get plot orientaton");
    PlotOrientation plotOrientation = PlotOrientation.VERTICAL;
    if (horizontalView) {
        plotOrientation = PlotOrientation.HORIZONTAL;
    }

    JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title
            categoryLabel, // domain axis label
            valueLabel, // range axis label
            dataset, // data
            plotOrientation, // the plot orientation
            legend, // legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(color);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    int numElForGroup = 0;
    for (int idx = 0; idx < numGroups.intValue(); idx++) {
        for (int j = 0; j < numSerieForGroup.intValue(); j++) {
            try {
                String tmpSubCat = (String) subCategoryNames.get(j + idx * numSerieForGroup.intValue());
                map.mapKeyToGroup(tmpSubCat, "G" + (idx + 1));

            } catch (Exception e) {
                logger.error("out of range error in inserting in stacked bar group: continue anayway", e);
            }
        }
    }

    renderer.setSeriesToGroupMap(map);
    renderer.setItemMargin(0.0);
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(true);
    if (percentageValue)
        renderer.setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%")));
    else
        renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

    if (maxBarWidth != null) {
        renderer.setMaximumBarWidth(maxBarWidth.doubleValue());
    }

    boolean document_composition = false;
    if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
        document_composition = true;

    /*
    MyCategoryUrlGenerator mycatUrl=new MyCategoryUrlGenerator(rootUrl);
    mycatUrl.setDocument_composition(document_composition);
    mycatUrl.setCategoryUrlLabel(categoryUrlName);
    mycatUrl.setSerieUrlLabel(serieUrlname);
            
    renderer.setItemURLGenerator(mycatUrl);
     */

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(color);

    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setNumberFormatOverride(nf);
    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    if (rangeAxisLocation != null) {
        if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
        } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
        }
    }

    int seriesN = dataset.getRowCount();
    int numSerieColored = 0;

    if (orderColorVector != null && orderColorVector.size() > 0) {
        logger.debug("color serie by SERIES_ORDER_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            if (orderColorVector.get(i) != null) {
                Color color = orderColorVector.get(i);
                renderer.setSeriesPaint(i, color);
            }
        }
    } else if (colorMap != null) {
        while (numSerieColored < seriesN) {
            for (int i = 1; i <= colorMap.size(); i++) {
                Color color = (Color) colorMap.get("SER" + i);
                Color gradient = new Color(Integer.decode("#FFFFFF").intValue());
                if (gradientMap != null)
                    gradient = (Color) gradientMap.get("SER" + i);

                if (color != null) {
                    Paint p = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, gradient);

                    //renderer.setSeriesPaint(numSerieColored, color);
                    renderer.setSeriesPaint(numSerieColored, p);
                }
                numSerieColored++;
            }
        }
    }
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    MyStandardCategoryItemLabelGenerator generator = null;
    if (additionalLabels) {
        generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance());

        double orient = (-Math.PI / 2.0);
        if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
            orient = 0.0;
        }
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

        renderer.setBaseItemLabelGenerator(generator);
        renderer.setBaseItemLabelsVisible(true);
        //vertical labels          
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        renderer.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));

        //horizontal labels
        /*
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
           ItemLabelAnchor.CENTER, TextAnchor.CENTER));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
           ItemLabelAnchor.CENTER, TextAnchor.CENTER));
         */

    }

    SubCategoryAxis domainAxis = new SubCategoryAxis(categoryLabel + " / " + subCategoryLabel);
    String subCatLabel = "";
    for (int j = 1; j <= numGroups.intValue(); j++) {
        if (subCatLabelsMap != null)
            subCatLabel = (String) subCatLabelsMap.get("CAT" + j);
        else
            subCatLabel = subCategoryLabel;

        domainAxis.addSubCategory(subCatLabel);
        domainAxis
                .setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
        domainAxis.setLabelPaint(styleYaxesLabels.getColor());
        domainAxis.setTickLabelFont(
                new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
        domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());
    }
    plot.setDomainAxis(domainAxis);
    plot.setRenderer(renderer);

    /*
    domainAxis.setCategoryLabelPositions(
    CategoryLabelPositions.createUpRotationLabelPositions(
          Math.PI / 6.0));
     */
    if (legend == true)
        drawLegend(chart);
    logger.debug("OUT");
    return chart;

}

From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java

public ChartGenerationFrame()//dummy constructor for testing
{

    initComponents();// w w w .j a  v a  2s  .c om
    this.addRadioButtonGroup();
    // create a baseDataset...
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(20.3, "Product 1 (US)", "Jan 04");
    dataset.addValue(27.2, "Product 1 (US)", "Feb 04");
    dataset.addValue(19.7, "Product 1 (US)", "Mar 04");
    dataset.addValue(19.4, "Product 1 (Europe)", "Jan 04");
    dataset.addValue(10.9, "Product 1 (Europe)", "Feb 04");
    dataset.addValue(18.4, "Product 1 (Europe)", "Mar 04");
    dataset.addValue(16.5, "Product 1 (Asia)", "Jan 04");
    dataset.addValue(15.9, "Product 1 (Asia)", "Feb 04");
    dataset.addValue(16.1, "Product 1 (Asia)", "Mar 04");
    dataset.addValue(13.2, "Product 1 (Middle East)", "Jan 04");
    dataset.addValue(14.4, "Product 1 (Middle East)", "Feb 04");
    dataset.addValue(13.7, "Product 1 (Middle East)", "Mar 04");

    dataset.addValue(23.3, "Product 2 (US)", "Jan 04");
    dataset.addValue(16.2, "Product 2 (US)", "Feb 04");
    dataset.addValue(28.7, "Product 2 (US)", "Mar 04");
    dataset.addValue(12.7, "Product 2 (Europe)", "Jan 04");
    dataset.addValue(17.9, "Product 2 (Europe)", "Feb 04");
    dataset.addValue(12.6, "Product 2 (Europe)", "Mar 04");
    dataset.addValue(15.4, "Product 2 (Asia)", "Jan 04");
    dataset.addValue(21.0, "Product 2 (Asia)", "Feb 04");
    dataset.addValue(11.1, "Product 2 (Asia)", "Mar 04");
    dataset.addValue(23.8, "Product 2 (Middle East)", "Jan 04");
    dataset.addValue(23.4, "Product 2 (Middle East)", "Feb 04");
    dataset.addValue(19.3, "Product 2 (Middle East)", "Mar 04");

    dataset.addValue(11.9, "Product 3 (US)", "Jan 04");
    dataset.addValue(31.0, "Product 3 (US)", "Feb 04");
    dataset.addValue(22.7, "Product 3 (US)", "Mar 04");
    dataset.addValue(15.3, "Product 3 (Europe)", "Jan 04");
    dataset.addValue(14.4, "Product 3 (Europe)", "Feb 04");
    dataset.addValue(25.3, "Product 3 (Europe)", "Mar 04");
    dataset.addValue(23.9, "Product 3 (Asia)", "Jan 04");
    dataset.addValue(19.0, "Product 3 (Asia)", "Feb 04");
    dataset.addValue(10.1, "Product 3 (Asia)", "Mar 04");
    dataset.addValue(13.2, "Product 3 (Middle East)", "Jan 04");
    dataset.addValue(15.5, "Product 3 (Middle East)", "Feb 04");
    dataset.addValue(10.1, "Product 3 (Middle East)", "Mar 04");
    // create a chart...
    IBarChart c = new CustomBarChart("Test barchart", "Domain", "Range", PlotOrientation.VERTICAL, true);
    c.generate3DStackedBarChart(dataset);
    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("Product 1 (US)", "G1");
    map.mapKeyToGroup("Product 1 (Europe)", "G1");
    map.mapKeyToGroup("Product 1 (Asia)", "G1");
    map.mapKeyToGroup("Product 1 (Middle East)", "G1");
    map.mapKeyToGroup("Product 2 (US)", "G2");
    map.mapKeyToGroup("Product 2 (Europe)", "G2");
    map.mapKeyToGroup("Product 2 (Asia)", "G2");
    map.mapKeyToGroup("Product 2 (Middle East)", "G2");
    map.mapKeyToGroup("Product 3 (US)", "G3");
    map.mapKeyToGroup("Product 3 (Europe)", "G3");
    map.mapKeyToGroup("Product 3 (Asia)", "G3");
    map.mapKeyToGroup("Product 3 (Middle East)", "G3");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(8, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);
    renderer.setSeriesPaint(5, p2);
    renderer.setSeriesPaint(9, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);
    renderer.setSeriesPaint(6, p3);
    renderer.setSeriesPaint(10, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setSeriesPaint(7, p4);
    renderer.setSeriesPaint(11, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.addSubCategory("Product 1");
    domainAxis.addSubCategory("Product 2");
    domainAxis.addSubCategory("Product 3");

    CategoryPlot plot = (CategoryPlot) ((CustomJFreeChart) c).getPlot();
    plot.setDomainAxis(domainAxis);
    //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setRenderer(renderer);
    //plot.setFixedLegendItems(createLegendItems());

    ChartPanel panel = c.drawChart("Chart Editor").getChartPanel();

    ChartPanel.add(panel);
    //ChartPanel.setSize(panel.getWidth(), panel.getHeight());
    splitPane.setDividerLocation(panel.getHeight());
    //test table
    //H4_2 t = new H4_2();
    //CustomJTable temp = (CustomJTable) t.generateTable();
    //temp.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    //JScrollPane tableScrollPane = new JScrollPane(temp);
    //tableScrollPane.add(temp);
    //splitPane.setBottomComponent(tableScrollPane);
    //temp.setCellSelectionEnabled(true);
    //this.getContentPane().add(TablePanel)
}