List of usage examples for org.jfree.chart.axis ValueAxis setLabelAngle
public void setLabelAngle(double angle)
From source file:org.jfree.chart.demo.CategoryStepChartDemo.java
/** * Creates a chart./*from ww w .ja v a2 s . c om*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final CategoryItemRenderer renderer = new CategoryStepRenderer(true); final CategoryAxis domainAxis = new CategoryAxis("Category"); final ValueAxis rangeAxis = new NumberAxis("Value"); final CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); final JFreeChart chart = new JFreeChart("Category Step Chart", plot); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setAnchor(StandardLegend.SOUTH); chart.setBackgroundPaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private JFreeChart createBubbleChart() throws QueryException { bubbleDataset = new DefaultXYZDataset(); // x, y are inverted for jfree bubble chart! // that's why we use minX & maxX values to compute Tu (tickUnit) String chartTitle = replaceParameters(chart.getTitle().getTitle()); chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language)); String xLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); String yLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); JFreeChart jfreechart = ChartFactory.createBubbleChart(chartTitle, xLegend, // x-axis Label yLegend, // y-axis Label bubbleDataset, PlotOrientation.HORIZONTAL, true, true, false); // hide border jfreechart.setBorderVisible(false);/*w w w. j a va2 s . co m*/ // title setTitle(jfreechart); boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart(); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setForegroundAlpha(transparency); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); DecimalFormat decimalformat; DecimalFormat percentageFormat; if (chart.getYTooltipPattern() == null) { decimalformat = new DecimalFormat("#"); percentageFormat = new DecimalFormat("0.00%"); } else { decimalformat = new DecimalFormat(chart.getYTooltipPattern()); percentageFormat = decimalformat; } if (showValues) { // increase a little bit the range axis to view all item label values over bars xyplot.getRangeAxis().setUpperMargin(0.2); } // grid axis visibility & colors if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) { xyplot.setDomainGridlinesVisible(false); } else { if (chart.getXGridColor() != null) { xyplot.setDomainGridlinePaint(chart.getXGridColor()); } else { xyplot.setDomainGridlinePaint(Color.BLACK); } } if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) { xyplot.setRangeGridlinesVisible(false); } else { if (chart.getYGridColor() != null) { xyplot.setRangeGridlinePaint(chart.getYGridColor()); } else { xyplot.setRangeGridlinePaint(Color.BLACK); } } // chart background xyplot.setBackgroundPaint(chart.getBackground()); // labels color xyplot.getDomainAxis().setTickLabelPaint(chart.getXColor()); xyplot.getRangeAxis().setTickLabelPaint(chart.getYColor()); // legend color xyplot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor()); xyplot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor()); // legend font xyplot.getDomainAxis().setLabelFont(chart.getXLegend().getFont()); xyplot.getRangeAxis().setLabelFont(chart.getYLegend().getFont()); // axis color xyplot.getDomainAxis().setAxisLinePaint(chart.getxAxisColor()); xyplot.getRangeAxis().setAxisLinePaint(chart.getyAxisColor()); // hide labels if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) { xyplot.getDomainAxis().setTickLabelsVisible(false); xyplot.getDomainAxis().setTickMarksVisible(false); } if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) { xyplot.getRangeAxis().setTickLabelsVisible(false); xyplot.getRangeAxis().setTickMarksVisible(false); } // label orientation ValueAxis domainAxis = xyplot.getDomainAxis(); if (chart.getXorientation() == Chart.VERTICAL) { domainAxis.setLabelAngle(Math.PI / 2); } else if (chart.getXorientation() == Chart.DIAGONAL) { domainAxis.setLabelAngle(Math.PI / 4); } else if (chart.getXorientation() == Chart.HALF_DIAGONAL) { domainAxis.setLabelAngle(Math.PI / 8); } // labels fonts xyplot.getDomainAxis().setTickLabelFont(chart.getXLabelFont()); xyplot.getRangeAxis().setTickLabelFont(chart.getYLabelFont()); createChart(xyplot.getRangeAxis(), new Object[4]); double minX = Double.MAX_VALUE; double maxX = Double.MIN_VALUE; double minY = Double.MAX_VALUE; double maxY = Double.MIN_VALUE; double maxZ = Double.MIN_VALUE; for (String serie : bubbleData.keySet()) { XYZList xyzList = bubbleData.get(serie); List<Number> yList = xyzList.getyList(); for (Number n : yList) { minY = Math.min(minY, n.doubleValue()); maxY = Math.max(maxY, n.doubleValue()); } List<Number> xList = xyzList.getxList(); for (Number n : xList) { minX = Math.min(minX, n.doubleValue()); maxX = Math.max(maxX, n.doubleValue()); } List<Number> zList = xyzList.getzList(); for (Number n : zList) { maxZ = Math.max(maxZ, n.doubleValue()); } } double tu = Math.floor((maxX - minX) / 5 + 0.5d); NumberTickUnit rUnit = new NumberTickUnit(tu); ((NumberAxis) xyplot.getRangeAxis()).setTickUnit(rUnit); // make the bubble with text fit on X axis (which is shown vertically!) xyplot.getDomainAxis().setUpperMargin(0.2); xyplot.getDomainAxis().setLowerMargin(0.2); for (String serie : bubbleData.keySet()) { XYZList xyzList = bubbleData.get(serie); double[][] data = { getDoubleArray(xyzList.getyList()), getDoubleArray(xyzList.getxList()), getZDoubleArray(xyzList.getzList(), tu, maxZ) }; bubbleDataset.addSeries(serie, data); } int series = bubbleData.keySet().size(); for (int i = 0; i < series; i++) { xyitemrenderer.setSeriesPaint(i, chart.getForegrounds().get(i)); if (showValues) { xyitemrenderer.setSeriesItemLabelsVisible(i, true); xyitemrenderer.setSeriesItemLabelGenerator(i, new StandardXYItemLabelGenerator("{2}", decimalformat, percentageFormat)); } } // show labels on bubbles xyitemrenderer.setBaseItemLabelsVisible(true); xyitemrenderer.setBaseItemLabelGenerator(new LegendXYItemLabelGenerator()); return jfreechart; }