List of usage examples for org.jfree.chart.axis CategoryAxis setLabel
public void setLabel(String label)
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartAxisFactory.java
public static CategoryAxis createCategoryDomainAxis(PlotConfiguration plotConfiguration) { CategoryAxis domainAxis = new CategoryAxis(null); String label = plotConfiguration.getDomainConfigManager().getLabel(); if (label == null) { label = I18N.getGUILabel("plotter.unnamed_value_label"); }/*from ww w. jav a 2 s .c o m*/ domainAxis.setLabel(label); Font axesFont = plotConfiguration.getAxesFont(); if (axesFont != null) { domainAxis.setLabelFont(axesFont); domainAxis.setTickLabelFont(axesFont); } // rotate labels if (plotConfiguration.getOrientation() != PlotOrientation.HORIZONTAL) { domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } formatAxis(plotConfiguration, domainAxis); return domainAxis; }
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) {/* w ww. ja v a 2s.c o 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:net.sf.statcvs.output.xml.chart.AbstractStackedChart.java
public void setCategoryAxisLabel(String text) { CategoryPlot plot = getChart().getCategoryPlot(); CategoryAxis axis = (CategoryAxis) plot.getDomainAxis(); axis.setLabel(text); }
From source file:org.sonar.plugins.buildstability.BuildStabilityChart.java
private void configureDomainAxis(CategoryPlot plot, String days) { CategoryAxis categoryAxis = new CategoryAxis(); if (!StringUtils.isBlank(days)) { categoryAxis.setLabel("Last " + days + " days"); }/* w ww . j a v a2 s.co m*/ categoryAxis.setTickLabelsVisible(false); plot.setDomainAxis(categoryAxis); plot.setDomainGridlinesVisible(false); }
From source file:de.berlios.statcvs.xml.chart.AbstractChart.java
/** * @deprecated/* www.jav a 2s . c o m*/ */ public void setCategoryAxisLabel(String text) { CategoryPlot plot = getChart().getCategoryPlot(); CategoryAxis axis = (CategoryAxis) plot.getDomainAxis(); axis.setLabel(text); }
From source file:ch.opentrainingcenter.charts.bar.OTCCategoryChartViewer.java
void updateAxis(final TrainingChart chartType, final XAxisChart chartSerieType) { if (chart != null) { chart.setTitle(chartType.getTitle()); ((CategoryPlot) chart.getPlot()).getRangeAxis().setLabel(chartType.getyAchse()); final CategoryAxis domainAxis = ((CategoryPlot) chart.getPlot()).getDomainAxis(); domainAxis.setLabel(CategoryHelper.getDomainAxis(chartSerieType)); if (XAxisChart.YEAR.equals(chartSerieType) || XAxisChart.YEAR_START_TILL_NOW.equals(chartSerieType)) { domainAxis.setCategoryMargin(-0.75d); } else {/*from w ww . j a va 2s. c o m*/ domainAxis.setCategoryMargin(0.2d); } } }
From source file:org.amanzi.awe.charts.builder.CategoryChartBuilder.java
@Override protected CategoryAxis configDomainAxis(String domainAxisName) { CategoryAxis domainAxis = new CategoryAxis(domainAxisName); domainAxis.setMaximumCategoryLabelWidthRatio(MAXIMUM_CATEGORY_LABEL_WIDTH); domainAxis.setMaximumCategoryLabelLines(MAXIMUM_CATEGORY_LABEL_LINES); domainAxis.setLabel(domainAxisName); domainAxis.setTickLabelFont(getDefaulTickLabelFont()); domainAxis.setLabelFont(getDefaultAxisFont()); return domainAxis; }
From source file:com.pureinfo.srm.reports.impl.CategoryChartBuilder.java
/** * @see com.pureinfo.srm.reports.IChartBuilder#buildChart(java.util.List, * int, java.lang.String)//from w w w . j a va 2s .c o m */ public JFreeChart buildChart() { CategoryDataset dataset = createDataset(); JFreeChart jfreechart = MyChartFactory.createBarChart3D(null, m_sXAxisName, m_sYXxisName, dataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); jfreechart.setBackgroundPaint(Color.white); categoryplot.setDomainGridlinesVisible(false); categoryplot.setRangeGridlinesVisible(true); categoryplot.setForegroundAlpha(0.8f); categoryplot.setDrawingSupplier(new DefaultDrawingSupplier(MyPaintMgr.getPaints(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); CategoryAxis categoryAxisX = categoryplot.getDomainAxis(); categoryAxisX.setTickLabelsVisible(true); categoryAxisX.setLabel(null); categoryAxisX.setMaximumCategoryLabelWidthRatio(.8f); ValueAxis categoryAxisY = categoryplot.getRangeAxis(); categoryAxisY.setVerticalTickLabels(false); // categoryplot.setDrawSharedDomainAxis(false); categoryAxisX.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D)); BarRenderer3D barrenderer3d = (BarRenderer3D) categoryplot.getRenderer(); barrenderer3d.setDrawBarOutline(false); barrenderer3d.setItemLabelsVisible(true); barrenderer3d.setBaseItemLabelsVisible(false); barrenderer3d.setSeriesVisible(Boolean.FALSE); //CategoryPlot categoryPlot = jfreechart.getCategoryPlot(); // categoryPlot.setBackgroundPaint(Color.lightGray); // categoryPlot.setDomainGridlinePaint(Color.white); // categoryPlot.setRangeGridlinePaint(Color.white); // // BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer(); // barRenderer.setDrawBarOutline(false); // barRenderer.setMaxBarWidth(0.03); // GradientPaint gradientPaint = new GradientPaint(0.0F, 0.0F, // Color.red, 0.0F, 0.0F, new Color(64, 0, 0)); // barRenderer.setSeriesPaint(0, gradientPaint); DecimalFormat format = null; if (m_dblMaxData > 1) { format = new DecimalFormat("#,###"); } else { StringBuffer sb = new StringBuffer(); sb.append("0.00#"); for (double i = m_dblMaxData; i != 0 && i < 1; i *= 10f) { sb.append("#"); } format = new DecimalFormat(sb.toString()); } fillChartInfo(dataset, format); barrenderer3d.setMaxBarWidth(8.0 / m_ChartInfo.getChartSize().x); NumberAxis numberAxis = (NumberAxis) categoryplot.getRangeAxis(0); numberAxis.setUpperMargin(0.149999999999D); numberAxis.setNumberFormatOverride(format); categoryAxisX.setCategoryLabelPositions(CategoryLabelPositions.UP_45); NumberAxis dataNumberAxis = (NumberAxis) categoryplot.getRangeAxisForDataset(0); dataNumberAxis.setUpperMargin(0.149999999999D); dataNumberAxis.setNumberFormatOverride(format); // CategoryItemRenderer renderer = categoryPlot.getRenderer(); // CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", format); // renderer.setItemLabelGenerator(generator); // renderer.setItemLabelFont(new Font("Serif", 0, 9)); // renderer.setItemLabelsVisible(true); return jfreechart; }
From source file:dk.sdu.mmmi.featureous.views.codecharacterization.TanglingViewChart.java
public TanglingViewChart(boolean pkg, boolean sortByValue) { this.sortByValue = sortByValue; this.pkg = pkg; data = new DefaultKeyedValues2DDataset(); String title = "Computational unit characterization"; jchart = ChartFactory.createStackedBarChart(title, (pkg) ? "Package" : "Class", "Tangling", data, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) jchart.getPlot(); // chart.getLegend().setPosition(RectangleEdge.RIGHT); // chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP); // chart.getLegend().setHorizontalAlignment(HorizontalAlignment.LEFT); LegendItemCollection lic = new LegendItemCollection(); // lic.add(new LegendItem("Infrastructural unit", "", "", "", new Rectangle(10, 10), Color.GREEN)); // lic.add(new LegendItem("Group-feature unit", "", "", "", new Rectangle(10, 10), Color.BLUE)); // lic.add(new LegendItem("Single-feature unit", "", "", "", new Rectangle(10, 10), Color.RED)); plot.setFixedLegendItems(lic);/*from w w w.ja v a2 s . co m*/ // chart.removeLegend(); plot.setDomainAxis(new SparselyLabeledCategoryAxis(20)); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); xAxis.setLabel((pkg) ? "Package" : "Class"); // xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 5, 5)); // xAxis.setMaximumCategoryLabelLines(1); xAxis.setLowerMargin(0); xAxis.setCategoryMargin(0); xAxis.setUpperMargin(0); // xAxis.setMaximumCategoryLabelWidthRatio(20f); jchart.setBackgroundPaint(Color.white); StackedBarRenderer renderer = new StackedBarRenderer() { @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); double start = plot.getDomainAxis().getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double end = plot.getDomainAxis().getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); String compUnit = data.getRowKey(row).toString(); // Calculate y coeffs double posBase = getBase(); // for(int i = 0; i<row; i++){ // Number val = dataset.getValue(i, column); // if(val!=null){ // posBase = posBase + val.doubleValue(); // } // } Number value = dataset.getValue(row, column); if (value == null) { return; } double val = value.doubleValue(); double translatedBase = plot.getRangeAxis().valueToJava2D(posBase, dataArea, plot.getRangeAxisEdge()); double translatedValue = plot.getRangeAxis().valueToJava2D(posBase + val, dataArea, plot.getRangeAxisEdge()); if (Controller.getInstance().getTraceSet().getSelectionManager().getSelectedClasses() .contains(compUnit) || Controller.getInstance().getTraceSet().getSelectionManager().getSelectedPkgs() .contains(compUnit)) { g2.setPaint(UIUtils.SELECTION_COLOR); g2.setStroke(new BasicStroke(3f)); Line2D l2d = new Line2D.Double(start, translatedBase, start, translatedValue); g2.draw(l2d); l2d = new Line2D.Double(end, translatedBase, end, translatedValue); g2.draw(l2d); l2d = new Line2D.Double(start, translatedBase, end, translatedBase); g2.draw(l2d); l2d = new Line2D.Double(start, translatedValue, end, translatedValue); g2.draw(l2d); } } }; renderer.setToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset cd, int i, int i1) { String key = data.getRowKey(i).toString(); // key = key.substring(0, key.length()-1); return "<html>" + i + " - " + key + "<br>" + Double.toString(cd.getValue(i, i1).doubleValue()) + "</hmtl>"; } }); plot.setRenderer(renderer); panel = new ChartPanel(jchart); panel.getPopupMenu().setEnabled(false);//add(SVGExporter.createExportAction(chart, panel)); createView(); Controller.getInstance().getTraceSet().getSelectionManager().addSelectionListener(this); }
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 v a 2s . c om*/ @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; }