List of usage examples for org.jfree.chart.plot CategoryPlot setRangeAxisLocation
public void setRangeAxisLocation(int index, AxisLocation location)
From source file:org.amanzi.awe.charts.builder.CategoryChartBuilder.java
@Override protected void setSecondAxisForPlot(CategoryPlot plot, Dataset dataset, LineAndShapeRenderer subRenderer, NumberAxis secondAxis) {/* www . j a v a 2 s . c o m*/ plot.setDataset(1, (CategoryDataset) dataset); plot.mapDatasetToRangeAxis(1, 1); plot.setRangeAxis(1, secondAxis); plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_LEFT); plot.setRenderer(1, subRenderer); }
From source file:org.testeditor.dashboard.TableDurationTrend.java
/** * designs and creates graph from data sets. * /*from w ww . ja v a 2 s.co m*/ * @param objektList * list of all suite GoogleSucheSuite runs <AllRunsResult> * @param parent * composite parent * @param modelService * to find part label * @param window * trimmed window * @param app * org.eclipse.e4.ide.application */ @SuppressWarnings({ "serial" }) @Inject @Optional public void createControls(@UIEventTopic("Testobjektlist") List<AllRunsResult> objektList, Composite parent, EModelService modelService, MWindow window, MApplication app) { MPart mPart = (MPart) modelService.find("org.testeditor.ui.part.2", app); String[] arr = objektList.get(0).getFilePath().getName().split("\\."); String filenameSplitted = arr[arr.length - 1]; mPart.setLabel(translationService.translate("%dashboard.table.label.duration", CONTRIBUTOR_URI) + " " + filenameSplitted); mPart.setTooltip(translationService.translate("%dashboard.table.label.duration", CONTRIBUTOR_URI) + " " + objektList.get(0).getFilePath().getName()); parent.setLayout(new FillLayout()); // create the chart... chart = ChartFactory.createBarChart3D(null, // chart // title translationService.translate("%dashboard.table.label.duration.axis.dates", CONTRIBUTOR_URI), // domain // X axis // label translationService.translate("%dashboard.table.label.duration.axis.duration", CONTRIBUTOR_URI) + " h:m:s:ms", // range // Y axis // label createDataset(objektList), // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); // y axis right plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setNumberFormatOverride(new NumberFormat() { // show duration // values in // h:m:s:ms @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { // return new StringBuffer(String.format("%f", number)); return new StringBuffer(String.format(formatDuration(number))); } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { // return new StringBuffer(String.format("%f", number)); return new StringBuffer(String.format(formatDuration(number))); } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } }); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1} " + translationService.translate("%dashboard.table.label.duration.axis.duration", CONTRIBUTOR_URI) + ": {2}ms", NumberFormat.getInstance())); renderer.setDrawBarOutline(false); renderer.setMaximumBarWidth(.15); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(1.57)); Color color = toAwtColor(ColorConstants.COLOR_BLUE); final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, color, 0, 0, color); renderer.setSeriesPaint(0, gp0); chartComposite = new ChartComposite(parent, SWT.EMBEDDED); chartComposite.setSize(800, 800); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); chartComposite.setLayoutData(data); chartComposite.setHorizontalAxisTrace(false); chartComposite.setVerticalAxisTrace(false); chartComposite.setChart(chart); chartComposite.pack(true); chartComposite.setVisible(true); chartComposite.forceRedraw(); parent.layout(); }
From source file:org.jfree.chart.demo.DualAxisDemo6.java
private static JFreeChart createChart(CategoryDataset categorydataset, CategoryDataset categorydataset1) { CategoryAxis categoryaxis = new CategoryAxis("Category"); NumberAxis numberaxis = new NumberAxis("Value"); GroupedStackedBarRenderer groupedstackedbarrenderer = new GroupedStackedBarRenderer(); KeyToGroupMap keytogroupmap = new KeyToGroupMap("G1"); keytogroupmap.mapKeyToGroup("Series 1A", "G1"); keytogroupmap.mapKeyToGroup("Series 1B", "G1"); keytogroupmap.mapKeyToGroup("NOTHING", "G2"); groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap); CategoryPlot categoryplot = new CategoryPlot(categorydataset, categoryaxis, numberaxis, groupedstackedbarrenderer) { private static final long serialVersionUID = 1L; public LegendItemCollection getLegendItems() { LegendItemCollection legenditemcollection = new LegendItemCollection(); legenditemcollection.addAll(getRenderer().getLegendItems()); CategoryDataset categorydataset2 = getDataset(1); if (categorydataset2 != null) { CategoryItemRenderer categoryitemrenderer = getRenderer(1); if (categoryitemrenderer != null) { org.jfree.chart.LegendItem legenditem = categoryitemrenderer.getLegendItem(1, 1); legenditemcollection.add(legenditem); }// ww w .j a v a 2s .c o m } return legenditemcollection; } }; JFreeChart jfreechart = new JFreeChart("Dual Axis Bar Chart", categoryplot); categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); categoryplot.setDataset(1, categorydataset1); categoryplot.mapDatasetToRangeAxis(1, 1); NumberAxis numberaxis1 = new NumberAxis("Secondary"); categoryplot.setRangeAxis(1, numberaxis1); categoryplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); BarRenderer barrenderer = new BarRenderer(); categoryplot.setRenderer(1, barrenderer); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:peakmlviewer.dialog.peakinformation.Graph.java
public Graph(Composite parent) { super(parent, SWT.EMBEDDED); setLayout(new FillLayout()); // create the chart linechart = ChartFactory.createLineChart(null, "", "Abundance", dataset_intensity, PlotOrientation.VERTICAL, false, // legend false, // tooltips false // urls );/* w w w . j av a 2s .c o m*/ CategoryPlot plot = (CategoryPlot) linechart.getPlot(); // make the labels for the xaxis 45 degrees CategoryAxis xaxis = (CategoryAxis) plot.getDomainAxis(); xaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // add the mass accuracy yaxis NumberAxis yaxis_massacc = new NumberAxis("Mass accuracy (ppm)"); plot.setRangeAxis(1, yaxis_massacc); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // create the mass accuracy dataset dataset_ppm = new DefaultCategoryDataset(); plot.setDataset(1, dataset_ppm); plot.mapDatasetToRangeAxis(1, 1); // create the renderer for the mass accuracy dataset LineAndShapeRenderer renderer_ppm = new LineAndShapeRenderer(); renderer_ppm.setBaseShapesFilled(true); renderer_ppm.setBaseShapesVisible(true); renderer_ppm.setBaseStroke( new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1, new float[] { 5, 5 }, 0)); plot.setRenderer(1, renderer_ppm); // setup the renderer for the intensity dataset LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesFilled(true); renderer.setBaseShapesVisible(true); // general properties linechart.setBackgroundPaint(Color.WHITE); linechart.setBorderVisible(false); linechart.setAntiAlias(true); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); // add the components // -------------------------------------------------------------------------------- // This uses the SWT-trick for embedding awt-controls in an SWT-Composit. try { System.setProperty("sun.awt.noerasebackground", "true"); } catch (NoSuchMethodError error) { ; } java.awt.Frame frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(this); // create a new ChartPanel, without the popup-menu (5x false) frame.add(new ChartPanel(linechart, false, false, false, false, false)); // -------------------------------------------------------------------------------- }
From source file:org.jfree.chart.demo.DualAxisDemo3.java
/** * Creates a new demo instance.//from ww w. ja v a2 s .c o m * * @param title the frame title. */ public DualAxisDemo3(final String title) { super(title); final CategoryDataset dataset1 = createDataset1(); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Dual Axis Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset1, // dataset PlotOrientation.HORIZONTAL, // orientation true, // include legend true, false); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(new Color(0xCC, 0xFF, 0xCC)); // chart.getLegend().setAnchor(Legend.WEST); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); // plot.getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f); final CategoryDataset dataset2 = createDataset2(); final ValueAxis axis2 = new NumberAxis("Secondary"); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); final CategoryItemRenderer renderer2 = new LineAndShapeRenderer(); plot.setRenderer(1, renderer2); // 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:com.jaspersoft.studio.jasper.ChartConverter.java
/** * /*from www . ja v a 2s . com*/ */ private Renderable getRenderer(ReportConverter reportConverter, JRChart chart) { JasperReportsConfiguration jContext = (JasperReportsConfiguration) reportConverter .getJasperReportsContext(); String renderType = null; Rectangle2D rectangle = null; ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(jContext.getClassLoader()); if (dataset != null && jfreeChart != null) dataset.removeChangeListener(jfreeChart.getPlot()); renderType = chart.getRenderType();// FIXMETHEME try reuse this sequence if (renderType == null) { renderType = JRPropertiesUtil.getInstance(jContext).getProperty(reportConverter.getReport(), JRChart.PROPERTY_CHART_RENDER_TYPE); } String themeName = chart.getTheme(); if (themeName == null) { themeName = JRPropertiesUtil.getInstance(jContext).getProperty(reportConverter.getReport(), JRChart.PROPERTY_CHART_THEME); } ChartTheme theme = ChartUtil.getInstance(jContext).getTheme(themeName); if (theme instanceof SimpleChartTheme) { SimpleChartTheme sct = (SimpleChartTheme) theme; sct.getChartSettings() .setBackgroundImage(getCachedImageProvider(sct.getChartSettings().getBackgroundImage())); sct.getPlotSettings() .setBackgroundImage(getCachedImageProvider(sct.getPlotSettings().getBackgroundImage())); } ChartContext chartContext = null; // Object cc = jContext.getMap().get(chart); // if (cc != null && cc instanceof ChartContext) // chartContext = (ChartContext) cc; // else { chartContext = new ConvertChartContext(chart, jContext); try { jfreeChart = theme.createChart(chartContext); dataset = chartContext.getDataset(); if (jfreeChart == null && chart.getChartType() == JRChart.CHART_TYPE_MULTI_AXIS) { List<JRChartAxis> axis = ((JRDesignMultiAxisPlot) chart.getPlot()).getAxes(); Plot mainPlot = null; int axisNumber = 0; for (JRChartAxis ax : axis) { JRChart chartAxis = ((JRDesignChartAxis) ax).getChart(); if (jfreeChart == null) { jfreeChart = getJFreeChart(reportConverter, chartAxis); mainPlot = jfreeChart.getPlot(); if (mainPlot instanceof CategoryPlot) ((CategoryPlot) mainPlot).setRangeAxisLocation(0, getChartAxisLocation(ax)); else if (mainPlot instanceof XYPlot) ((XYPlot) mainPlot).setRangeAxisLocation(0, getChartAxisLocation(ax)); } else { axisNumber++; JFreeChart axisChart = getJFreeChart(reportConverter, chartAxis); if (mainPlot instanceof CategoryPlot) { CategoryPlot mainCatPlot = (CategoryPlot) mainPlot; if (!(axisChart.getPlot() instanceof CategoryPlot)) continue; // Get the axis and add it to the multi axis chart plot CategoryPlot axisPlot = (CategoryPlot) axisChart.getPlot(); mainCatPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis()); mainCatPlot.setRangeAxisLocation(axisNumber, getChartAxisLocation(ax)); // Add the data set and map it to the recently added axis mainCatPlot.setDataset(axisNumber, axisPlot.getDataset()); mainCatPlot.mapDatasetToRangeAxis(axisNumber, axisNumber); // Set the renderer to use to draw the dataset. mainCatPlot.setRenderer(axisNumber, axisPlot.getRenderer()); // Handle any color series for this chart configureAxisSeriesColors(axisPlot.getRenderer(), chartAxis.getPlot()); } else if (mainPlot instanceof XYPlot) { XYPlot mainXyPlot = (XYPlot) mainPlot; if (!(axisChart.getPlot() instanceof XYPlot)) continue; // Get the axis and add it to the multi axis chart plot XYPlot axisPlot = (XYPlot) axisChart.getPlot(); mainXyPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis()); mainXyPlot.setRangeAxisLocation(axisNumber, getChartAxisLocation(ax)); // Add the data set and map it to the recently added axis mainXyPlot.setDataset(axisNumber, axisPlot.getDataset()); mainXyPlot.mapDatasetToRangeAxis(axisNumber, axisNumber); // Set the renderer to use to draw the dataset. mainXyPlot.setRenderer(axisNumber, axisPlot.getRenderer()); // Handle any color series for this chart configureAxisSeriesColors(axisPlot.getRenderer(), chartAxis.getPlot()); } } } } } catch (JRException e) { throw new JRRuntimeException(e); } rectangle = new Rectangle2D.Double(0, 0, chart.getWidth(), chart.getHeight()); } finally { Thread.currentThread().setContextClassLoader(oldLoader); } return ChartUtil.getInstance(jContext).getChartRenderableFactory(renderType).getRenderable(jContext, jfreeChart, null, rectangle); }
From source file:org.pentaho.chart.plugin.jfreechart.chart.JFreeChartGenerator.java
/** * Sets the current range axis location based on axis location style key (specified in the chart document). * * NOTE: Plot's range axis location is updated * * @param plot Plot for the current chart * @param axisElement Current axis element being proccessed * @param axisCounter Set the location and tie it to a index. *//* ww w .j a va2 s .c o m*/ private void setRangeAxisLocation(final CategoryPlot plot, final ChartElement axisElement, final int axisCounter) { final CSSValue cssValue = axisElement.getLayoutStyle().getValue(ChartStyleKeys.AXIS_LOCATION); final String side = cssValue.getCSSText(); if (side != null && (cssValue.equals(ChartAxisLocationType.PRIMARY))) { plot.setRangeAxisLocation(axisCounter, AxisLocation.BOTTOM_OR_LEFT); } else { plot.setRangeAxisLocation(axisCounter, AxisLocation.TOP_OR_RIGHT); } }
From source file:org.pentaho.reporting.engine.classic.extensions.legacy.charts.LegacyChartType.java
private JFreeChart createChart(final Expression aExpression) { if (aExpression instanceof BarLineChartExpression) { final CategoryAxis catAxis = new CategoryAxis("Category");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final CategoryPlot plot = new CategoryPlot(createDataset(), catAxis, barsAxis, new BarRenderer()); plot.setRenderer(1, new LineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createDataset()); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); return new JFreeChart("Bar Line Chart", plot); }// w w w . j a v a 2 s . c om if (aExpression instanceof RingChartExpression) { return ChartFactory.createRingChart("Ring Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof AreaChartExpression) { return ChartFactory.createAreaChart("Area Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof BarChartExpression) { return ChartFactory.createBarChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof LineChartExpression) { return ChartFactory.createLineChart("Line Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof MultiPieChartExpression) { return ChartFactory.createMultiplePieChart("Multi Pie Chart", createDataset(), TableOrder.BY_COLUMN, true, false, false);// NON-NLS } if (aExpression instanceof PieChartExpression) { return ChartFactory.createPieChart("Pie Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof WaterfallChartExpressions) { return ChartFactory.createWaterfallChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.HORIZONTAL, true, false, false);// NON-NLS } if (aExpression instanceof BubbleChartExpression) { return ChartFactory.createBubbleChart("Bubble Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ExtendedXYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ScatterPlotChartExpression) { return ChartFactory.createScatterPlot("Scatter Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYAreaLineChartExpression) { final NumberAxis catAxis = new NumberAxis("Range");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final XYPlot plot = new XYPlot(createXYZDataset(), catAxis, barsAxis, new XYAreaRenderer()); plot.setRenderer(1, new XYLineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createXYZDataset()); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); return new JFreeChart("XY Area Line Chart", plot);// NON-NLS } if (aExpression instanceof XYAreaChartExpression) { return ChartFactory.createXYAreaChart("XY Area Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYBarChartExpression) { return XYBarChartExpression.createXYBarChart("XY Bar Chart", "X", false, "Y", createIntervalXYDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof RadarChartExpression) { final SpiderWebPlot plot = new SpiderWebPlot(createDataset()); return new JFreeChart("Radar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } if (aExpression instanceof ThermometerChartExpression) { final DefaultValueDataset dataset = new DefaultValueDataset(new Double(65.0)); final ThermometerPlot plot = new ThermometerPlot(dataset); return new JFreeChart("Thermometer Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } return null; }
From source file:RDGraphGenerator.java
/** * Creates a sample chart.//from w ww.j ava 2 s. c o m * * @param dataset the dataset for the chart. * * @return A sample chart. */ private JFreeChart createDistChart(String riderID) { String riderName = (String) riders.get(riderID); final JFreeChart chart = ChartFactory.createStackedBarChart(riderName + "'s Distances", // chart title "Month", // domain axis label mainDist, // range axis label (CategoryDataset) riderDistances.get(riderID), // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); map.mapKeyToGroup("0", "G1"); map.mapKeyToGroup("1", "G1"); map.mapKeyToGroup("2", "G1"); map.mapKeyToGroup("3", "G1"); renderer.setSeriesToGroupMap(map); renderer.setItemMargin(0.0); Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f, new Color(0x88, 0x88, 0xFF)); renderer.setSeriesPaint(0, p1); Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f, new Color(0x88, 0xFF, 0x88)); renderer.setSeriesPaint(1, p2); Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f, new Color(0xFF, 0x88, 0x88)); renderer.setSeriesPaint(2, p3); Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f, new Color(0xFF, 0xFF, 0x88)); renderer.setSeriesPaint(3, p4); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRenderer(renderer); plot.setFixedLegendItems(createLegendItems()); ValueAxis va = (ValueAxis) plot.getRangeAxis(); ValueAxis ova = null; try { ova = (ValueAxis) va.clone(); } catch (CloneNotSupportedException cnse) { } ova.setLabel(secondaryDist); ova.setLowerBound(va.getLowerBound() * unitConversion); ova.setUpperBound(va.getUpperBound() * unitConversion); plot.setRangeAxis(1, ova); plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT); CategoryAxis ca = plot.getDomainAxis(); ca.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); //Make around the chart transparent. chart.setBackgroundPaint(null); return chart; }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createBarLineChart(final BarLineChartDefinition chartDefinition) { // TODO Make the following accessible from the chartDefinition String categoryAxisLabel = null; String valueAxisLabel = null; String secondValueAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); PlotOrientation orientation = chartDefinition.getOrientation(); // split BarLineChartDefinition in two Definitions CategoryDatasetChartDefinition barsDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); CategoryDatasetChartDefinition linesDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); /*//w w w . j av a2 s. c o m * try{ barsDataset = (CategoryDatasetChartDefinition)chartDefinition.clone(); linesDataset = * (CategoryDatasetChartDefinition)chartDefinition.clone(); }catch(Exception e){} */ // get column and row count of the data set int iColumnCount = chartDefinition.getColumnCount(); int iRowCount = chartDefinition.getRowCount(); if (iRowCount <= 0) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE")); //$NON-NLS-1$ } /* * Copy data to the two new data sets */ // Loop through columns for (int r = 0; r < iRowCount; r++) { // check if measure should be include in bar or line dataset String strMeasureName = (String) chartDefinition.getRowKey(r); boolean bIsBarColumn = JFreeChartEngine.isBarColumn(chartDefinition.getBarColumns(), strMeasureName); boolean bIsLineColumn = JFreeChartEngine.isLineColumn(chartDefinition.getLineColumns(), strMeasureName); // getting all values for (int c = 0; c < iColumnCount; c++) { Comparable compColumnName = chartDefinition.getColumnKey(c); Number nValue = chartDefinition.getValue(strMeasureName, compColumnName); if (bIsBarColumn) { barsDataset.addValue(nValue, strMeasureName, compColumnName); } if (bIsLineColumn) { linesDataset.addValue(nValue, strMeasureName, compColumnName); } } } if ((iRowCount > 0) && (barsDataset.getRowCount() <= 0) && (linesDataset.getRowCount() <= 0)) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT")); //$NON-NLS-1$ } // Create Axis Objects CategoryAxis catAxis = new CategoryAxis(categoryAxisLabel); NumberAxis barsAxis = new NumberAxis(valueAxisLabel); NumberAxis linesAxis = new NumberAxis(secondValueAxisLabel); // set title and font for lines Axis linesDataset.setRangeTitle(chartDefinition.getLinesRangeTitle()); linesDataset.setRangeTitleFont(chartDefinition.getLinesRangeTitleFont()); if (chartDefinition.getLinesRangeTickFormat() != null) { linesAxis.setNumberFormatOverride(chartDefinition.getLinesRangeTickFormat()); } // create renderer BarRenderer barRenderer = null; LineAndShapeRenderer lineRenderer = null; // Determine the type of renderer to use if (chartDefinition.isStacked() || chartDefinition.isThreeD()) { if (chartDefinition.isStacked() && chartDefinition.isThreeD()) { barRenderer = new StackedBarRenderer3D(); lineRenderer = new LineRenderer3D(); } else if (chartDefinition.isStacked()) { barRenderer = new StackedBarRenderer(); lineRenderer = new LineAndShapeRenderer(); } else { barRenderer = new BarRenderer3D(); lineRenderer = new LineRenderer3D(); } } else { barRenderer = new BarRenderer(); lineRenderer = new LineAndShapeRenderer(); } if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } if (tooltips) { barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); lineRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { barRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); lineRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } if (chartDefinition.getMaxBarWidth() != null) { barRenderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue()); } // setting some line attributes lineRenderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth())); lineRenderer.setShapesVisible(chartDefinition.isMarkersVisible()); lineRenderer.setBaseShapesFilled(chartDefinition.isMarkersVisible()); /* * Create plot and make necessary adjustments for overlaid chart */ // create the plot with bar chart CategoryPlot plot = new CategoryPlot(barsDataset, catAxis, barsAxis, barRenderer); // add line renderer plot.setRenderer(1, lineRenderer); // add lines dataset, renderer and axis to plot plot.setDataset(1, linesDataset); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // standard settings for plots JFreeChartEngine.updatePlot(plot, barsDataset); // additional settings for second axis ValueAxis secondValueAxis = plot.getRangeAxis(1); if (secondValueAxis != null) { if (chartDefinition.getLinesRangeTitle() != null) { secondValueAxis.setLabel(chartDefinition.getLinesRangeTitle()); } if (chartDefinition.getLinesRangeTitleFont() != null) { secondValueAxis.setLabelFont(chartDefinition.getLinesRangeTitleFont()); } if (chartDefinition.getLinesRangeTickFont() != null) { secondValueAxis.setTickLabelFont(chartDefinition.getLinesRangeTickFont()); } if (chartDefinition.getLinesRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { secondValueAxis.setLowerBound(chartDefinition.getLinesRangeMinimum()); } if (chartDefinition.getLinesRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { secondValueAxis.setUpperBound(chartDefinition.getLinesRangeMaximum()); } } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }