List of usage examples for org.jfree.chart.axis CategoryAxis setCategoryLabelPositions
public void setCategoryLabelPositions(CategoryLabelPositions positions)
From source file:lospolloshermanos.BarChart.java
/** * Creates a sample chart./* w ww. j av a2 s .c o m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = null; if (Title.equals("Categories")) { chart = ChartFactory.createBarChart("Sales Chart for Categories vs Quantity", // chart title "Categories", // domain axis label "Quantity", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); } else if (Title.equals("Categories 2")) { chart = ChartFactory.createBarChart("Sales Chart for Categories Vs Total Amount", // chart title "Categories", // domain axis label "Sub Total", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); } else if (Title.equals("Items")) { chart = ChartFactory.createBarChart("Top 5 items vs Quantity sales ", // chart title "Items", // domain axis label "Quantity", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); } else if (Title.equals("Items 2")) { chart = ChartFactory.createBarChart("Top 5 items vs Quantity sales ", // chart title "Items", // domain axis label "Sub Total", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); } else if (Title.equals("Ratings")) { chart = ChartFactory.createBarChart("Ratings ", // chart title "Type", // domain axis label "Rating Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:gg.view.categoriesbalances.GraphCategoriesBalancesTopComponent.java
/** * Displays the categories/sub-categories' balances by period * @param balances Categories' balances/*from w w w. j av a2s.c o m*/ */ private void displayData(Map<Long, Map<SearchCriteria, BigDecimal>> balances) { log.info("Categories' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the categories/sub-categories' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphCategoriesBalancesTopComponent.class, "GraphAccountsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelCategoriesBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for each category/sub-category displayed in the table for (Long categoryId : balances.keySet()) { Category category = Wallet.getInstance().getCategoriesWithId().get(categoryId); assert (category != null); SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>( balances.get(categoryId).keySet()); for (SearchCriteria searchCriteria : sortedSearchCriteria) { if ((!searchCriteria.hasCategoriesFilter() && category.isTopCategory() && !category.getSystemProperty()) || searchCriteria.getCategories().contains(category)) { BigDecimal balance = new BigDecimal(0); if (balances.get(categoryId) != null && balances.get(categoryId).get(searchCriteria) != null) { balance = balances.get(categoryId).get(searchCriteria); } dataset.addValue(balance, category.getName(), searchCriteria.getPeriod()); } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelCategoriesBalances.removeAll(); jPanelCategoriesBalances.add(chartPanel, BorderLayout.CENTER); jPanelCategoriesBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:gg.view.accountsbalances.GraphAccountsBalancesTopComponent.java
/** * Displays the accounts' balances by period * @param balances Accounts' balances//w w w. j a v a2 s.co m */ private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) { log.info("Accounts' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the accounts' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphAccountsBalancesTopComponent.class, "AccountsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelAccountsBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for each account displayed in the table for (MoneyContainer moneyContainer : balances.keySet()) { if (moneyContainer instanceof Account) { Account account = (Account) moneyContainer; SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>( balances.get(account).keySet()); for (SearchCriteria searchCriteria : sortedSearchCriteria) { if (!searchCriteria.hasAccountsFilter() || searchCriteria.getAccounts().contains(account)) { dataset.addValue(balances.get(moneyContainer).get(searchCriteria), account.toString(), searchCriteria.getPeriod()); } } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelAccountsBalances.removeAll(); jPanelAccountsBalances.add(chartPanel, BorderLayout.CENTER); jPanelAccountsBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:gg.view.movementsbalances.GraphMovementsBalancesTopComponent.java
/** * Displays the accounts' movements balances by period * @param searchFilters Search filter objects (one per period) for which the movements balances are wanted *///from ww w .java2s.c o m private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) { log.info("Movements' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the movements' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphMovementsBalancesTopComponent.class, "GraphMovementsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelMovementsBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for (MoneyContainer moneyContainer : balances.keySet()) { if (moneyContainer instanceof Account) { SortedSet<SearchCriteria> sortedSearchFilters = new TreeSet<SearchCriteria>( balances.get(moneyContainer).keySet()); for (SearchCriteria searchCriteria : sortedSearchFilters) { BigDecimal accountBalance = balances.get(moneyContainer).get(searchCriteria); accountBalance = accountBalance.setScale(2, RoundingMode.HALF_EVEN); dataset.addValue(accountBalance, moneyContainer.toString(), searchCriteria.getPeriod()); } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelMovementsBalances.removeAll(); jPanelMovementsBalances.add(chartPanel, BorderLayout.CENTER); jPanelMovementsBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:RDGraphGenerator.java
/** * Creates a sample chart.//from w w w . ja va2s . 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:hudson.graph.jfreechart.JFreeChartSupport.java
public JFreeChart createChart() { if (chartType == Graph.TYPE_STACKED_AREA) { jFreeChart = ChartFactory.createStackedAreaChart(null, // chart chartTitle, // // title xAxisLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );/*from w ww . jav a 2 s. c o m*/ } else if (chartType == Graph.TYPE_LINE) { jFreeChart = ChartFactory.createLineChart(null, // chart title chartTitle, // // title xAxisLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); } jFreeChart.setBackgroundPaint(Color.white); final CategoryPlot plot = jFreeChart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); // plot.setDomainGridlinesVisible(true); // plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); if (chartType == Graph.TYPE_LINE) { final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(3)); if (multiStageTimeSeries != null) { for (int i = 0; i < multiStageTimeSeries.size(); i++) { renderer.setSeriesPaint(i, multiStageTimeSeries.get(i).color); } } } CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); Utils.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (chartType == Graph.TYPE_STACKED_AREA) { StackedAreaRenderer ar = new StackedAreaRenderer2() { @Override public Paint getItemPaint(int row, int column) { if (row == 2) { return ColorPalette.BLUE; } if (row == 1) { return ColorPalette.YELLOW; } if (row == 0) { return ColorPalette.RED; } ChartLabel key = (ChartLabel) dataset.getColumnKey(column); return key.getColor(row, column); } @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getLink(row, column); } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getToolTip(row, column); } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Failures. ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skips. ar.setSeriesPaint(2, ColorPalette.BLUE); // Total. } // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return jFreeChart; }
From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreateBarChartView.java
/** * Creates a sample chart./* w ww .j av a 2 s .c o m*/ * * @param dataset the dataset. * @return The chart. */ private JFreeChart createChart(CategoryDataset dataset, int typeOfChart) { String title = ""; if (typeOfChart == 1) title = VCTTracUtil.getMessage("vcttrac.graph.statistic.compare.todayandyesterday", null); else if (typeOfChart == 2) title = VCTTracUtil.getMessage("vcttrac.year", null) + " : " + (new Date().getYear() + 1900); else if (typeOfChart == 3) title = VCTTracUtil.getMessage("vcttrac.graph.statistic.years", null); // create the chart... JFreeChart chart = ChartFactory.createBarChart(title, null, null, // chart title dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); Paint[] colors = createPaint(); CustomBarRenderer renderer = new CustomBarRenderer(colors); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); plot.setRenderer(renderer); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.15); // CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 12)); if (typeOfChart < 2) domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); else domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.AreaChartDemo1.java
/** * Creates a Area chart./* w ww . j a v a 2 s. c o m*/ * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createAreaChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); if (isDemo) { TextTitle subtitle = new TextTitle("An area chart demonstration. We use this subtitle as an " + "example of what happens when you get a really long title or " + "subtitle."); subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12)); subtitle.setPosition(RectangleEdge.TOP); subtitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05, 0.05, 0.05, 0.05)); subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM); chart.addSubtitle(subtitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); AreaRenderer renderer = (AreaRenderer) plot.getRenderer(); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); if (isDemo) { domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); } NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); return chart; }
From source file:dk.sdu.mmmi.featureous.views.featurecharacterization.FeatureViewChart.java
public FeatureViewChart(List<TraceModel> ftms, final boolean pkg) { this.pkg = pkg; data = new DefaultCategoryDataset(); chart = ChartFactory.createStackedBarChart("Feature characterization", "Feature", "Scattering", data, PlotOrientation.VERTICAL, true, false, false); plot = (CategoryPlot) chart.getPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); xAxis.setMaximumCategoryLabelLines(2); // 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);/*w ww .j a v a 2 s. c o m*/ // chart.removeLegend(); panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.white); this.ftms = ftms; scattering = new ArrayList<Result>( new StaticScattering(pkg).calculateAndReturnAll(new HashSet<TraceModel>(ftms), null)); Result.sortByName(scattering); for (Result r : scattering) { // OutputUtil.log(r.name + ";" +r.value); } panel.getPopupMenu().setEnabled(false);//add(SVGExporter.createExportAction(chart, panel)); StackedBarRenderer r2 = 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); } } }; plot.setRenderer(r2, true); StackedBarRenderer r = (StackedBarRenderer) plot.getRenderer(); r.setDrawBarOutline(true); plot.getRenderer().setOutlineStroke(new BasicStroke(0.1f)); Controller.getInstance().getTraceSet().getSelectionManager().addSelectionListener(this); }
From source file:j2se.jfreechart.barchart.BarChart3DDemo2.java
/** * Creates a chart./*w ww.ja va 2s . com*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart3D("3D Bar Chart Demo 2", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips false // urls ); final CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(1.0f); // left align the category labels... final CategoryAxis axis = plot.getDomainAxis(); final CategoryLabelPositions p = axis.getCategoryLabelPositions(); final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f); axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left)); return chart; }