List of usage examples for org.jfree.chart.axis CategoryAxis setCategoryLabelPositions
public void setCategoryLabelPositions(CategoryLabelPositions positions)
From source file:com.rapidminer.gui.plotter.charts.ParetoChartPlotter.java
private JFreeChart createChart() { if (data.getItemCount() > 0) { // get cumulative percentages KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset( "Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart(null, // chart title this.dataTable.getColumnName(this.groupByColumn), // domain axis label "Count", // range axis label categoryDataset, // data PlotOrientation.VERTICAL, true, // include legend true, false);//from ww w .j a va2 s . c o m // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); // get a reference to the plot for further customization... CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); // second data set (cumulative percentages) CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker()); NumberAxis axis2 = new NumberAxis("Percent of " + countValue); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis2.setLabelFont(LABEL_FONT_BOLD); axis2.setTickLabelFont(LABEL_FONT); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); axis2.setTickUnit(new NumberTickUnit(0.1)); // show grid lines plot.setRangeGridlinesVisible(true); // bring cumulative line to front plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); if (isLabelRotating()) { domainAxis.setTickLabelsVisible(true); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } return chart; } else { return null; } }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * *//*from w w w. ja v a 2 s . c om*/ protected void configurePlot(Plot plot) { plot.setOutlinePaint(null); if (getPlot().getOwnBackcolor() == null)// in a way, plot backcolor inheritence from chart is useless { plot.setBackgroundPaint(null); } else { plot.setBackgroundPaint(getPlot().getBackcolor()); } float backgroundAlpha = getPlot().getBackgroundAlphaFloat() == null ? 1f : getPlot().getBackgroundAlphaFloat(); float foregroundAlpha = getPlot().getForegroundAlphaFloat() == null ? 1f : getPlot().getForegroundAlphaFloat(); plot.setBackgroundAlpha(backgroundAlpha); plot.setForegroundAlpha(foregroundAlpha); if (plot instanceof CategoryPlot) { // Handle rotation of the category labels. CategoryAxis axis = ((CategoryPlot) plot).getDomainAxis(); // it's OK to use deprecated method here; avoiding it means attempting cast operations double labelRotation = getLabelRotation(); if (labelRotation == 90) { axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); } else if (labelRotation == -90) { axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); } else if (labelRotation < 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions((-labelRotation / 180.0) * Math.PI)); } else if (labelRotation > 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createDownRotationLabelPositions((labelRotation / 180.0) * Math.PI)); } } // Set any color series SortedSet<JRSeriesColor> seriesColors = getPlot().getSeriesColors(); if (seriesColors != null && seriesColors.size() > 0) { if (seriesColors.size() == 1) { // Add the single color to the beginning of the color cycle, using all the default // colors. To replace the defaults you have to specify at least two colors. Paint[] colors = new Paint[DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length + 1]; colors[0] = seriesColors.first().getColor(); System.arraycopy(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE, 0, colors, 1, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length); plot.setDrawingSupplier( new DefaultDrawingSupplier(colors, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); } else if (seriesColors.size() > 1) { // Set up a custom drawing supplier that cycles through the user's colors // instead of the default colors. Color[] colors = new Color[seriesColors.size()]; JRSeriesColor[] colorSequence = new JRSeriesColor[seriesColors.size()]; seriesColors.toArray(colorSequence); for (int i = 0; i < colorSequence.length; i++) { colors[i] = colorSequence[i].getColor(); } plot.setDrawingSupplier( new DefaultDrawingSupplier(colors, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); } } }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java
private JFreeChart createCategoryBarChart(String title, String xLabel, String yLabel, CategoryDataset dataset) { // System.out.println("layout = "+layout); JFreeChart chart;//from w w w .j a v a 2s. co m if (dimension.equalsIgnoreCase("3d")) { chart = ChartFactory.createBarChart3D(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data orientation, // orientation true, // include legend true, // tooltips false // urls ); CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinesVisible(true); CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)); BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer(); //renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); renderer.setDrawBarOutline(false); return chart; } if (layout.equalsIgnoreCase("stacked")) { chart = ChartFactory.createStackedBarChart(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data orientation, // the plot orientation true, // legend true, // tooltips false // urls ); } else if (layout.equalsIgnoreCase("waterfall")) { chart = ChartFactory.createWaterfallChart(title, xLabel, yLabel, dataset, orientation, true, true, false); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); DecimalFormat labelFormatter = new DecimalFormat("$##,###.00"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", labelFormatter)); renderer.setBaseItemLabelsVisible(true); } else { chart = ChartFactory.createBarChart(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data orientation, // orientation true, // include legend true, // tooltips? false // URLs? ); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... if (layout.equalsIgnoreCase("stacked")) { StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator()); } else if (layout.equalsIgnoreCase("layered")) { LayeredBarRenderer renderer = new LayeredBarRenderer(); renderer.setDrawBarOutline(false); plot.setRenderer(renderer); plot.setRowRenderingOrder(SortOrder.DESCENDING); } else { BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); } /* CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) );*/ // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
protected void handleCategoryPlotSettings(CategoryPlot p, JRChartPlot jrPlot) { Double defaultPlotLabelRotation = (Double) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_LABEL_ROTATION); PlotOrientation defaultPlotOrientation = (PlotOrientation) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_ORIENTATION); // Handle rotation of the category labels. CategoryAxis axis = p.getDomainAxis(); boolean hasRotation = jrPlot.getLabelRotationDouble() != null || defaultPlotLabelRotation != null; if (hasRotation) { double labelRotation = jrPlot.getLabelRotationDouble() != null ? jrPlot.getLabelRotationDouble().doubleValue() : defaultPlotLabelRotation.doubleValue(); if (labelRotation == 90) { axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); } else if (labelRotation == -90) { axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); } else if (labelRotation < 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions((-labelRotation / 180.0) * Math.PI)); } else if (labelRotation > 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createDownRotationLabelPositions((labelRotation / 180.0) * Math.PI)); }//from w w w .j av a 2 s. co m } if (defaultPlotOrientation != null) { p.setOrientation(defaultPlotOrientation); } }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
protected void handleCategoryPlotSettings(CategoryPlot p, JRChartPlot jrPlot) { PlotSettings plotSettings = getPlotSettings(); Double themeLabelRotation = plotSettings.getLabelRotation(); // Handle rotation of the category labels. CategoryAxis axis = p.getDomainAxis(); boolean hasRotation = jrPlot.getLabelRotationDouble() != null || themeLabelRotation != null; if (hasRotation) { double labelRotation = jrPlot.getLabelRotationDouble() != null ? jrPlot.getLabelRotationDouble().doubleValue() : themeLabelRotation.doubleValue(); if (labelRotation == 90) { axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); } else if (labelRotation == -90) { axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); } else if (labelRotation < 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions((-labelRotation / 180.0) * Math.PI)); } else if (labelRotation > 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createDownRotationLabelPositions((labelRotation / 180.0) * Math.PI)); }//from ww w . j ava 2 s .c o m } PlotOrientation plotOrientation = jrPlot.getOrientation() != null ? jrPlot.getOrientation() : plotSettings.getOrientation(); if (plotOrientation != null) { p.setOrientation(plotOrientation); } CategoryItemRenderer categoryRenderer = p.getRenderer(); Paint[] paintSequence = getPaintSequence(plotSettings, jrPlot); if (paintSequence != null) { for (int i = 0; i < paintSequence.length; i++) { categoryRenderer.setSeriesPaint(i, paintSequence[i]); } } Paint[] outlinePaintSequence = getOutlinePaintSequence(plotSettings); if (outlinePaintSequence != null) { for (int i = 0; i < outlinePaintSequence.length; i++) { categoryRenderer.setSeriesOutlinePaint(i, outlinePaintSequence[i]); } } Stroke[] strokeSequence = getStrokeSequence(plotSettings); if (strokeSequence != null) { for (int i = 0; i < strokeSequence.length; i++) { categoryRenderer.setSeriesStroke(i, strokeSequence[i]); } } Stroke[] outlineStrokeSequence = getOutlineStrokeSequence(plotSettings); if (outlineStrokeSequence != null) { for (int i = 0; i < outlineStrokeSequence.length; i++) { categoryRenderer.setSeriesOutlineStroke(i, outlineStrokeSequence[i]); } } Boolean domainGridlineVisible = plotSettings.getDomainGridlineVisible(); if (domainGridlineVisible == null || domainGridlineVisible.booleanValue()) { PaintProvider domainGridlinePaint = plotSettings.getDomainGridlinePaint(); if (domainGridlinePaint != null) { p.setDomainGridlinePaint(domainGridlinePaint.getPaint()); } Stroke domainGridlineStroke = plotSettings.getDomainGridlineStroke(); if (domainGridlineStroke != null) { p.setDomainGridlineStroke(domainGridlineStroke); } } Boolean rangeGridlineVisible = plotSettings.getRangeGridlineVisible(); if (rangeGridlineVisible == null || rangeGridlineVisible.booleanValue()) { PaintProvider rangeGridlinePaint = plotSettings.getRangeGridlinePaint(); if (rangeGridlinePaint != null) { p.setRangeGridlinePaint(rangeGridlinePaint.getPaint()); } Stroke rangeGridlineStroke = plotSettings.getRangeGridlineStroke(); if (rangeGridlineStroke != null) { p.setRangeGridlineStroke(rangeGridlineStroke); } } }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
protected void handleCategoryPlotSettings(CategoryPlot p, JRChartPlot jrPlot) { Double defaultPlotLabelRotation = (Double) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_LABEL_ROTATION); PlotOrientation defaultPlotOrientation = (PlotOrientation) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_ORIENTATION); // Handle rotation of the category labels. CategoryAxis axis = p.getDomainAxis(); boolean hasRotation = jrPlot.getLabelRotationDouble() != null || defaultPlotLabelRotation != null; if (hasRotation) { double labelRotation = jrPlot.getLabelRotationDouble() != null ? jrPlot.getLabelRotationDouble() : defaultPlotLabelRotation; if (labelRotation == 90) { axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); } else if (labelRotation == -90) { axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); } else if (labelRotation < 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions((-labelRotation / 180.0) * Math.PI)); } else if (labelRotation > 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createDownRotationLabelPositions((labelRotation / 180.0) * Math.PI)); }//from w w w . j a va 2 s . c o m } if (defaultPlotOrientation != null) { p.setOrientation(defaultPlotOrientation); } }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
protected void handleCategoryPlotSettings(CategoryPlot p, JRChartPlot jrPlot) { PlotSettings plotSettings = getPlotSettings(); Double themeLabelRotation = plotSettings.getLabelRotation(); // Handle rotation of the category labels. CategoryAxis axis = p.getDomainAxis(); boolean hasRotation = jrPlot.getLabelRotationDouble() != null || themeLabelRotation != null; if (hasRotation) { double labelRotation = jrPlot.getLabelRotationDouble() != null ? jrPlot.getLabelRotationDouble() : themeLabelRotation;/*from w w w . j a v a2 s. co m*/ if (labelRotation == 90) { axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); } else if (labelRotation == -90) { axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); } else if (labelRotation < 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions((-labelRotation / 180.0) * Math.PI)); } else if (labelRotation > 0) { axis.setCategoryLabelPositions( CategoryLabelPositions.createDownRotationLabelPositions((labelRotation / 180.0) * Math.PI)); } } PlotOrientation plotOrientation = jrPlot.getOrientationValue() != null ? jrPlot.getOrientationValue().getOrientation() : plotSettings.getOrientation(); if (plotOrientation != null) { p.setOrientation(plotOrientation); } CategoryItemRenderer categoryRenderer = p.getRenderer(); Paint[] paintSequence = getPaintSequence(plotSettings, jrPlot); if (paintSequence != null) { for (int i = 0; i < paintSequence.length; i++) { categoryRenderer.setSeriesPaint(i, paintSequence[i]); } } Paint[] outlinePaintSequence = getOutlinePaintSequence(plotSettings); if (outlinePaintSequence != null) { for (int i = 0; i < outlinePaintSequence.length; i++) { categoryRenderer.setSeriesOutlinePaint(i, outlinePaintSequence[i]); } } Stroke[] strokeSequence = getStrokeSequence(plotSettings); if (strokeSequence != null) { for (int i = 0; i < strokeSequence.length; i++) { categoryRenderer.setSeriesStroke(i, strokeSequence[i]); } } Stroke[] outlineStrokeSequence = getOutlineStrokeSequence(plotSettings); if (outlineStrokeSequence != null) { for (int i = 0; i < outlineStrokeSequence.length; i++) { categoryRenderer.setSeriesOutlineStroke(i, outlineStrokeSequence[i]); } } Boolean domainGridlineVisible = plotSettings.getDomainGridlineVisible(); if (domainGridlineVisible == null || domainGridlineVisible) { PaintProvider domainGridlinePaint = plotSettings.getDomainGridlinePaint(); if (domainGridlinePaint != null) { p.setDomainGridlinePaint(domainGridlinePaint.getPaint()); } Stroke domainGridlineStroke = plotSettings.getDomainGridlineStroke(); if (domainGridlineStroke != null) { p.setDomainGridlineStroke(domainGridlineStroke); } } Boolean rangeGridlineVisible = plotSettings.getRangeGridlineVisible(); if (rangeGridlineVisible == null || rangeGridlineVisible) { PaintProvider rangeGridlinePaint = plotSettings.getRangeGridlinePaint(); if (rangeGridlinePaint != null) { p.setRangeGridlinePaint(rangeGridlinePaint.getPaint()); } Stroke rangeGridlineStroke = plotSettings.getRangeGridlineStroke(); if (rangeGridlineStroke != null) { p.setRangeGridlineStroke(rangeGridlineStroke); } } }
From source file:Output.SplitChart.java
public void drawGridLinesData(int[] selectIndex) { DefaultCategoryDataset dataset3D = new DefaultCategoryDataset(); Object[][] branchData = this.amesFrame.getBranchData(); int iBranchNumber = branchData.length; if ((selectIndex.length < 1) || (selectIndex[0] == 0)) { for (int i = 0; i < iBranchNumber; i++) { String branchName = (String) branchData[i][0]; dataset3D.addValue((Math.round(Support.parseDouble(branchData[i][3].toString()) * 1000)) / 1000.0, "Capacities (MWs)", branchName); }//from w w w . j a va 2 s . co m } else { int iDataNumber = selectIndex.length; for (int i = 0; i < iDataNumber; i++) { String branchName = (String) branchData[selectIndex[i] - 1][0]; dataset3D.addValue( (Math.round(Support.parseDouble(branchData[selectIndex[i] - 1][3].toString()) * 1000)) / 1000.0, "Capacities (MWs)", branchName); } } this.chart = ChartFactory.createBarChart3D("Branch Max Capacities", // chart title "", // domain axis label "Capacities (MWs)", // range axis label dataset3D, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = this.chart.getCategoryPlot(); final CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelsVisible(true); final BarRenderer r = (BarRenderer) renderer; r.setMaximumBarWidth(0.05); this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.chart); }