List of usage examples for org.jfree.chart.renderer.category StackedBarRenderer StackedBarRenderer
public StackedBarRenderer(boolean renderAsPercentages)
From source file:edu.gmu.cs.sim.util.media.chart.BarChartGenerator.java
protected void buildGlobalAttributes(LabelledList list) { // create the chart CategoryPlot plot = (CategoryPlot) (chart.getPlot()); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinePaint(new Color(200, 200, 200)); plot.setRangeGridlinePaint(new Color(200, 200, 200)); // define the renderers barRenderer = new BarRenderer(); reviseRenderer(barRenderer);/*from w w w . ja va 2 s . com*/ stackedBarRenderer = new StackedBarRenderer(false); reviseRenderer(stackedBarRenderer); percentageRenderer = new StackedBarRenderer(true); reviseRenderer(percentageRenderer); plot.setRenderer(barRenderer); xLabel = new PropertyField() { public String newValue(String newValue) { setXAxisLabel(newValue); getChartPanel().repaint(); return newValue; } }; xLabel.setValue(getXAxisLabel()); list.add(new JLabel("X Label"), xLabel); yLabel = new PropertyField() { public String newValue(String newValue) { setYAxisLabel(newValue); getChartPanel().repaint(); return newValue; } }; yLabel.setValue(getYAxisLabel()); list.add(new JLabel("Y Label"), yLabel); final JCheckBox gridlines = new JCheckBox(); gridlines.setSelected(false); ItemListener il = new ItemListener() { public void itemStateChanged(ItemEvent e) { hasgridlines = (e.getStateChange() == ItemEvent.SELECTED); updateGridLines(); } }; gridlines.addItemListener(il); list.add(new JLabel("Grid Lines"), gridlines); final JCheckBox labels = new JCheckBox(); labels.setSelected(true); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { getBarRenderer().setBaseItemLabelsVisible(true); getStackedBarRenderer().setBaseItemLabelsVisible(true); getPercentageRenderer().setBaseItemLabelsVisible(true); } else { getBarRenderer().setBaseItemLabelsVisible(false); getStackedBarRenderer().setBaseItemLabelsVisible(false); getPercentageRenderer().setBaseItemLabelsVisible(false); } } }; labels.addItemListener(il); list.add(new JLabel("Labels"), labels); final JComboBox barType = new JComboBox(); barType.setEditable(false); barType.setModel(new DefaultComboBoxModel( new java.util.Vector(Arrays.asList(new String[] { "Separate", "Stacked", "Percentage" })))); barType.setSelectedIndex(0); barType.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CategoryPlot plot = (CategoryPlot) (chart.getPlot()); int type = barType.getSelectedIndex(); if (type == 0) // separate { plot.setRenderer(getBarRenderer()); } else if (type == 1) // stacked { plot.setRenderer(getStackedBarRenderer()); } else // percentage { plot.setRenderer(getPercentageRenderer()); } } }); list.add(new JLabel("Bars"), barType); final JCheckBox horizontal = new JCheckBox(); horizontal.setSelected(false); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { CategoryPlot plot = (CategoryPlot) (chart.getPlot()); if (e.getStateChange() == ItemEvent.SELECTED) { plot.setOrientation(PlotOrientation.HORIZONTAL); ishorizontal = true; } else { plot.setOrientation(PlotOrientation.VERTICAL); ishorizontal = false; } updateGridLines(); } }; horizontal.addItemListener(il); list.add(new JLabel("Horizontal"), horizontal); }
From source file:org.fhaes.fhrecorder.view.ColorBarGraph.java
/** * Creates the chart with the data from the given data set. * /*www. j av a2 s . c o m*/ * @param dataset the data to plot. * @return the chart. */ private static JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.VERTICAL, false, true, false); StackedBarRenderer renderer = new StackedBarRenderer(true); renderer.setShadowVisible(false); renderer.setBarPainter(new StandardBarPainter()); // Remove shine renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot plot = chart.getCategoryPlot(); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(new Color(192, 192, 192)); plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.getDomainAxis().setVisible(false); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setLowerMargin(.025); plot.getDomainAxis().setUpperMargin(.025); chart.setBackgroundPaint(new Color(214, 217, 233, 30)); return chart; }
From source file:com.greenpepper.confluence.macros.historic.AggregationExecutionChartBuilder.java
private void customizeChart(JFreeChart chart) throws IOException { chart.setBackgroundPaint(Color.white); chart.setBorderVisible(settings.isBorder()); TextTitle chartTitle = chart.getTitle(); customizeTitle(chartTitle, DEFAULT_TITLE_FONT); addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT); addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage(gpUtil.getText("greenpepper.historic.nodata")); StackedBarRenderer renderer = new StackedBarRenderer(true); plot.setRenderer(renderer);//w ww. ja va 2 s . c om int index = 0; renderer.setSeriesPaint(index++, GREEN_COLOR); if (settings.isShowIgnored()) renderer.setSeriesPaint(index++, Color.yellow); renderer.setSeriesPaint(index, Color.red); renderer.setToolTipGenerator(new DefaultTooltipGenerator()); renderer.setItemURLGenerator(new CategoryURLGenerator() { public String generateURL(CategoryDataset data, int series, int category) { Comparable valueKey = data.getColumnKey(category); ChartLongValue value = (ChartLongValue) valueKey; return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');"; } }); CategoryAxis domainAxis = plot.getDomainAxis(); customizeAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setCategoryMargin(0.01); ValueAxis rangeAxis = plot.getRangeAxis(); customizeAxis(rangeAxis); rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(1.0); if (rangeAxis instanceof NumberAxis) { NumberAxis numberAxis = (NumberAxis) rangeAxis; numberAxis.setTickUnit(new NumberTickUnit(.10)); numberAxis.setNumberFormatOverride(PERCENT_FORMATTER); } plot.setForegroundAlpha(0.8f); }
From source file:info.novatec.testit.livingdoc.confluence.macros.historic.AggregationExecutionChartBuilder.java
@SuppressWarnings("deprecation") private void customizeChart(JFreeChart chart) throws IOException { chart.setBackgroundPaint(Color.white); chart.setBorderVisible(settings.isBorder()); TextTitle chartTitle = chart.getTitle(); customizeTitle(chartTitle, DEFAULT_TITLE_FONT); addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT); addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata")); StackedBarRenderer renderer = new StackedBarRenderer(true); plot.setRenderer(renderer);/* www . jav a 2s . c o m*/ int index = 0; renderer.setSeriesPaint(index++, GREEN_COLOR); if (settings.isShowIgnored()) { renderer.setSeriesPaint(index++, Color.yellow); } renderer.setSeriesPaint(index, Color.red); renderer.setToolTipGenerator(new DefaultTooltipGenerator()); renderer.setItemURLGenerator(new CategoryURLGenerator() { @Override public String generateURL(CategoryDataset data, int series, int category) { Comparable<?> valueKey = data.getColumnKey(category); ChartLongValue value = (ChartLongValue) valueKey; return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');"; } }); CategoryAxis domainAxis = plot.getDomainAxis(); customizeAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setCategoryMargin(0.01); ValueAxis rangeAxis = plot.getRangeAxis(); customizeAxis(rangeAxis); rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(1.0); if (rangeAxis instanceof NumberAxis) { NumberAxis numberAxis = (NumberAxis) rangeAxis; numberAxis.setTickUnit(new NumberTickUnit(.10)); numberAxis.setNumberFormatOverride(PERCENT_FORMATTER); } plot.setForegroundAlpha(0.8f); }