List of usage examples for org.jfree.data KeyToGroupMap mapKeyToGroup
public void mapKeyToGroup(Comparable key, Comparable group)
From source file:org.jfree.chart.demo.StackedBarChartDemo5.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 5", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); GroupedStackedBarRenderer groupedstackedbarrenderer = new GroupedStackedBarRenderer(); KeyToGroupMap keytogroupmap = new KeyToGroupMap("G1"); keytogroupmap.mapKeyToGroup("S1", "G1"); keytogroupmap.mapKeyToGroup("S2", "G1"); keytogroupmap.mapKeyToGroup("S3", "G2"); keytogroupmap.mapKeyToGroup("S4", "G3"); groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap); groupedstackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); groupedstackedbarrenderer.setBaseItemLabelsVisible(true); groupedstackedbarrenderer.setPositiveItemLabelPositionFallback( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); groupedstackedbarrenderer.setItemMargin(0.10000000000000001D); SubCategoryAxis subcategoryaxis = new SubCategoryAxis("Category / Group"); subcategoryaxis.setCategoryMargin(0.050000000000000003D); subcategoryaxis.addSubCategory("G1"); subcategoryaxis.addSubCategory("G2"); subcategoryaxis.addSubCategory("G3"); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setDomainAxis(subcategoryaxis); categoryplot.setRenderer(groupedstackedbarrenderer); return jfreechart; }
From source file:org.jfree.chart.demo.DualAxisDemo6.java
private static JFreeChart createChart(CategoryDataset categorydataset, CategoryDataset categorydataset1) { CategoryAxis categoryaxis = new CategoryAxis("Category"); NumberAxis numberaxis = new NumberAxis("Value"); GroupedStackedBarRenderer groupedstackedbarrenderer = new GroupedStackedBarRenderer(); KeyToGroupMap keytogroupmap = new KeyToGroupMap("G1"); keytogroupmap.mapKeyToGroup("Series 1A", "G1"); keytogroupmap.mapKeyToGroup("Series 1B", "G1"); keytogroupmap.mapKeyToGroup("NOTHING", "G2"); groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap); CategoryPlot categoryplot = new CategoryPlot(categorydataset, categoryaxis, numberaxis, groupedstackedbarrenderer) { private static final long serialVersionUID = 1L; public LegendItemCollection getLegendItems() { LegendItemCollection legenditemcollection = new LegendItemCollection(); legenditemcollection.addAll(getRenderer().getLegendItems()); CategoryDataset categorydataset2 = getDataset(1); if (categorydataset2 != null) { CategoryItemRenderer categoryitemrenderer = getRenderer(1); if (categoryitemrenderer != null) { org.jfree.chart.LegendItem legenditem = categoryitemrenderer.getLegendItem(1, 1); legenditemcollection.add(legenditem); }// w ww . j ava 2 s.co m } return legenditemcollection; } }; JFreeChart jfreechart = new JFreeChart("Dual Axis Bar Chart", categoryplot); categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); categoryplot.setDataset(1, categorydataset1); categoryplot.mapDatasetToRangeAxis(1, 1); NumberAxis numberaxis1 = new NumberAxis("Secondary"); categoryplot.setRangeAxis(1, numberaxis1); categoryplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); BarRenderer barrenderer = new BarRenderer(); categoryplot.setRenderer(1, barrenderer); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:org.pentaho.chart.plugin.jfreechart.utils.JFreeChartUtils.java
/** * @param chartDocument//from w ww. java 2 s . co m * @param data * @return */ public static KeyToGroupMap createKeyToGroupMap(final ChartDocument chartDocument, final ChartTableModel data, final CategoryDataset dataSet) { ChartElement groupElement = getBaseStackedGroupElement(chartDocument); // First build the set of keys to match against final Set matchSet = new HashSet(); final int rowCount = data.getRowCount(); for (int row = 0; row < rowCount; row++) { final StringBuffer keyStr = new StringBuffer(); final int groupDepth = getGroupDepth(groupElement); for (int i = 0; i < groupDepth; i++) { final String columnName = groupElement.getAttribute(ChartElement.COLUMN_NAME).toString(); final int columnNum = data.findColumn(columnName); keyStr.append(data.getValueAt(row, columnNum)).append(SEPERATOR); groupElement = getChildGroup(groupElement); } matchSet.add(keyStr.toString()); groupElement = getBaseStackedGroupElement(chartDocument); } // Now we match them and add then to an appropriate group final KeyToGroupMap keyToGroupMap = new KeyToGroupMap(); for (final Object aMatchSet : matchSet) { final String matchStr = aMatchSet.toString(); final Iterator rowHeaderIterator = dataSet.getRowKeys().iterator(); while (rowHeaderIterator.hasNext()) { final String rowHeader = aMatchSet.toString(); if (rowHeader.startsWith(matchStr)) { keyToGroupMap.mapKeyToGroup(rowHeader, matchStr); } } } return keyToGroupMap; }
From source file:CPU.StackedBarChartExample1.java
/** * Create chart//from ww w . j a v a 2s. c o m * @param dataset * @return */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart stackedChart = ChartFactory.createStackedBarChart("Stacked Bar Chart", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, true, false); //create group GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); map.mapKeyToGroup("Toyota (US)", "G1"); map.mapKeyToGroup("Toyota (Europe)", "G1"); map.mapKeyToGroup("Toyota (Asia)", "G1"); map.mapKeyToGroup("Ford (US)", "G2"); map.mapKeyToGroup("Ford (Europe)", "G2"); map.mapKeyToGroup("Ford (Asia)", "G2"); map.mapKeyToGroup("BMW (US)", "G3"); map.mapKeyToGroup("BMW (Europe)", "G3"); map.mapKeyToGroup("BMW (Asia)", "G3"); renderer.setSeriesToGroupMap(map); //margin between bar. renderer.setItemMargin(0.03); //end SubCategoryAxis dom_axis = new SubCategoryAxis("Car Production / Month"); //Margin between group dom_axis.setCategoryMargin(0.06); //end dom_axis.addSubCategory("Toyota"); dom_axis.addSubCategory("Ford"); dom_axis.addSubCategory("BMW"); CategoryPlot plot = (CategoryPlot) stackedChart.getPlot(); plot.setDomainAxis(dom_axis); plot.setRenderer(renderer); return stackedChart; }
From source file:org.jfree.data.KeyToGroupMapTest.java
/** * Confirm that cloning works./*from w w w .j av a2 s. c o m*/ */ @Test public void testCloning() throws CloneNotSupportedException { KeyToGroupMap m1 = new KeyToGroupMap("Test"); m1.mapKeyToGroup("K1", "G1"); KeyToGroupMap m2 = (KeyToGroupMap) m1.clone(); assertTrue(m1 != m2); assertTrue(m1.getClass() == m2.getClass()); assertTrue(m1.equals(m2)); // a small check for independence m1.mapKeyToGroup("K1", "G2"); assertFalse(m1.equals(m2)); m2.mapKeyToGroup("K1", "G2"); assertTrue(m1.equals(m2)); }
From source file:org.altaprise.vawr.charts.demos.StackedBarChartDemo4.java
/** * Creates a sample chart.//from ww w . ja v a 2s . co m * * @param dataset the dataset for the chart. * * @return A sample chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 4", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); 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) chart.getPlot(); plot.setDomainAxis(domainAxis); //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); plot.setRenderer(renderer); plot.setFixedLegendItems(createLegendItems()); return chart; }
From source file:playground.yu.utils.charts.StackedBarChart.java
public void addSeries(String[] rowKeys, String[] columnKeys, String[] subCategoryKeys, double[][] values) { for (int rowIdx = 0; rowIdx < values.length; rowIdx++) { for (int columnIdx = 0; columnIdx < values[rowIdx].length; columnIdx++) { dataset.addValue(Double.valueOf(values[rowIdx][columnIdx]), rowKeys[rowIdx], columnKeys[columnIdx]); }//from w w w . ja v a2s. c o m } GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap(subCategoryKeys[0]); int size = rowKeys.length / subCategoryKeys.length; for (int rowIdx = 0; rowIdx < rowKeys.length; rowIdx++) { map.mapKeyToGroup(rowKeys[rowIdx], subCategoryKeys[rowIdx / size]); } renderer.setSeriesToGroupMap(map); Color[] paints = new Color[size]; Random random = MatsimRandom.getLocalInstance(); for (int i = 0; i < paints.length; i++) { paints[i] = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)); } for (int i = 0; i < rowKeys.length; i++) { renderer.setSeriesPaint(i, paints[i % size]); } CategoryPlot plot = (CategoryPlot) chart.getPlot(); SubCategoryAxis domainAxis = new SubCategoryAxis("subCategory / column"); for (int subCtgr = 0; subCtgr < subCategoryKeys.length; subCtgr++) { domainAxis.addSubCategory(subCategoryKeys[subCtgr]); } plot.setDomainAxis(domainAxis); plot.setRenderer(renderer); // plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); }
From source file:org.jfree.data.KeyToGroupMapTest.java
/** * Tests the mapKeyToGroup() method./* ww w.j a v a2s. c om*/ */ @Test public void testMapKeyToGroup() { KeyToGroupMap m1 = new KeyToGroupMap("G1"); // map a key to the default group m1.mapKeyToGroup("K1", "G1"); assertEquals("G1", m1.getGroup("K1")); // map a key to a new group m1.mapKeyToGroup("K2", "G2"); assertEquals("G2", m1.getGroup("K2")); // clear a mapping m1.mapKeyToGroup("K2", null); assertEquals("G1", m1.getGroup("K2")); // after clearing, reverts to // default group // check handling of null key boolean pass = false; try { m1.mapKeyToGroup(null, "G1"); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet2.java
private JFreeChart getChart(CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 4", // chart title "Category", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls );/*from w ww.j a v a 2s . c o m*/ TextTitle title = new TextTitle(" ()", labelFont); title.setPaint(new Color(68, 99, 156)); chart.setTitle(title); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); map.mapKeyToGroup("product 1 (US)", "G1"); map.mapKeyToGroup("product 1 (Europe)", "G1"); renderer.setSeriesToGroupMap(map); BarPainter b = new StandardBarPainter(); // BarPainter b = new GradientBarPainter(0,0.9,0.9); renderer.setBarPainter(b); renderer.setSeriesPaint(0, color1); renderer.setSeriesPaint(1, color2); SubCategoryAxis domainAxis = new SubCategoryAxis("DCM / JPG "); domainAxis.setCategoryMargin(0.05); domainAxis.setTickLabelFont(dateFont); // domainAxis.addSubCategory("Product 1"); // domainAxis.addSubCategory("Product 2"); // domainAxis.addSubCategory("Product 3"); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(domainAxis); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.red); plot.setRangeGridlinePaint(Color.lightGray); ValueAxis v = plot.getRangeAxis(); v.setTickLabelFont(dateFont); // plot.setRangeAxis(ValueAxis); //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); plot.setRenderer(renderer); plot.setFixedLegendItems(createLegendItems()); return chart; }
From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet2.java
private JFreeChart getChart(CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 4", // chart title "Category", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls );//from ww w .ja v a 2 s . c o m TextTitle title = new TextTitle("? ? ? (.)", labelFont); title.setPaint(new Color(68, 99, 156)); chart.setTitle(title); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); map.mapKeyToGroup("product 1 (US)", "G1"); map.mapKeyToGroup("product 1 (Europe)", "G1"); renderer.setSeriesToGroupMap(map); BarPainter b = new StandardBarPainter(); // BarPainter b = new GradientBarPainter(0,0.9,0.9); renderer.setBarPainter(b); renderer.setSeriesPaint(0, color1); renderer.setSeriesPaint(1, color2); SubCategoryAxis domainAxis = new SubCategoryAxis(" / "); domainAxis.setCategoryMargin(0.05); domainAxis.setTickLabelFont(dateFont); // domainAxis.addSubCategory("Product 1"); // domainAxis.addSubCategory("Product 2"); // domainAxis.addSubCategory("Product 3"); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(domainAxis); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.red); plot.setRangeGridlinePaint(Color.lightGray); ValueAxis v = plot.getRangeAxis(); v.setTickLabelFont(dateFont); // plot.setRangeAxis(ValueAxis); //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); plot.setRenderer(renderer); plot.setFixedLegendItems(createLegendItems()); return chart; }