List of usage examples for org.jfree.chart.axis CategoryAxis setLabelFont
public void setLabelFont(Font font)
From source file:org.toobsframework.pres.chart.ChartUtil.java
public static CategoryAxis createCategoryAxis(IRequest componentRequest, DomainAxisDef categoryAxisDef, Map params, boolean is3D) { CategoryAxis categoryAxis; if (is3D) {/*from w w w . j a v a 2s. co m*/ categoryAxis = new CategoryAxis3D(); } else { categoryAxis = new CategoryAxis(); } if (categoryAxisDef != null) { if (categoryAxisDef.getDomainLabel() != null) { categoryAxis .setLabel(evaluateTextLabel(componentRequest, categoryAxisDef.getDomainLabel(), params)); if (categoryAxisDef.getDomainLabel().getFont() != null) { categoryAxis.setLabelFont(getFont(categoryAxisDef.getDomainLabel(), null)); } categoryAxis.setLabelPaint(getColor(categoryAxisDef.getDomainLabel().getColor())); } if (categoryAxisDef.getLabelPosition() != null) { Integer labelPos = domainLabelPositions.get(ParameterUtil.resolveParam(componentRequest, categoryAxisDef.getLabelPosition(), params, "standard")[0]); if (labelPos != null) { switch (labelPos) { case DOM_LABEL_STANDARD_TYPE: categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); break; case DOM_LABEL_UP_45_TYPE: categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); break; case DOM_LABEL_DOWN_45_TYPE: categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); break; case DOM_LABEL_UP_90_TYPE: categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); break; case DOM_LABEL_DOWN_90_TYPE: categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); break; } } } double domainMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest, categoryAxisDef.getDomainMargin(), params, "0.0")[0]); double lowerMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest, categoryAxisDef.getLowerMargin(), params, "0.0")[0]); double upperMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest, categoryAxisDef.getUpperMargin(), params, "0.0")[0]); categoryAxis.setCategoryMargin(domainMargin); categoryAxis.setLowerMargin(lowerMargin); categoryAxis.setUpperMargin(upperMargin); } return categoryAxis; }
From source file:org.amanzi.awe.charts.builder.StackedChartBuilder.java
@Override public JFreeChart createChart() throws ModelException { CategoryDatasetContainer dataset = new CategoryDatasetContainer(getModel()); dataset.computeDatasets();/* www . j a v a 2 s . c om*/ JFreeChart chart = ChartFactory.createStackedBarChart(getModel().getName(), // chart // title getModel().getDomainAxisName(), getModel().getMainRangeAxis().getName(), dataset.getDataset(getModel().getMainRangeAxis()), getModel().getPlotOrientation(), true, true, false); CategoryPlot plot = ((CategoryPlot) chart.getPlot()); plot.setRenderer(new StackedBarRenderer3D()); CategoryAxis axis = plot.getDomainAxis(); axis.setTickLabelFont(getDefaulTickLabelFont()); axis.setLabelFont(getDefaultAxisFont()); chart.addSubtitle(getSubTitle(Messages.clickItemToDrillDown)); return chart; }
From source file:org.jfree.chart.demo.IntervalBarChartDemo1.java
/** * Creates a new demo./* w w w .j av a2s.c o m*/ */ public IntervalBarChartDemo1() { DefaultIntervalCategoryDataset data = null; final double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } }; final double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } }; data = new DefaultIntervalCategoryDataset(lows, highs); data.setCategoryKeys(CATEGORIES); final String title = "Strategie Sicherheit"; final String xTitle = "Zeitraum (in Jahren)"; final String yTitle = "Performance"; final CategoryAxis xAxis = new CategoryAxis(xTitle); xAxis.setLabelFont(titleFont); xAxis.setTickLabelFont(labelFont); xAxis.setTickMarksVisible(false); final NumberAxis yAxis = new NumberAxis(yTitle); yAxis.setLabelFont(titleFont); yAxis.setTickLabelFont(labelFont); yAxis.setRange(-0.2, 0.40); final DecimalFormat formatter = new DecimalFormat("0.##%"); yAxis.setTickUnit(new NumberTickUnit(0.05, formatter)); final IntervalBarRenderer renderer = new IntervalBarRenderer(); renderer.setSeriesPaint(0, new Color(51, 102, 153)); // renderer.setLabelGenerator(new IntervalCategoryLabelGenerator()); renderer.setItemLabelsVisible(true); renderer.setItemLabelPaint(Color.white); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER); renderer.setPositiveItemLabelPosition(p); final CategoryPlot plot = new CategoryPlot(data, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setOutlinePaint(Color.white); plot.setOrientation(PlotOrientation.VERTICAL); this.chart = new JFreeChart(title, titleFont, plot, false); this.chart.setBackgroundPaint(Color.white); }
From source file:org.javarebel.chart.generator.ChartGenerator.java
protected void configureAxis(CategoryAxis axis, DefaultAxisConfig config) { axis.setCategoryLabelPositions(config.getLabelPosition()); axis.setLabelFont(config.getLabelFont()); axis.setTickLabelFont(config.getTickLabelFont()); axis.setLowerMargin(config.getLowerMargin()); axis.setUpperMargin(config.getUpperMargin()); axis.setCategoryMargin(config.getCategoryMargin()); }
From source file:org.jfree.chart.demo.OverlaidCategoryChartDemo.java
/** * Creates a new demo.//from w ww . j a v a2 s. c o m * * @param title the frame title. */ public OverlaidCategoryChartDemo(String title) { super(title); DefaultIntervalCategoryDataset barData = null; double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } }; double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } }; barData = new DefaultIntervalCategoryDataset(lows, highs); double[][] vals = { { 0.0808, 0.0808, 0.0808, 0.0808, 0.0808 } }; CategoryDataset dotData = DatasetUtilities.createCategoryDataset("Series ", "Category ", vals); double[][] lineVals = new double[4][5]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 5; j++) { lineVals[i][j] = (Math.random() * 0.56) - 0.18; } } CategoryDataset lineData = DatasetUtilities.createCategoryDataset("Series ", "Category ", lineVals); String ctitle = "Strategie Sicherheit"; String xTitle = "Zeitraum (in Jahren)"; String yTitle = "Performance"; CategoryAxis xAxis = new CategoryAxis(xTitle); xAxis.setLabelFont(titleFont); xAxis.setTickLabelFont(labelFont); xAxis.setTickMarksVisible(false); NumberAxis yAxis = new NumberAxis(yTitle); yAxis.setLabelFont(titleFont); yAxis.setTickLabelFont(labelFont); yAxis.setRange(-0.2, 0.4); DecimalFormat formatter = new DecimalFormat("0.##%"); yAxis.setTickUnit(new NumberTickUnit(0.05, formatter)); IntervalBarRenderer barRenderer = new IntervalBarRenderer(); barRenderer.setItemLabelsVisible(Boolean.TRUE); CategoryPlot plot = new CategoryPlot(barData, xAxis, yAxis, barRenderer); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); plot.setBackgroundPaint(Color.lightGray); plot.setOutlinePaint(Color.black); LineAndShapeRenderer dotRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES); dotRenderer.setItemLabelsVisible(Boolean.TRUE); plot.setSecondaryDataset(0, dotData); plot.setSecondaryRenderer(0, dotRenderer); LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES_AND_LINES); plot.setSecondaryDataset(1, lineData); plot.setSecondaryRenderer(1, lineRenderer); this.chart = new JFreeChart(ctitle, titleFont, plot, false); this.chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(this.chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:com.netsteadfast.greenstep.action.CommonBarChartAction.java
private void fillChart(String title, String categoryLabel, String valueLabel, List<String> names, List<Float> values, List<String> colors, boolean horizontal) throws Exception { DefaultCategoryDataset data = new DefaultCategoryDataset(); for (int ix = 0; ix < names.size(); ix++) { data.addValue(values.get(ix), "", names.get(ix)); }//w w w.j a va2 s .co m this.chart = ChartFactory.createBarChart3D(title, // title categoryLabel, valueLabel, data, (horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL), false, false, false); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9)); categoryAxis.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 9)); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9)); this.setPlotColor(plot, names, colors); this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9))); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.linecharts.LineChart.java
public JFreeChart createChart() { logger.debug("IN"); CategoryPlot plot = new CategoryPlot(); NumberAxis rangeAxis = new NumberAxis("Kpi Values"); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12)); Color colorLabel = Color.decode("#000000"); rangeAxis.setLabelPaint(colorLabel); rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); rangeAxis.setTickLabelPaint(colorLabel); plot.setRangeAxis(rangeAxis);//from ww w .jav a 2 s .c o m CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setLabelPaint(colorLabel); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setTickLabelPaint(colorLabel); plot.setDomainAxis(domainAxis); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); //I create a line renderer MyStandardCategoryItemLabelGenerator generator = null; LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(); lineRenderer.setShapesFilled(true); lineRenderer.setBaseItemLabelGenerator(generator); lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12)); lineRenderer.setBaseItemLabelPaint(colorLabel); lineRenderer.setBaseItemLabelsVisible(true); DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line"); for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) { String serName = (String) iterator.next(); String labelName = ""; int index = -1; index = datasetLine.getRowIndex(serName); Color color = Color.decode("#990200"); lineRenderer.setSeriesPaint(index, color); } plot.setDataset(0, datasetLine); plot.setRenderer(0, lineRenderer); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); JFreeChart chart = new JFreeChart(plot); logger.debug("Chart created"); TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.setTitle(title); TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle); TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle2); chart.removeLegend(); chart.setBackgroundPaint(Color.white); logger.debug("OUT"); return chart; }
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.trendcharts.LineChart.java
public JFreeChart createChart() { logger.debug("IN"); CategoryPlot plot = new CategoryPlot(); IMessageBuilder msgBuilder = MessageBuilderFactory.getMessageBuilder(); String rangeAxisName = msgBuilder.getMessage("sbi.kpi.rangeAxisName"); NumberAxis rangeAxis = new NumberAxis(rangeAxisName); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12)); Color colorLabel = Color.decode("#000000"); rangeAxis.setLabelPaint(colorLabel); rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); rangeAxis.setTickLabelPaint(colorLabel); plot.setRangeAxis(rangeAxis);/* w w w . j ava2 s. co m*/ CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setLabelPaint(colorLabel); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setTickLabelPaint(colorLabel); plot.setDomainAxis(domainAxis); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); //I create a line renderer MyStandardCategoryItemLabelGenerator generator = null; LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(); lineRenderer.setShapesFilled(true); lineRenderer.setBaseItemLabelGenerator(generator); lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12)); lineRenderer.setBaseItemLabelPaint(colorLabel); lineRenderer.setBaseItemLabelsVisible(true); DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line"); for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) { String serName = (String) iterator.next(); String labelName = ""; int index = -1; index = datasetLine.getRowIndex(serName); Color color = Color.decode("#990200"); lineRenderer.setSeriesPaint(index, color); } plot.setDataset(0, datasetLine); plot.setRenderer(0, lineRenderer); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); JFreeChart chart = new JFreeChart(plot); logger.debug("Chart created"); TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.setTitle(title); TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle); TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle2); chart.removeLegend(); chart.setBackgroundPaint(Color.white); logger.debug("OUT"); return chart; }
From source file:uk.ac.lkl.cram.ui.chart.FeedbackChartMaker.java
/** * Create a chart from the provided category dataset * @return a Chart that can be rendered in a ChartPanel *///from w ww. j a va2 s . c o m @Override protected JFreeChart createChart() { //Create a vertical bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs JFreeChart chart = ChartFactory.createBarChart(null, null, null, (CategoryDataset) dataset, PlotOrientation.VERTICAL, true, true, false); //Get the font from the platform UI Font chartFont = UIManager.getFont("Label.font"); //Get the plot from the chart CategoryPlot plot = (CategoryPlot) chart.getPlot(); //Get the renderer from the plot BarRenderer barRenderer = (BarRenderer) plot.getRenderer(); //Set the rendered to use a standard bar painter (nothing fancy) barRenderer.setBarPainter(new StandardBarPainter()); //Set the colours for the bars barRenderer.setSeriesPaint(0, PEER_ONLY_COLOR); barRenderer.setSeriesPaint(1, TEL_COLOR); barRenderer.setSeriesPaint(2, TUTOR_COLOR); //Set the tooltip to be series, category and value barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator( "<html><center>{0} ({2} hours)<br/>Double-click for more</center></html>", NumberFormat.getInstance())); //Get the category axis (that's the X-axis in this case) CategoryAxis categoryAxis = plot.getDomainAxis(); //Set the font for rendering the labels on the x-axis to be the platform default categoryAxis.setLabelFont(chartFont); //Hide the tick marks and labels for the x-axis categoryAxis.setTickMarksVisible(false); categoryAxis.setTickLabelsVisible(false); //Set the label for the x-axis categoryAxis.setLabel("Feedback to individuals or group"); //Get the number axis (that's the Y-axis in this case) NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); //Use the same font as the x-axis numberAxis.setLabelFont(chartFont); //Set the label for the vertical axis numberAxis.setLabel("Hours"); return chart; }
From source file:uk.ac.lkl.cram.ui.chart.HoursChartMaker.java
/** * Create a chart from the provided category dataset * @return a Chart that can be rendered in a ChartPanel *//* w w w.j a va 2s . c om*/ @Override protected JFreeChart createChart() { //Create a vertical stacked bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs JFreeChart chart = ChartFactory.createStackedBarChart(null, null, null, (CategoryDataset) dataset, PlotOrientation.VERTICAL, true, true, false); //Get the font from the platform UI Font chartFont = UIManager.getFont("Label.font"); //Get the plot from the chart CategoryPlot plot = (CategoryPlot) chart.getPlot(); //Get the renderer from the plot StackedBarRenderer sbRenderer = (StackedBarRenderer) plot.getRenderer(); //Set the rendered to use a standard bar painter (nothing fancy) sbRenderer.setBarPainter(new StandardBarPainter()); //Set the colours for the bars sbRenderer.setSeriesPaint(0, PREPARATION_COLOR); sbRenderer.setSeriesPaint(1, SUPPORT_COLOR); //Set the tooltip to be series, category and value sbRenderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{0}, {1} ({2})", NumberFormat.getInstance())); //Get the category axis (that's the X-axis in this case) CategoryAxis categoryAxis = plot.getDomainAxis(); //Set the font for rendering the labels on the x-axis to be the platform default categoryAxis.setLabelFont(chartFont); //Get the number axis (that's the Y-axis in this case) NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); //Use the same font as the x-axis numberAxis.setLabelFont(chartFont); return chart; }