List of usage examples for org.jfree.chart.axis CategoryLabelPositions createUpRotationLabelPositions
public static CategoryLabelPositions createUpRotationLabelPositions(double angle)
From source file:ReportGen.java
private void yearlyPreview(String table) throws NumberFormatException { try {/*from w w w. j a v a 2s .c o m*/ exportcounttableexcel.setEnabled(true); exportcounttablepdf.setEnabled(true); // exportgraphtoimage.setEnabled(true); tableModel = (DefaultTableModel) dataTable.getModel(); tableModel.getDataVector().removeAllElements(); tableModel.fireTableDataChanged(); String str[] = { "Months", "Values" }; tableModel.setColumnIdentifiers(str); ChartPanel chartPanel; displaypane.removeAll(); displaypane.revalidate(); displaypane.repaint(); displaypane.setLayout(new BorderLayout()); //row String series1 = "Results"; //column, String years[] = { "2014", "2015", "2016", "2017", "2018", "2019", "2020" }; int value[] = new int[7]; int c = 0; switch (table) { case "Reservation": for (String year : years) { value[c] = client.getCountYearlyReportReservation(year); c++; } break; case "Registration": for (String year : years) { value[c] = client.getCountYearlyReportRegistration(year); c++; } break; } for (int i = 0; i < years.length; i++) { tableModel.addRow(new Object[] { years[i], value[i] }); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(value[0], series1, years[0]); dataset.addValue(value[1], series1, years[1]); dataset.addValue(value[2], series1, years[2]); dataset.addValue(value[3], series1, years[3]); dataset.addValue(value[4], series1, years[4]); dataset.addValue(value[5], series1, years[5]); dataset.addValue(value[6], series1, years[6]); chart = ChartFactory.createBarChart("181 North Place Residences Graph", // chart title "Months of the Year 2014", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); chartPanel = new ChartPanel(chart); displaypane.add(chartPanel, BorderLayout.CENTER); } catch (RemoteException ex) { // Logger.getLogger(ReportGen.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }
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.ja v a 2 s .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:Output.SplitChart.java
public void drawGeneratorProfitAndNetEarningsData(String outputTimeTypeSelect, int iStartTime, int iEndTime, int[] selectIndex, boolean bProfit) { if (bProfit) { this.chartTitle = "GenCo Daily Profits"; } else {// ww w. j av a2 s .co m this.chartTitle = "GenCo Daily Net Earnings"; } ArrayList genAgentProfitAndNetGainByDay = this.amesFrame.getAMESMarket().getGenAgentProfitAndNetGainByDay(); boolean draw3DChart = false; this.dataset = new XYSeriesCollection(); DefaultCategoryDataset dataset3D = new DefaultCategoryDataset(); Object[][] genData = this.amesFrame.getGeneratorData(); int iGenNumber = genData.length; if ((selectIndex.length < 1) || (selectIndex[0] == 0)) { if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run")) { int iDayNumber = genAgentProfitAndNetGainByDay.size(); double[][] genProfit; this.chartTitle = this.chartTitle + "\n " + "for Entire Run"; for (int i = 0; i < iGenNumber; i++) { String genName = (String) genData[i][0]; XYSeries series1; series1 = new XYSeries(genName); for (int iDay = 0; iDay < iDayNumber; iDay++) { genProfit = (double[][]) genAgentProfitAndNetGainByDay.get(iDay); if (bProfit) { series1.add(iDay + 1, (Math.round(genProfit[i][0] * 1000)) / 1000.0); } else { series1.add(iDay + 1, (Math.round(genProfit[i][1] * 1000)) / 1000.0); } } this.dataset.addSeries(series1); } } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day")) { int iDayNumber = (iEndTime - iStartTime) + 1; double[][] genProfit; this.chartTitle = this.chartTitle + "\n " + "From Day " + iStartTime + " to Day " + iEndTime; for (int i = 0; i < iGenNumber; i++) { String genName = (String) genData[i][0]; XYSeries series1; series1 = new XYSeries(genName); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { genProfit = (double[][]) genAgentProfitAndNetGainByDay.get(iDay); if (bProfit) { series1.add(iDay + 1, (Math.round(genProfit[i][0] * 1000)) / 1000.0); } else { series1.add(iDay + 1, (Math.round(genProfit[i][1] * 1000)) / 1000.0); } } this.dataset.addSeries(series1); } } } else { int iDataNumber = selectIndex.length; if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run")) { int iDayNumber = genAgentProfitAndNetGainByDay.size(); double[][] genProfit; this.chartTitle = this.chartTitle + "\n " + "for Entire Run"; for (int i = 0; i < iDataNumber; i++) { String genName = (String) genData[selectIndex[i] - 1][0]; XYSeries series1; series1 = new XYSeries(genName); for (int iDay = 0; iDay < iDayNumber; iDay++) { genProfit = (double[][]) genAgentProfitAndNetGainByDay.get(iDay); if (bProfit) { series1.add(iDay + 1, (Math.round(genProfit[selectIndex[i] - 1][0] * 1000)) / 1000.0); } else { series1.add(iDay + 1, (Math.round(genProfit[selectIndex[i] - 1][1] * 1000)) / 1000.0); } } this.dataset.addSeries(series1); } } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day")) { int iDayNumber = (iEndTime - iStartTime) + 1; double[][] genProfit; this.chartTitle = this.chartTitle + "\n " + "From Day " + iStartTime + " to Day " + iEndTime; for (int i = 0; i < iDataNumber; i++) { String genName = (String) genData[selectIndex[i] - 1][0]; XYSeries series1; series1 = new XYSeries(genName); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { genProfit = (double[][]) genAgentProfitAndNetGainByDay.get(iDay); if (bProfit) { series1.add(iDay + 1, (Math.round(genProfit[selectIndex[i] - 1][0] * 1000)) / 1000.0); } else { series1.add(iDay + 1, (Math.round(genProfit[selectIndex[i] - 1][1] * 1000)) / 1000.0); } } this.dataset.addSeries(series1); } } } if (draw3DChart) { this.chart = ChartFactory.createBarChart3D(this.chartTitle, // chart title "Value Category", // domain axis label "Value ($/D)", // 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); } else { // create the chart... this.chart = ChartFactory.createXYLineChart(this.chartTitle, // chart title "Day", // x axis label "Money ($/D)", // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); this.chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.blue); plot.setRangeGridlinePaint(Color.blue); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.chart); }
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 w w w . j a va2 s. c om*/ } 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:Output.SplitChart.java
public void drawLSESurplusData(String outputTimeTypeSelect, int iStartTime, int iEndTime, int[] selectIndex) { String[] names = { "LSE Name", "Day Index", "Surplus ($/H)" }; this.chartTitle = "LSE Daily Net Earnings"; ArrayList lseAgentSurplusByDay = this.amesFrame.getAMESMarket().getLSEAgentSurplusByDay(); boolean draw3DChart = false; this.dataset = new XYSeriesCollection(); DefaultCategoryDataset dataset3D = new DefaultCategoryDataset(); Object[][] lseHybridData = this.amesFrame.getLSEHybridDemandData(); int iLSENumber = lseHybridData.length; if ((selectIndex.length < 1) || (selectIndex[0] == 0)) { if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run")) { int iDayNumber = lseAgentSurplusByDay.size(); double[][] lseSurplus; this.chartTitle = this.chartTitle + "\n " + "for Entire Run"; for (int i = 0; i < iLSENumber; i++) { String lseName = (String) lseHybridData[i][0]; XYSeries series1 = new XYSeries(lseName + " Surplus"); for (int iDay = 0; iDay < iDayNumber; iDay++) { lseSurplus = (double[][]) lseAgentSurplusByDay.get(iDay); series1.add(iDay + 1, (Math.round(lseSurplus[i][0] * 1000)) / 1000.0); }//w w w . ja v a 2s . co m this.dataset.addSeries(series1); } } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day")) { int iDayNumber = (iEndTime - iStartTime) + 1; double[][] lseSurplus; this.chartTitle = this.chartTitle + "\n " + "From Day " + iStartTime + " to Day " + iEndTime; for (int i = 0; i < iLSENumber; i++) { String lseName = (String) lseHybridData[i][0]; XYSeries series1 = new XYSeries(lseName + " Surplus"); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { lseSurplus = (double[][]) lseAgentSurplusByDay.get(iDay); series1.add(iDay + 1, (Math.round(lseSurplus[i][0] * 1000)) / 1000.0); } this.dataset.addSeries(series1); } } } else { int iDataNumber = selectIndex.length; int iField = names.length; if (outputTimeTypeSelect.equalsIgnoreCase("Entire Run")) { int iDayNumber = lseAgentSurplusByDay.size(); double[][] lseSurplus; this.chartTitle = this.chartTitle + "\n " + "for Entire Run"; for (int i = 0; i < iDataNumber; i++) { String lseName = (String) lseHybridData[selectIndex[i] - 1][0]; XYSeries series1 = new XYSeries(lseName + " Surplus"); for (int iDay = 0; iDay < iDayNumber; iDay++) { lseSurplus = (double[][]) lseAgentSurplusByDay.get(iDay); series1.add(iDay + 1, (Math.round(lseSurplus[selectIndex[i] - 1][0] * 1000)) / 1000.0); } this.dataset.addSeries(series1); } } else if (outputTimeTypeSelect.equalsIgnoreCase("Start to End Day")) { int iDayNumber = (iEndTime - iStartTime) + 1; double[][] lseSurplus; this.chartTitle = this.chartTitle + "\n " + "From Day " + iStartTime + " to Day " + iEndTime; for (int i = 0; i < iDataNumber; i++) { String lseName = (String) lseHybridData[selectIndex[i] - 1][0]; XYSeries series1 = new XYSeries(lseName + " Surplus"); for (int iDay = iStartTime - 1; iDay < iEndTime; iDay++) { lseSurplus = (double[][]) lseAgentSurplusByDay.get(iDay); series1.add(iDay + 1, (Math.round(lseSurplus[selectIndex[i] - 1][0] * 1000)) / 1000.0); } this.dataset.addSeries(series1); } } } if (draw3DChart) { this.chart = ChartFactory.createBarChart3D(this.chartTitle, // chart title "Value Category", // domain axis label "Value", // 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); } else { // create the chart... this.chart = ChartFactory.createXYLineChart(this.chartTitle, // chart title "Day", // x axis label "Value", // y axis label this.dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); this.chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = this.chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.blue); plot.setRangeGridlinePaint(Color.blue); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } this.chart.getTitle().setFont(this.font); this.chartPanel.setChart(this.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 ww w .j a va2s . co 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;//ww w .j a v a2 s.c o 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: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 ww w . j av a2 s. co m } if (defaultPlotOrientation != null) { p.setOrientation(defaultPlotOrientation); } }
From source file:org.forester.archaeopteryx.TreePanel.java
private static JFreeChart createChart(CategoryDataset dataset, String branch_name) { // create the chart JFreeChart chart = ChartFactory.createBarChart("RAxML Weights Histogram " + branch_name, // chart title "RAxML Weights", // domain axis label "Placements", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? );/*from w ww .j av a 2s . c o m*/ // set the background color for the chart and title colors & font chart.setBackgroundPaint(Color.black); chart.setTextAntiAlias(true); chart.setBorderPaint(Color.green); chart.getTitle().setPaint(Color.white); chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(12.0f)); // get a reference to the plot for further customisation CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.7f); plot.setBackgroundPaint(Color.black); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only, set colors & font final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelPaint(Color.white); rangeAxis.setLabelFont(rangeAxis.getLabelFont().deriveFont(10.0f)); rangeAxis.setAxisLinePaint(new Color(226, 236, 243)); rangeAxis.setTickLabelFont(rangeAxis.getTickLabelFont().deriveFont(8.0f)); rangeAxis.setTickLabelPaint(Color.white); // Custom renderer to display each bar in another color final BarRenderer renderer = new CustomRenderer(new Paint[] { new Color(255, 0, 0), new Color(227, 28, 0), new Color(199, 56, 0), new Color(171, 84, 0), new Color(143, 112, 0), new Color(115, 140, 0), new Color(87, 168, 0), new Color(59, 196, 0), new Color(31, 224, 0), new Color(0, 255, 0) }); // shadow effect off renderer.setShadowVisible(false); //make custom renderer the new renderer for the barchart plot.setRenderer(renderer); // set x axis label rotation, font and color CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4)); domainAxis.setLabelPaint(Color.white); domainAxis.setLabelFont(domainAxis.getLabelFont().deriveFont(10.0f)); domainAxis.setTickLabelPaint(Color.white); domainAxis.setTickLabelFont(domainAxis.getTickLabelFont().deriveFont(8.0f)); domainAxis.setAxisLinePaint(new Color(226, 236, 243)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }