List of usage examples for org.jfree.chart.axis Axis setTickMarkPaint
public void setTickMarkPaint(Paint paint)
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
protected void setAxisTickMarks(Axis axis, Paint lineColor) { Boolean defaultAxisTickMarksVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_MARKS_VISIBLE); if (defaultAxisTickMarksVisible != null && defaultAxisTickMarksVisible) { Float defaultAxisTickMarksInsideLength = (Float) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_MARKS_INSIDE_LENGTH); if (defaultAxisTickMarksInsideLength != null) axis.setTickMarkInsideLength(defaultAxisTickMarksInsideLength); Float defaultAxisTickMarksOutsideLength = (Float) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_MARKS_OUTSIDE_LENGTH); if (defaultAxisTickMarksOutsideLength != null) axis.setTickMarkInsideLength(defaultAxisTickMarksOutsideLength); Paint tickMarkPaint = getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_MARKS_PAINT) != null ? (Paint) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_MARKS_PAINT) : lineColor;/*from w w w . j ava2 s.c om*/ if (tickMarkPaint != null) { axis.setTickMarkPaint(tickMarkPaint); } Stroke defaultTickMarkStroke = (Stroke) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_MARKS_STROKE); if (defaultTickMarkStroke != null) axis.setTickMarkStroke(defaultTickMarkStroke); } }
From source file:org.orbeon.oxf.processor.serializer.legacy.JFreeChartSerializer.java
protected JFreeChart drawChart(ChartConfig chartConfig, final Dataset ds) { JFreeChart chart = null;//from ww w .j a v a 2 s . co m Axis categoryAxis = null; if (ds instanceof XYSeriesCollection) { categoryAxis = new RestrictedNumberAxis(chartConfig.getCategoryTitle()); } else if (ds instanceof TimeSeriesCollection) { categoryAxis = new DateAxis(chartConfig.getCategoryTitle()); ((DateAxis) categoryAxis).setDateFormatOverride(new SimpleDateFormat(chartConfig.getDateFormat())); if (chartConfig.getCategoryLabelAngle() == 90) { ((DateAxis) categoryAxis).setVerticalTickLabels(true); } else { if (chartConfig.getCategoryLabelAngle() != 0) throw new OXFException( "The only supported values of category-label-angle for time-series charts are 0 or 90"); } } else { categoryAxis = new CategoryAxis(chartConfig.getCategoryTitle()); ((CategoryAxis) categoryAxis).setCategoryLabelPositions(chartConfig.getCategoryLabelPosition()); } NumberAxis valueAxis = new RestrictedNumberAxis(chartConfig.getSerieTitle()); valueAxis.setAutoRangeIncludesZero(chartConfig.getSerieAutoRangeIncludeZero()); AbstractRenderer renderer = null; Plot plot = null; switch (chartConfig.getType()) { case ChartConfig.VERTICAL_BAR_TYPE: case ChartConfig.HORIZONTAL_BAR_TYPE: renderer = (ds instanceof ItemPaintCategoryDataset) ? new BarRenderer() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new BarRenderer(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); if (chartConfig.getType() == ChartConfig.VERTICAL_BAR_TYPE) ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); else ((CategoryPlot) plot).setOrientation(PlotOrientation.HORIZONTAL); break; case ChartConfig.STACKED_VERTICAL_BAR_TYPE: case ChartConfig.STACKED_HORIZONTAL_BAR_TYPE: renderer = (ds instanceof ItemPaintCategoryDataset) ? new StackedBarRenderer() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new StackedBarRenderer(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); if (chartConfig.getType() == ChartConfig.STACKED_VERTICAL_BAR_TYPE) ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); else ((CategoryPlot) plot).setOrientation(PlotOrientation.HORIZONTAL); break; case ChartConfig.LINE_TYPE: renderer = (ds instanceof ItemPaintCategoryDataset) ? new LineAndShapeRenderer(true, false) { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : (new LineAndShapeRenderer(true, false)); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); break; case ChartConfig.AREA_TYPE: renderer = (ds instanceof ItemPaintCategoryDataset) ? new AreaRenderer() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new AreaRenderer(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); break; case ChartConfig.VERTICAL_BAR3D_TYPE: case ChartConfig.HORIZONTAL_BAR3D_TYPE: categoryAxis = new CategoryAxis3D(chartConfig.getCategoryTitle()); valueAxis = new NumberAxis3D(chartConfig.getSerieTitle()); renderer = (ds instanceof ItemPaintCategoryDataset) ? new BarRenderer3D() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new BarRenderer3D(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); if (chartConfig.getType() == ChartConfig.VERTICAL_BAR3D_TYPE) ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); else ((CategoryPlot) plot).setOrientation(PlotOrientation.HORIZONTAL); break; case ChartConfig.STACKED_VERTICAL_BAR3D_TYPE: case ChartConfig.STACKED_HORIZONTAL_BAR3D_TYPE: categoryAxis = new CategoryAxis3D(chartConfig.getCategoryTitle()); valueAxis = new NumberAxis3D(chartConfig.getSerieTitle()); renderer = (ds instanceof ItemPaintCategoryDataset) ? new StackedBarRenderer3D() { public Paint getItemPaint(int row, int column) { Paint p = ((ItemPaintCategoryDataset) ds).getItemPaint(row, column); if (p != null) return p; else return getSeriesPaint(row); } } : new StackedBarRenderer3D(); plot = new CategoryPlot((CategoryDataset) ds, (CategoryAxis) categoryAxis, (ValueAxis) valueAxis, (CategoryItemRenderer) renderer); if (chartConfig.getType() == ChartConfig.STACKED_VERTICAL_BAR3D_TYPE) ((CategoryPlot) plot).setOrientation(PlotOrientation.VERTICAL); else ((CategoryPlot) plot).setOrientation(PlotOrientation.HORIZONTAL); break; case ChartConfig.PIE_TYPE: case ChartConfig.PIE3D_TYPE: categoryAxis = null; valueAxis = null; renderer = null; ExtendedPieDataset pds = (ExtendedPieDataset) ds; plot = chartConfig.getType() == ChartConfig.PIE_TYPE ? new PiePlot(pds) : new PiePlot3D(pds); PiePlot pp = (PiePlot) plot; pp.setLabelGenerator(new StandardPieSectionLabelGenerator()); for (int i = 0; i < pds.getItemCount(); i++) { Paint p = pds.getPaint(i); if (p != null) pp.setSectionPaint(i, p); pp.setExplodePercent(i, pds.getExplodePercent(i)); Paint paint = pds.getPaint(i); if (paint != null) pp.setSectionPaint(i, paint); } break; case ChartConfig.XY_LINE_TYPE: renderer = new XYLineAndShapeRenderer(true, false); plot = new XYPlot((XYDataset) ds, (ValueAxis) categoryAxis, (ValueAxis) valueAxis, (XYLineAndShapeRenderer) renderer); break; case ChartConfig.TIME_SERIES_TYPE: renderer = new XYLineAndShapeRenderer(true, false); plot = new XYPlot((XYDataset) ds, (DateAxis) categoryAxis, (ValueAxis) valueAxis, (XYLineAndShapeRenderer) renderer); break; default: throw new OXFException("Chart Type not supported"); } if (categoryAxis != null) { categoryAxis.setLabelPaint(chartConfig.getTitleColor()); categoryAxis.setTickLabelPaint(chartConfig.getTitleColor()); categoryAxis.setTickMarkPaint(chartConfig.getTitleColor()); if (categoryAxis instanceof RestrictedNumberAxis) { ((RestrictedNumberAxis) categoryAxis).setMaxTicks(chartConfig.getMaxNumOfLabels()); } if (categoryAxis instanceof CategoryAxis && chartConfig.getCategoryMargin() != 0) ((CategoryAxis) categoryAxis).setCategoryMargin(chartConfig.getCategoryMargin()); } if (valueAxis != null) { valueAxis.setLabelPaint(chartConfig.getTitleColor()); valueAxis.setTickLabelPaint(chartConfig.getTitleColor()); valueAxis.setTickMarkPaint(chartConfig.getTitleColor()); ((RestrictedNumberAxis) valueAxis).setMaxTicks(chartConfig.getMaxNumOfLabels()); } if (renderer != null) { if (renderer instanceof XYLineAndShapeRenderer) { ((XYLineAndShapeRenderer) renderer).setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); } else { ((CategoryItemRenderer) renderer) .setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } if (renderer instanceof BarRenderer) ((BarRenderer) renderer).setItemMargin(chartConfig.getBarMargin()); int j = 0; for (Iterator i = chartConfig.getValueIterator(); i.hasNext();) { Value v = (Value) i.next(); renderer.setSeriesPaint(j, v.getColor()); j++; } } plot.setOutlinePaint(chartConfig.getTitleColor()); CustomLegend legend = chartConfig.getLegendConfig(); chart = new JFreeChart(chartConfig.getTitle(), TextTitle.DEFAULT_FONT, plot, false); if (legend.isVisible()) { legend.setSources(new LegendItemSource[] { plot }); chart.addLegend(legend); } chart.setBackgroundPaint(chartConfig.getBackgroundColor()); TextTitle textTitle = new TextTitle(chartConfig.getTitle(), TextTitle.DEFAULT_FONT, chartConfig.getTitleColor(), TextTitle.DEFAULT_POSITION, TextTitle.DEFAULT_HORIZONTAL_ALIGNMENT, TextTitle.DEFAULT_VERTICAL_ALIGNMENT, TextTitle.DEFAULT_PADDING); chart.setTitle(textTitle); return chart; }