List of usage examples for org.jfree.chart.axis CategoryAxis setTickLabelFont
public void setTickLabelFont(Font font)
From source file:com.att.aro.main.ProperSessionTerminationPanel.java
/** * Initializes the Panel for Proper Session Termination plot. *//*from w w w . j a v a2s. co m*/ private void initialize() { JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.sessionoverview.title"), null, null, createDataset(null), PlotOrientation.HORIZONTAL, false, false, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setMaximumCategoryLabelWidthRatio(1.0f); domainAxis.setMaximumCategoryLabelLines(2); domainAxis.setLabelFont(AROUIManager.LABEL_FONT); domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(rb.getString("analysisresults.percentage")); rangeAxis.setRange(0.0, 100.0); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String sessionInfo = ""; switch (arg2) { case SESSION_TERMINATION: sessionInfo = rb.getString("tooltip.sessionTermination"); break; case SESSION_TIGHT_CONN: sessionInfo = rb.getString("tooltip.sessionTightConn"); break; case SESSION_BURST: sessionInfo = rb.getString("tooltip.sessionBurst"); break; case SESSION_LONG_BURST: sessionInfo = rb.getString("tooltip.sessionLongBurst"); break; } return sessionInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100, 100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER, PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); this.add(chartPanel, BorderLayout.CENTER); }
From source file:com.att.aro.main.TraceOverviewPanel.java
/** * Initializes the Main panel and its various components. *//*w ww. ja v a 2 s . c o m*/ private void initialize() { JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.traceoverview.title"), null, null, createDataset(null), PlotOrientation.HORIZONTAL, false, true, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis valueRangeAxis = plot.getDomainAxis(); valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f); valueRangeAxis.setMaximumCategoryLabelLines(2); valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT); valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(rb.getString("analysisresults.percentile")); rangeAxis.setRange(0.0, 100.0); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String traceInfo = ""; switch (arg2) { case TRACE_AVERAGE: traceInfo = rb.getString("tooltip.traceAnalysis.avg"); break; case TRACE_ENERGY: traceInfo = rb.getString("tooltip.traceAnalysis.engy"); break; case TRACE_OVERHEAD: traceInfo = rb.getString("tooltip.traceAnalysis.ovrhd"); break; } return traceInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100, 100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER, PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); this.add(chartPanel, BorderLayout.CENTER); }
From source file:piilSource.BarChart.java
private JFreeChart createChart(String title, final CategoryDataset dataset, String metaLabel) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart( "Barplot of the " + metaLabel + " values for all samples - " + title, // chart title "Samples", // domain axis label metaLabel + " values", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );//from w w 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 customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.red); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (metaLabel.equals("beta")) { rangeAxis.setRange(0, 1); rangeAxis.setTickUnit(new NumberTickUnit(0.2)); } // 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.blue); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.green); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.red); final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, Color.yellow); final GradientPaint gp4 = new GradientPaint(0.0f, 0.0f, Color.cyan, 0.0f, 0.0f, Color.cyan); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); renderer.setSeriesPaint(3, gp3); renderer.setSeriesPaint(4, gp4); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); if (dataset.getColumnCount() > 40) { domainAxis.setTickLabelFont(new Font("Serif", Font.PLAIN, 10)); domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2)); } return chart; }
From source file:com.att.aro.ui.view.overviewtab.ConnectionStatisticsChartPanel.java
public JFreeChart initializeChart() { JFreeChart chart = ChartFactory.createBarChart( ResourceBundleHelper.getMessageString("overview.sessionoverview.title"), null, null, createDataset(), PlotOrientation.HORIZONTAL, false, false, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setMaximumCategoryLabelWidthRatio(1.0f); domainAxis.setMaximumCategoryLabelLines(2); domainAxis.setLabelFont(AROUIManager.LABEL_FONT); domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(ResourceBundleHelper.getMessageString("analysisresults.percentage")); rangeAxis.setRange(0.0, 100.0);/*from www .ja va 2s. c o m*/ rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String sessionInfo = ""; switch (arg2) { case SESSION_TERMINATION: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionTermination"); break; case SESSION_TIGHT_CONN: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionTightConn"); break; case SESSION_BURST: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionBurst"); break; case SESSION_LONG_BURST: sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionLongBurst"); break; default: break; } return sessionInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); return chart; }
From source file:com.att.aro.ui.view.overviewtab.TraceBenchmarkChartPanel.java
private JFreeChart initializeChart() { JFreeChart chart = ChartFactory.createBarChart( ResourceBundleHelper.getMessageString("overview.traceoverview.title"), null, null, createDataset(), PlotOrientation.HORIZONTAL, false, true, false); chart.setBackgroundPaint(this.getBackground()); chart.getTitle().setFont(AROUIManager.HEADER_FONT); this.plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryAxis valueRangeAxis = plot.getDomainAxis(); valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f); valueRangeAxis.setMaximumCategoryLabelLines(2); valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT); valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabel(ResourceBundleHelper.getMessageString("analysisresults.percentile")); rangeAxis.setRange(0.0, 100.0);/*from w w w. j a v a 2 s . c o m*/ rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setLabelFont(AROUIManager.LABEL_FONT); rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT); BarRenderer renderer = new StackedBarRenderer(); renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseItemLabelGenerator(new PercentLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); // Make second bar in stack invisible renderer.setSeriesItemLabelsVisible(1, false); renderer.setSeriesPaint(1, new Color(0, 0, 0, 0)); ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setBasePositiveItemLabelPosition(insideItemlabelposition); ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) { String traceInfo = ""; switch (arg2) { case TRACE_AVERAGE: traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.avg"); break; case TRACE_ENERGY: traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.engy"); break; case TRACE_OVERHEAD: traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.ovrhd"); break; default: break; } return traceInfo; } }); plot.setRenderer(renderer); plot.getDomainAxis().setMaximumCategoryLabelLines(2); return chart; }
From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java
private void updateChart(SimpleFeatureCollection features, String[] fields) { // Setup Box plot int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; CategoryAxis xPlotAxis = new CategoryAxis(EMPTY); // Type xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 12)); NumberAxis yPlotAxis = new NumberAxis("Value"); // Value //$NON-NLS-1$ yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); yPlotAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setMedianVisible(true);/*from w ww . j a v a2 s .c o m*/ renderer.setMeanVisible(false); renderer.setFillBox(true); renderer.setSeriesFillPaint(0, java.awt.Color.CYAN); renderer.setBaseFillPaint(java.awt.Color.CYAN); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); // Set the scatter data, renderer, and axis into plot CategoryDataset dataset = getDataset(features, fields); CategoryPlot plot = new CategoryPlot(dataset, xPlotAxis, yPlotAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setRangePannable(false); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setForegroundAlpha(0.85f); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup Selection /***************************************************************************************** * CategoryAxis xSelectionAxis = new CategoryAxis(EMPTY); * xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); * * NumberAxis ySelectionAxis = new NumberAxis(EMPTY); * ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); * * BoxAndWhiskerRenderer selectionRenderer = new BoxAndWhiskerRenderer(); * selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6)); * selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot * * plot.setDataset(2, new DefaultBoxAndWhiskerCategoryDataset()); plot.setRenderer(2, * selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, * ySelectionAxis); * * // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, * 0); plot.mapDatasetToRangeAxis(2, 0); *****************************************************************************************/ // 5. Finally, Create the chart with the plot and a legend java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:org.sakaiproject.evaluation.tool.reporting.EvalLikertChartBuilder.java
@SuppressWarnings("deprecation") public JFreeChart makeLikertChart() { DefaultCategoryDataset likertDataset = new DefaultCategoryDataset(); for (int i = 0; i < responses.length; i++) { likertDataset.addValue(values[i], "Responses", responses[i]); }//w w w . j a v a2s. c o m JFreeChart chart = ChartFactory.createBarChart(null, // "Likert Chart", // Chart title null, // "Choices", // domain axis label null, // "# of Responses", // range axis label likertDataset, PlotOrientation.HORIZONTAL, false, // show legend false, // show tooltips false // show URLs ); // Set the background colours chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); // Configure the bar colors and display BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(244, 252, 212)); renderer.setDrawBarOutline(true); renderer.setOutlinePaint(new Color(34, 35, 237)); renderer.setOutlineStroke(new BasicStroke(0.5f)); renderer.setBaseItemLabelsVisible(true); if (showPercentages) { renderer.setBaseItemLabelGenerator(new LikertPercentageItemLabelGenerator(this.responseCount)); } else { renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } // Turn off the Top Value Axis ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setVisible(false); rangeAxis.setUpperMargin(0.35); rangeAxis.resizeRange(1.1f); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setMaximumCategoryLabelWidthRatio(0.4f); domainAxis.setMaximumCategoryLabelLines(2); // Set the font for the labels Font labelFont = new Font("Serif", Font.PLAIN, 6); CategoryItemRenderer itemRenderer = plot.getRenderer(); itemRenderer.setBaseItemLabelFont(labelFont); plot.setOutlinePaint(null); domainAxis.setLabelFont(labelFont); domainAxis.setTickLabelFont(labelFont); rangeAxis.setLabelFont(labelFont); rangeAxis.setTickLabelFont(labelFont); return chart; }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * DOC bZhou Comment method "decorateCategoryPlot". * // w w w. j av a2 s. c o m * @param chart */ public static void decorateCategoryPlot(JFreeChart chart, PlotOrientation orientation) { CategoryPlot plot = chart.getCategoryPlot(); CategoryItemRenderer render = plot.getRenderer(); CategoryAxis domainAxis = plot.getDomainAxis(); // ADD msjian TDQ-5111 2012-4-9: set something look it well domainAxis.setCategoryMargin(0.1); domainAxis.setUpperMargin(0.05); domainAxis.setLowerMargin(0.05); domainAxis.setCategoryLabelPositionOffset(10); // TDQ-5111~ ValueAxis valueAxis = plot.getRangeAxis(); Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$ render.setBaseItemLabelFont(font); // MOD zshen 10998: change the font name 2010-01-16 font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setLabelFont(font); font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ valueAxis.setLabelFont(font); font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setTickLabelFont(font); valueAxis.setTickLabelFont(font); setLegendFont(chart); font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$ TextTitle title = chart.getTitle(); if (title != null) { title.setFont(font); } font = null; if (render instanceof BarRenderer) { CategoryDataset dataset = chart.getCategoryPlot().getDataset(); if (dataset != null) { int rowCount = dataset.getRowCount(); List<?> columnKeys = dataset.getColumnKeys(); if (!isContainCJKCharacter(columnKeys.toArray())) { domainAxis.setTickLabelFont(new Font("Tahoma", Font.PLAIN, 10));//$NON-NLS-1$ } ((BarRenderer) render).setItemMargin(-0.40 * rowCount); // TDQ-12621 add Tooltip for Lable for (Object colKey : columnKeys) { domainAxis.addCategoryLabelToolTip(colKey.toString(), colKey.toString()); } } domainAxis.setUpperMargin(0.1); // TDQ-12621 Only display in 1 line for the label, other chars will be displayed as "..." domainAxis.setMaximumCategoryLabelLines(1); // ADD msjian TDQ-5111 2012-4-9: set Bar Width and let it look well // not do this when the bar is horizontal Orientation if (orientation == null) { ((BarRenderer) render).setMaximumBarWidth(0.2); } // TDQ-5111~ } // ~10998 }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartCategoryGraphSource.java
@Override public void initialize() throws GraphException { String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE); String xLabel = getParam(GraphSource.GRAPH_X_LABEL, String.class, DEFAULT_DOMAIN_LABEL); String yLabel = getParam(GraphSource.GRAPH_Y_LABEL, String.class, DEFAULT_RANGE_LABEL); CategoryDataset dataset = makeDataSet(); chart = createChart(title, xLabel, yLabel, dataset, false, false); // start customizing the graph Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor); Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET); Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class, backgroundColor);/* w w w . j av a2s . c o m*/ Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class, backgroundColor); boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER); chart.setBackgroundPaint(backgroundColor); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(plotColor); plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset)); plot.setDomainGridlinePaint(graphDomainGridlinePaint); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(graphRangeGridlinePaint); plot.setOutlineVisible(graphBorder); // set the axis location AxisLocation axisLocation = getParam(GraphSource.GRAPH_RANGE_AXIS_LOCATION, AxisLocation.class, AxisLocation.TOP_OR_LEFT); plot.setRangeAxisLocation(axisLocation); // customize the y-axis if (params.get(RANGE_AXIS) instanceof ValueAxis) { ValueAxis valueAxis = (ValueAxis) params.get(RANGE_AXIS); plot.setRangeAxis(valueAxis); } ValueAxis valueAxis = plot.getRangeAxis(); Object yAxisFont = params.get(GraphSource.GRAPH_Y_AXIS_FONT); Object yAxisLabelFont = params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT); Double rangeLowerBound = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, null); Double rangeUpperBound = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, null); boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false); boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class, true); if (yAxisFont instanceof Font) { valueAxis.setTickLabelFont((Font) yAxisFont); } if (yAxisLabelFont instanceof Font) { valueAxis.setLabelFont((Font) yAxisLabelFont); } if (rangeLowerBound != null) { valueAxis.setLowerBound(rangeLowerBound); } if (rangeUpperBound != null) { valueAxis.setUpperBound(rangeUpperBound); } if (graphRangeIntegerTick) { valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } valueAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible); // customize the x-axis if (params.get(DOMAIN_AXIS) instanceof CategoryAxis) { CategoryAxis domainAxis = (CategoryAxis) params.get(DOMAIN_AXIS); plot.setDomainAxis(domainAxis); } CategoryAxis domainAxis = plot.getDomainAxis(); Object xAxisFont = params.get(GraphSource.GRAPH_X_AXIS_FONT); Object xAxisLabelFont = params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT); if (xAxisFont instanceof Font) { domainAxis.setTickLabelFont((Font) xAxisFont); } if (xAxisLabelFont instanceof Font) { domainAxis.setLabelFont((Font) xAxisLabelFont); } domainAxis.setLabel(xLabel); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); // change the font of the graph title Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT); TextTitle textTitle = new TextTitle(); textTitle.setText(title); textTitle.setFont(titleFont); chart.setTitle(textTitle); // makes a wrapper for the legend to remove the border around it boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND); boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER); Object legendFont = params.get(GraphSource.LEGEND_FONT); if (legend) { LegendTitle legendTitle = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); if (legendBorder) { wrapper.setFrame(new BlockBorder(1, 1, 1, 1)); } else { wrapper.setFrame(new BlockBorder(0, 0, 0, 0)); } BlockContainer items = legendTitle.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legendTitle.setWrapper(wrapper); legendTitle.setPosition(RectangleEdge.BOTTOM); legendTitle.setHorizontalAlignment(HorizontalAlignment.CENTER); if (legendFont instanceof Font) { legendTitle.setItemFont((Font) legendFont); } chart.addSubtitle(legendTitle); } this.initialized = true; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.SimpleBar.java
public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1"); PlotOrientation plotOrientation = PlotOrientation.VERTICAL; if (horizontalView) { plotOrientation = PlotOrientation.HORIZONTAL; }/*from w ww .j a v a 2s . c o m*/ JFreeChart chart = ChartFactory.createBarChart(name, // chart title categoryLabel, // domain axis label valueLabel, // range axis label dataset, // data plotOrientation, // orientation false, // include legend true, // tooltips? false // URLs? ); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } // set the background color for the chart... chart.setBackgroundPaint(color); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); NumberFormat nf = NumberFormat.getNumberInstance(locale); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); rangeAxis.setUpperMargin(0.10); rangeAxis.setNumberFormatOverride(nf); if (firstAxisLB != null && firstAxisUB != null) { rangeAxis.setLowerBound(firstAxisLB); rangeAxis.setUpperBound(firstAxisUB); } if (rangeIntegerValues == true) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } else rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); if (rangeAxisLocation != null) { if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT); } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) { plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); } } // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // add CategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator("{0}"); renderer.setLegendItemLabelGenerator(generator); if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth.doubleValue()); } if (showValueLabels) { renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); // if(valueLabelsPosition.equalsIgnoreCase("inside")){ // renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); // renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); // } else { // renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); // renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition( // ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT)); // } } // PROVA LEGENDA if (legend == true) { drawLegend(chart); /*BlockContainer wrapper = new BlockContainer(new BorderArrangement()); wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0)); LabelBlock titleBlock = new LabelBlock("Legend Items:", new Font("SansSerif", Font.BOLD, 12)); title.setPadding(5, 5, 5, 5); wrapper.add(titleBlock, RectangleEdge.TOP); LegendTitle legend = new LegendTitle(chart.getPlot()); BlockContainer items = legend.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legend.setWrapper(wrapper); if(legendPosition.equalsIgnoreCase("bottom")) legend.setPosition(RectangleEdge.BOTTOM); else if(legendPosition.equalsIgnoreCase("left")) legend.setPosition(RectangleEdge.LEFT); else if(legendPosition.equalsIgnoreCase("right")) legend.setPosition(RectangleEdge.RIGHT); else if(legendPosition.equalsIgnoreCase("top")) legend.setPosition(RectangleEdge.TOP); else legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); chart.addSubtitle(legend);*/ } int seriesN = dataset.getRowCount(); // the order color vedctor overrides the color map!! if (orderColorVector != null && orderColorVector.size() > 0) { logger.debug("color serie by SERIES_ORDER_COLORS template specification"); for (int i = 0; i < seriesN; i++) { if (orderColorVector.get(i) != null) { Color color = orderColorVector.get(i); renderer.setSeriesPaint(i, color); } } } else if (colorMap != null) { logger.debug("color serie by SERIES_COLORS template specification"); for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getRowKey(i); String labelName = ""; int index = -1; if (seriesCaptions != null && seriesCaptions.size() > 0) { labelName = serieName; serieName = (String) seriesCaptions.get(serieName); index = dataset.getRowIndex(labelName); } else index = dataset.getRowIndex(serieName); Color color = (Color) colorMap.get(serieName); if (color != null) { //renderer.setSeriesPaint(i, color); renderer.setSeriesPaint(index, color); renderer.setSeriesItemLabelFont(i, new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize())); renderer.setSeriesItemLabelPaint(i, defaultLabelsStyle.getColor()); } } } CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setLabelPaint(styleYaxesLabels.getColor()); domainAxis .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setTickLabelPaint(styleYaxesLabels.getColor()); domainAxis.setUpperMargin(0.10); logger.debug("OUT"); return chart; }