List of usage examples for org.jfree.chart.axis CategoryAxis setVisible
public void setVisible(boolean flag)
From source file:org.jfree.chart.demo.ItemLabelDemo3.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart("Item Label Demo 3", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinePaint(Color.white); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setVisible(false); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperMargin(0.14999999999999999D); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator( "{1}", NumberFormat.getInstance()); categoryitemrenderer.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); categoryitemrenderer.setBaseItemLabelFont(new Font("SansSerif", 0, 12)); categoryitemrenderer.setBaseItemLabelsVisible(true); categoryitemrenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, -1.5707963267948966D)); return jfreechart; }
From source file:org.nbheaven.sqe.codedefects.dashboard.controlcenter.panels.Statistics.java
private static JFreeChart createOverviewPanel(DefaultCategoryDataset dataSet) { JFreeChart overview = org.jfree.chart.ChartFactory.createStackedBarChart(null, null, "CodeDefects", dataSet, PlotOrientation.HORIZONTAL, false, true, false); overview.setBorderVisible(false);/*from w w w. j a v a 2s .c om*/ overview.setBackgroundPaint(Color.WHITE); overview.setAntiAlias(true); overview.setNotify(true); CategoryPlot overviewPlot = overview.getCategoryPlot(); overviewPlot.setRangeGridlinePaint(Color.BLACK); overviewPlot.setDomainGridlinePaint(Color.BLACK); overviewPlot.setBackgroundPaint(Color.WHITE); overviewPlot.setForegroundAlpha(0.7f); overviewPlot.setRangeAxisLocation(AxisLocation.getOpposite(overviewPlot.getRangeAxisLocation())); CategoryAxis domainAxis = overviewPlot.getDomainAxis(); domainAxis.setVisible(true); LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects"); rangeAxis.setLabel(null); rangeAxis.setStrictValuesFlag(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); overviewPlot.setRangeAxis(rangeAxis); CategoryItemRenderer categoryItemRenderer = new StackedBarRenderer(); //3D(); // categoryItemRenderers[0].setPaint(Color.RED); categoryItemRenderer.setSeriesPaint(0, Color.RED); categoryItemRenderer.setSeriesPaint(1, Color.ORANGE); categoryItemRenderer.setSeriesPaint(2, Color.YELLOW); categoryItemRenderer.setBaseItemLabelsVisible(true); overviewPlot.setRenderer(categoryItemRenderer); return overview; }
From source file:org.jfree.chart.demo.SurveyResultsDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart(null, null, null, categorydataset, PlotOrientation.HORIZONTAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle texttitle = new TextTitle( "Figure 7 | I. Resources - The site offers users relevant, informative and educational resources"); texttitle.setHorizontalAlignment(HorizontalAlignment.LEFT); texttitle.setBackgroundPaint(Color.red); texttitle.setPaint(Color.white); jfreechart.setTitle(texttitle);/*ww w. j a v a2 s.c om*/ CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setOutlinePaint(null); categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePosition(CategoryAnchor.END); categoryplot.setDomainGridlineStroke(new BasicStroke(0.5F)); categoryplot.setDomainGridlinePaint(Color.black); categoryplot.setRangeGridlinesVisible(false); categoryplot.clearRangeMarkers(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setVisible(false); categoryaxis.setCategoryMargin(0.5D); categoryplot.getRangeAxis().setVisible(false); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setSeriesPaint(0, new Color(156, 164, 74)); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelFont(new Font("SansSerif", 1, 10)); ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); barrenderer.setBasePositiveItemLabelPosition(itemlabelposition); CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("1. White papers are available.", "Category 1", 0.0D); categorytextannotation.setFont(new Font("SansSerif", 1, 12)); categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation); CategoryTextAnnotation categorytextannotation1 = new CategoryTextAnnotation( "2. White papers enhance users understanding of the firm and its expertise.", "Category 2", 0.0D); categorytextannotation1.setFont(new Font("SansSerif", 0, 12)); categorytextannotation1.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation1.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation1); CategoryTextAnnotation categorytextannotation2 = new CategoryTextAnnotation( "3. White papers are relevant to the firm's prospects and clients.", "Category 3", 0.0D); categorytextannotation2.setFont(new Font("SansSerif", 0, 12)); categorytextannotation2.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation2.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation2); CategoryTextAnnotation categorytextannotation3 = new CategoryTextAnnotation( "4. White papers are relevant to the firm's positioning.", "Category 4", 0.0D); categorytextannotation3.setFont(new Font("SansSerif", 0, 12)); categorytextannotation3.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation3.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation3); CategoryTextAnnotation categorytextannotation4 = new CategoryTextAnnotation( "5. Case studies are available.", "Category 5", 0.0D); categorytextannotation4.setFont(new Font("SansSerif", 1, 12)); categorytextannotation4.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation4.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation4); CategoryTextAnnotation categorytextannotation5 = new CategoryTextAnnotation( "6. Case studies enhance users understanding of the firm and its expertise.", "Category 6", 0.0D); categorytextannotation5.setFont(new Font("SansSerif", 0, 12)); categorytextannotation5.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation5.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation5); CategoryTextAnnotation categorytextannotation6 = new CategoryTextAnnotation( "7. Case studies are relevant to the firm's prospects and clients.", "Category 7", 0.0D); categorytextannotation6.setFont(new Font("SansSerif", 0, 12)); categorytextannotation6.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation6.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation6); CategoryTextAnnotation categorytextannotation7 = new CategoryTextAnnotation( "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0D); categorytextannotation7.setFont(new Font("SansSerif", 0, 12)); categorytextannotation7.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation7.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation7); CategoryTextAnnotation categorytextannotation8 = new CategoryTextAnnotation( "9. Case studies are available.", "Category 9", 0.0D); categorytextannotation8.setFont(new Font("SansSerif", 1, 12)); categorytextannotation8.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation8.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation8); CategoryTextAnnotation categorytextannotation9 = new CategoryTextAnnotation( "10. Case studies enhance users understanding of the firm and its expertise.", "Category 10", 0.0D); categorytextannotation9.setFont(new Font("SansSerif", 0, 12)); categorytextannotation9.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation9.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation9); CategoryTextAnnotation categorytextannotation10 = new CategoryTextAnnotation( "11. Case studies are relevant to the firm's prospects and clients.", "Category 11", 0.0D); categorytextannotation10.setFont(new Font("SansSerif", 0, 12)); categorytextannotation10.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation10.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation10); CategoryTextAnnotation categorytextannotation11 = new CategoryTextAnnotation( "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0D); categorytextannotation11.setFont(new Font("SansSerif", 0, 12)); categorytextannotation11.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation11.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation11); CategoryTextAnnotation categorytextannotation12 = new CategoryTextAnnotation( "13. Users can easily access resources based on viewer interest.", "Category 13", 0.0D); categorytextannotation12.setFont(new Font("SansSerif", 1, 12)); categorytextannotation12.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation12.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation12); CategoryTextAnnotation categorytextannotation13 = new CategoryTextAnnotation( "14. Access to additional hyperlinks enhances users's ability to find relevant information.", "Category 14", 0.0D); categorytextannotation13.setFont(new Font("SansSerif", 1, 12)); categorytextannotation13.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation13.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation13); CategoryTextAnnotation categorytextannotation14 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.", "Overall", 0.0D); categorytextannotation14.setFont(new Font("SansSerif", 1, 12)); categorytextannotation14.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation14.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation14); return jfreechart; }
From source file:jgnash.ui.budget.BudgetSparkline.java
public static Icon getSparklineImage(final List<BigDecimal> amounts) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final boolean[] negate = new boolean[amounts.size()]; for (int i = 0; i < amounts.size(); i++) { dataset.addValue(amounts.get(i), CATEGORY, i); negate[i] = amounts.get(i).signum() == -1; }/*from w ww.jav a 2s . c o m*/ CategoryAxis xAxis = new CategoryAxis(); xAxis.setTickLabelsVisible(false); xAxis.setTickMarksVisible(false); xAxis.setAxisLineVisible(false); xAxis.setVisible(false); NumberAxis yAxis = new NumberAxis(); yAxis.setTickLabelsVisible(false); yAxis.setTickMarksVisible(false); yAxis.setAxisLineVisible(false); yAxis.setNegativeArrowVisible(false); yAxis.setPositiveArrowVisible(false); yAxis.setAutoRangeIncludesZero(true); yAxis.setAutoRange(true); yAxis.setVisible(false); BarRenderer renderer = new BarRenderer() { @Override public Paint getItemPaint(final int row, final int column) { return negate[column] ? Color.RED : Color.BLACK; } }; renderer.setShadowVisible(false); renderer.setBarPainter(new StandardBarPainter()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setInsets(INSETS); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(CLEAR); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBorderVisible(false); chart.setBackgroundPaint(CLEAR); Icon icon = EMPTY_ICON; try { byte[] image = ENCODER .encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null)); icon = new ImageIcon(image); } catch (IOException ex) { Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex); } return icon; }
From source file:presentation.webgui.vitroappservlet.StyleCreator.java
private static JFreeChart createChart(CategoryDataset dataset, Vector<String> givCategColors, Model3dStylesEntry givStyleEntry) { String capSimpleName = givStyleEntry.getCorrCapability(); capSimpleName = capSimpleName.replaceAll(Capability.dcaPrefix, ""); JFreeChart chart = ChartFactory.createBarChart("Style Legend for " + capSimpleName, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, false, // include legend true, false);/*from w ww. java2s . com*/ chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 14)); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // seen CategoryPlot plot = chart.getCategoryPlot(); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); //new plot.setNoDataMessage("NO DATA!"); Paint[] tmpPaintCategories = { Color.white }; if (givCategColors.size() > 0) { tmpPaintCategories = new Paint[givCategColors.size()]; for (int i = 0; i < givCategColors.size(); i++) { tmpPaintCategories[i] = Color.decode(givCategColors.elementAt(i)); } } CategoryItemRenderer renderer = new CustomRenderer(tmpPaintCategories); renderer.setSeriesPaint(0, new Color(255, 204, 51)); //new plot.setRenderer(renderer); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); //new plot.setForegroundAlpha(1f); //new plot.setBackgroundAlpha(1f); //new plot.setInsets(new RectangleInsets(5, 0, 5, 0)); //new was 5,0,5,0 plot.setRangeGridlinesVisible(false); //new was true plot.setBackgroundPaint(Color.white);//new: was (Color.lightGray); plot.setOutlinePaint(Color.white); //plot.setOrientation(PlotOrientation.HORIZONTAL); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.04); domainAxis.setUpperMargin(0.04); domainAxis.setVisible(true); domainAxis.setLabelAngle(Math.PI / 2); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(0.0, 100.0); // new: was 100 rangeAxis.setVisible(false); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.dialcharts.BulletGraph.java
public JFreeChart createChart() { logger.debug("IN"); Number value = null;//from www . j a va 2 s . co m if (dataset == null) { logger.debug("The dataset to be represented is null"); value = new Double(0); } else { value = dataset.getValue(); } DefaultCategoryDataset datasetC = new DefaultCategoryDataset(); datasetC.addValue(value, "", ""); // customize a bar chart JFreeChart chart = ChartFactory.createBarChart(null, null, null, datasetC, PlotOrientation.HORIZONTAL, false, false, false); chart.setBorderVisible(false); CategoryPlot plot = chart.getCategoryPlot(); plot.setOutlineVisible(true); plot.setOutlinePaint(Color.BLACK); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(null); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setAnchorValue(value.doubleValue()); // add the target marker if (target != null) { ValueMarker marker = new ValueMarker(target.doubleValue(), Color.BLACK, new BasicStroke(2.0f)); plot.addRangeMarker(marker, Layer.FOREGROUND); } //sets different marks for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); // add the marks IntervalMarker marker = new IntervalMarker(interval.getMin(), interval.getMax(), interval.getColor()); plot.addRangeMarker(marker, Layer.BACKGROUND); logger.debug("Added new interval to the plot"); } // customize axes CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(show_axis); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 4)); // calculate the upper limit //double upperBound = target * upperFactor; rangeAxis.setRange(new Range(lower, upper)); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // customize renderer BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setMaximumBarWidth(0.18); renderer.setSeriesPaint(0, Color.BLACK); /*BasicStroke d = new BasicStroke(3f,BasicStroke.CAP_ROUND ,BasicStroke.JOIN_ROUND); renderer.setSeriesOutlineStroke(0, d); renderer.setSeriesStroke(0, d); renderer.setStroke(d);*/ return chart; }
From source file:com.swordlord.gozer.components.fop.graph.GFopStackedBarChart.java
public GFopStackedBarChart(IGozerFrameExtension gfe, GStackedBarChart chart) { super(gfe);/*from w ww.j a v a 2 s . c om*/ DataBindingMember dbMemberRowKey = chart.getDataBindingMemberRowKey(); DataBindingMember dbMemberColKey = chart.getDataBindingMemberColKey(); DataBindingMember dbMemberValue = chart.getDataBindingMemberValue(); DataBindingManager dbManager = chart.getDataBindingManager(); DefaultCategoryDataset dcd = new DefaultCategoryDataset(); List<DataRowBase> rowTests = dbManager.getRows(dbMemberValue); for (int j = 0; j < rowTests.size(); j++) { DataRowBase row = rowTests.get(j); String strKey = row.getPropertyAsStringForce(dbMemberRowKey.getRelativePathWithField()); dcd.setValue(row.getPropertyAsInt(dbMemberValue.getRelativePathWithField()), strKey, row.getPropertyAsStringForce(dbMemberColKey.getRelativePathWithField())); } JFreeChart fc = ChartFactory.createStackedBarChart(chart.getTitle(), chart.getCategoryAxisLabel(), chart.getValueAxisLabel(), dcd, chart.getOrientation(), chart.getLegend(), false, false); // Do this in a more static way! StackedBarRenderer.setDefaultBarPainter(new StandardBarPainter()); //chart.setBackgroundPaint(Color.white); if (chart.getSubTitle() != null) { fc.addSubtitle(new TextTitle(chart.getSubTitle())); } CategoryPlot plot = fc.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDrawingSupplier(chart.getDrawingSupplier()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(chart.getCategoryAxisVisible()); ValueAxis valueAxis = plot.getRangeAxis(); valueAxis.setVisible(chart.getValueAxisVisible()); /* //CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer(); for (int j = 0; j < rowKey.length; j++) { renderer.setSeriesItemLabelGenerator(j, new LabelGenerator(j, rowKey[j])); renderer.setSeriesItemLabelsVisible(j, true); } */ StackedBarRenderer renderer = new StackedBarRenderer(); for (int j = 0; j < dcd.getRowCount(); j++) { renderer.setSeriesItemLabelGenerator(j, new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelsVisible(j, true); } //renderer.setLegendItemLabelGenerator(new LabelGenerator()); renderer.setShadowVisible(false); plot.setRenderer(renderer); _image = new ChartImage("chart", fc, chart.getWidth(800), chart.getHeight(800)); }
From source file:j2se.jfreechart.barchart.BarChartDemo6.java
/** * Creates a new demo./* w w w . j a v a 2 s.c om*/ * * @param title the frame title. */ public BarChartDemo6(final String title) { super(title); // create a dataset... final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(83.0, "First", "Factor 1"); // create the chart... final JFreeChart chart = ChartFactory.createBarChart(null, // chart title "Category", // domain axis label "Score (%)", // range axis label dataset, // data PlotOrientation.HORIZONTAL, false, // include legend true, false); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.yellow); // not seen final CategoryPlot plot = chart.getCategoryPlot(); // plot.setInsets(new Insets(0, 0, 0, 0)); plot.setRangeGridlinesVisible(false); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.20); domainAxis.setUpperMargin(0.20); domainAxis.setVisible(false); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(0.0, 100.0); rangeAxis.setVisible(false); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.BulletGraph.java
public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); Dataset dataset = (Dataset) datasets.getDatasets().get("1"); ValueDataset valDataSet = (ValueDataset) dataset; Number value = valDataSet.getValue(); DefaultCategoryDataset datasetC = new DefaultCategoryDataset(); datasetC.addValue(value, "", ""); // customize a bar chart JFreeChart chart = ChartFactory.createBarChart(null, null, null, datasetC, PlotOrientation.HORIZONTAL, false, false, false);/*from ww w.j a v a2 s . c o m*/ chart.setBorderVisible(false); chart.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setOutlineVisible(true); plot.setOutlinePaint(Color.BLACK); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(null); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setAnchorValue(value.doubleValue()); // add the target marker if (target != null) { ValueMarker marker = new ValueMarker(target.doubleValue(), Color.BLACK, new BasicStroke(2.0f)); plot.addRangeMarker(marker, Layer.FOREGROUND); } //sets different marks for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); // add the marks IntervalMarker marker = new IntervalMarker(interval.getMin(), interval.getMax(), interval.getColor()); plot.addRangeMarker(marker, Layer.BACKGROUND); logger.debug("Added new interval to the plot"); } // customize axes CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(true); // calculate the upper limit //double upperBound = target * upperFactor; rangeAxis.setRange(new Range(lower, upper)); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // customize renderer BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setMaximumBarWidth(0.18); renderer.setSeriesPaint(0, Color.BLACK); return chart; }
From source file:com.swordlord.gozer.components.wicket.graph.GWStackedBarChartPanel.java
public GWStackedBarChartPanel(String id, IModel<?> model, GStackedBarChart child) { super(id, model); gchart = child;/* w ww .jav a2 s. c o m*/ DataBindingMember dbMemberRowKey = child.getDataBindingMemberRowKey(); DataBindingMember dbMemberTargetId = child.getDataBindingMemberTargetId(); DataBindingMember dbMemberColKey = child.getDataBindingMemberColKey(); DataBindingMember dbMemberValue = child.getDataBindingMemberValue(); DataBindingManager dbManager = child.getDataBindingManager(); DefaultCategoryDataset dcd = new DefaultCategoryDataset(); List<DataRowBase> rows = dbManager.getRows(dbMemberValue); // if the graph has some ordering info in the format of "<field> ASCENDING,<field2> DESCENDING" if (child.hasOrdering()) { List<Ordering> ordering = child.formatOrdering(child.getOrdering()); OrderingEx.orderList(rows, ordering); } for (int j = 0; j < rows.size(); j++) { DataRowBase row = rows.get(j); String strKey = row.getPropertyAsStringForce(dbMemberRowKey.getRelativePathWithField()); dcd.setValue(row.getPropertyAsInt(dbMemberValue.getRelativePathWithField()), strKey, row.getPropertyAsStringForce(dbMemberColKey.getRelativePathWithField())); if (dbMemberTargetId != null) { _target.put(strKey, row.getPropertyAsStringForce(dbMemberTargetId.getDataBindingFieldName())); } } JFreeChart chart = ChartFactory.createStackedBarChart(child.getTitle(), child.getCategoryAxisLabel(), child.getValueAxisLabel(), dcd, child.getOrientation(), child.getLegend(), false, false); // Do this in a more static way! StackedBarRenderer.setDefaultBarPainter(new StandardBarPainter()); //chart.setBackgroundPaint(Color.white); if (child.getSubTitle() != null) { chart.addSubtitle(new TextTitle(child.getSubTitle())); } CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDrawingSupplier(child.getDrawingSupplier()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(child.getCategoryAxisVisible()); ValueAxis valueAxis = plot.getRangeAxis(); valueAxis.setVisible(child.getValueAxisVisible()); /* //CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer(); for (int j = 0; j < rowKey.length; j++) { renderer.setSeriesItemLabelGenerator(j, new LabelGenerator(j, rowKey[j])); renderer.setSeriesItemLabelsVisible(j, true); } */ StackedBarRenderer renderer = new StackedBarRenderer(); for (int j = 0; j < dcd.getRowCount(); j++) { renderer.setSeriesItemLabelGenerator(j, new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelsVisible(j, true); } //renderer.setLegendItemLabelGenerator(new LabelGenerator()); renderer.setShadowVisible(false); plot.setRenderer(renderer); ChartImage image = new ChartImage("chart", chart, child.getWidth(800), child.getHeight(800)); String mapName = child.getCaption(); add(image); DynamicImageMap imageMap = constructImageMap(image, mapName); if (!child.isClickable()) { imageMap.setVisible(false); } else { image.add(new AttributeModifier("usemap", new Model<String>("#" + mapName))); } add(imageMap); }