List of usage examples for org.jfree.chart.labels ItemLabelPosition ItemLabelPosition
public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, TextAnchor textAnchor)
From source file:forms.frDados.java
/** * Inicializa o grfico de velocidade./*from w w w. j a va2s. com*/ */ private void initSatVelox() { dadosGraficoVelox.clear(); veloxPlot = ChartFactory.createLineChart("Velocidade", "Hora", "Velocidade KM/h", dadosGraficoVelox, PlotOrientation.VERTICAL, false, true, false); veloxPlot.getTitle().setFont(Font.decode("arial-16")); veloxPlot.getTitle().setPadding(5, 20, 5, 20); veloxPlot.setPadding(new RectangleInsets(10, 10, 0, 10)); ChartPanel cp = new ChartPanel(veloxPlot); cp.setBorder(LineBorder.createGrayLineBorder()); LineAndShapeRenderer br = (LineAndShapeRenderer) veloxPlot.getCategoryPlot().getRenderer(); br.setBaseItemLabelsVisible(true); br.setSeriesItemLabelFont(0, Font.decode("arial-12")); br.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); br.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER)); veloxPlot.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); //veloxPlot.getCategoryPlot().getRangeAxis().setRange(new Range(0,100), true,true); pnlChartSpeed.setLayout(new BorderLayout()); pnlChartSpeed.add(cp, BorderLayout.CENTER); }
From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java
private void writeWinningScoreDifferenceSummaryChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { ScoreDefinition scoreDefinition = solverBenchmark.getSolverConfig().getScoreDirectorFactoryConfig() .buildScoreDefinition(); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { Score score = singleBenchmark.getWinningScoreDifference(); Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score); String solverLabel = solverBenchmark.getName(); if (solverBenchmark.isRankingBest()) { solverLabel += " (winner)"; }//from w ww. j ava 2 s . c o m String planningProblemLabel = singleBenchmark.getProblemBenchmark().getName(); dataset.addValue(scoreGraphValue, solverLabel, planningProblemLabel); } } } CategoryAxis xAxis = new CategoryAxis("Data"); xAxis.setCategoryMargin(0.40); NumberAxis yAxis = new NumberAxis("Winning score difference"); BarRenderer renderer = new BarRenderer(); ItemLabelPosition positiveItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(positiveItemLabelPosition); ItemLabelPosition negativeItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(negativeItemLabelPosition); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Winning score difference summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); winningScoreDifferenceSummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "winningScoreDifferenceSummary.png"); OutputStream out = null; try { out = new FileOutputStream(winningScoreDifferenceSummaryFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException( "Problem writing winningScoreDifferenceSummaryFile: " + winningScoreDifferenceSummaryFile, e); } finally { IOUtils.closeQuietly(out); } }
From source file:jmemorize.gui.swing.panels.HistoryChartPanel.java
private void setupRenderer(CategoryPlot plot) { DecimalFormat format = new DecimalFormat("####"); format.setNegativePrefix(""); StackedBarRenderer renderer = new StackedBarRenderer(); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", format)); renderer.setItemLabelsVisible(true); renderer.setPositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.HALF_ASCENT_CENTER)); renderer.setSeriesPaint(0, ColorConstants.EXPIRED_CARDS); renderer.setSeriesPaint(1, ColorConstants.RELEARNED_CARDS); renderer.setSeriesPaint(2, ColorConstants.LEARNED_CARDS); renderer.setMaximumBarWidth(0.2);/*w w w. j a va 2 s . c o m*/ CategoryItemRenderer renderer2 = new LineAndShapeRenderer(true, false); renderer2.setSeriesPaint(0, new Color(75, 150, 200)); plot.setRenderer(1, renderer2); plot.setRenderer(renderer); }
From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java
public static JFreeChart createChart1(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("", // chart title "X-value", // domain axis label "Y-value", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*from ww w. j a va 2s . com*/ // 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 = (CategoryPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setCategoryMargin(0.1);// categoryAxis.setUpperMargin(0.02); categoryAxis.setLowerMargin(0.02); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // 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); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); renderer.setItemLabelAnchorOffset(10D); renderer.setItemLabelFont(new Font("", Font.PLAIN, 12)); renderer.setItemLabelsVisible(true); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 180)); // OPTIONAL CUSTOMISATION COMPLETED. chart.getTitle().setFont(new Font("", Font.BOLD, 16));// // domainAxis.setLabelFont(new Font("", Font.BOLD, 14)); // domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10)); // rangeAxis.setLabelFont(new Font("", Font.BOLD, 15)); chart.getLegend().setItemFont(new Font("", Font.BOLD, 15)); /** * chart.getTitle().setFont(new Font("",Font.BOLD,20));// // domainAxis.setLabelFont(new Font("",Font.BOLD,14)); // domainAxis.setTickLabelFont(new Font("",Font.BOLD,12)); // rangeAxis.setLabelFont(new Font("",Font.BOLD,15)); chart.getLegend().setItemFont(new Font("", Font.BOLD, 15)); */ return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createBarChart(CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); BarRenderer renderer = new BarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setBaseNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(position2); }/*ww w .j a v a 2 s. co m*/ if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Bar Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setDrawBarOutline(false); 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); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); categoryAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHistogram.java
protected void resetRenderer(final IScope scope, final String serieid) { // AbstractCategoryItemRenderer // newr=(AbstractCategoryItemRenderer)this.getOrCreateRenderer(scope, // serieid);//from w w w . j av a 2s . com final CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); final AbstractCategoryItemRenderer newr = (AbstractCategoryItemRenderer) plot.getRenderer(); // if // (serieid!=this.getChartdataset().series.keySet().iterator().next()) // newr=(AbstractCategoryItemRenderer)this.getOrCreateRenderer(scope, // serieid); final ChartDataSeries myserie = this.getChartdataset().getDataSeries(scope, serieid); if (!IdPosition.containsKey(serieid)) { // DEBUG.LOG("pb!!!"); } else { final int myrow = IdPosition.get(serieid); if (myserie.getMycolor() != null) { newr.setSeriesPaint(myrow, myserie.getMycolor()); } if (this.series_label_position.equals("onchart")) { // ((BarRenderer)newr).setBaseItemLabelGenerator(new // LabelGenerator()); newr.setBaseItemLabelGenerator(new LabelGenerator()); final ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); newr.setBasePositiveItemLabelPosition(itemlabelposition); newr.setBaseNegativeItemLabelPosition(itemlabelposition); newr.setBaseItemLabelsVisible(true); } if (newr instanceof BarRenderer) { if (gap >= 0) { ((BarRenderer) newr).setMaximumBarWidth(1 - gap); } } } }
From source file:forms.frDados.java
/** * Inicializa o grfico de intensidade de sinal dos satlites. *///from w ww. j a va2 s . com private void initSatGrafico() { dadosGraficoSats.clear(); plot = ChartFactory.createBarChart("Intensidade do sinal", "PRN", "SNR", dadosGraficoSats, PlotOrientation.VERTICAL, false, true, true); plot.getTitle().setFont(Font.decode("arial-16")); plot.getTitle().setPadding(5, 20, 5, 20); plot.setPadding(new RectangleInsets(10, 10, 0, 10)); //plot.setBackgroundPaint(new Color(255,255,255,0)); BarRenderer br = (BarRenderer) plot.getCategoryPlot().getRenderer(); br.setSeriesPaint(0, Color.BLUE); br.setMaximumBarWidth(0.05); plot.getCategoryPlot().getRangeAxis().setRange(new Range(0, 50), true, true); br.setBaseItemLabelsVisible(true); br.setSeriesItemLabelFont(0, Font.decode("arial-12")); br.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); br.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER)); SpringLayout lm = new SpringLayout(); ChartPanel cp = new ChartPanel(plot); cp.setBorder(LineBorder.createGrayLineBorder()); lm.putConstraint(SpringLayout.EAST, pnlSatPlot, 10, SpringLayout.EAST, cp); lm.putConstraint(SpringLayout.WEST, cp, 10, SpringLayout.WEST, pnlSatPlot); lm.putConstraint(SpringLayout.SOUTH, pnlSatPlot, 10, SpringLayout.SOUTH, cp); lm.putConstraint(SpringLayout.NORTH, cp, 10, SpringLayout.NORTH, pnlSatPlot); pnlSatPlot.setLayout(lm); pnlSatPlot.add(cp); }
From source file:jmemorize.gui.swing.panels.DeckChartPanel.java
private JFreeChart createChart() { m_dataset = createDefaultDataSet();/*from www.j a va 2 s .co m*/ JFreeChart chart = ChartFactory.createStackedBarChart3D(null, // chart title null, // domain axis label Localization.get("DeckChart.CARDS"), // range axis label //$NON-NLS-1$ m_dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // include legend true, // tooltips false // urls ); // setup legend // TODO we used to do this for the old jfreechar version, but it's not clear why. // can we get rid of it? LegendTitle legend = chart.getLegend(); // legend.setsetRenderingOrder(LegendRenderingOrder.REVERSE); legend.setItemFont(legend.getItemFont().deriveFont(11f)); // setup plot CategoryPlot plot = (CategoryPlot) chart.getPlot(); TickUnitSource tickUnits = NumberAxis.createIntegerTickUnits(); plot.getRangeAxis().setStandardTickUnits(tickUnits); //CHECK use locale plot.setForegroundAlpha(0.99f); // setup renderer m_barRenderer = new MyBarRenderer(); m_barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); m_barRenderer.setItemLabelsVisible(true); m_barRenderer .setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); plot.setRenderer(m_barRenderer); setSeriesPaint(); return chart; }
From source file:sim.app.antsvoronoi.AntsVoronoiWithUI.java
public JFrame createBarChartFrame() { barChart = new BarChartGenerator(); barChart.setTitle("Number of Food Closest to Each Ant Hill"); barChart.setYAxisLabel("Food Counts"); barChart.setXAxisLabel("Ant Hill"); CategoryPlot plot = barChart.getChart().getCategoryPlot(); ValueAxis axis = plot.getRangeAxis(); axis.setLowerBound(0);/*from ww w.j a va2 s.c o m*/ AntsForageVoronoi af = (AntsForageVoronoi) state; axis.setUpperBound(af.numFood * .75); BarRenderer renderer = new BarRenderer(); renderer = (BarRenderer) plot.getRenderer(); ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER);//, TextAnchor.BOTTOM_CENTER, 0.0); renderer.setPositiveItemLabelPosition(position); renderer.setNegativeItemLabelPosition(position); plot.setRenderer(renderer); barChartFrame = barChart.createFrame(); barChartFrame.setVisible(true); barChartFrame.setTitle("Bar Chart"); return barChartFrame; }
From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java
private void writeTimeSpendSummaryChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long timeMillisSpend = singleBenchmark.getTimeMillisSpend(); String solverLabel = solverBenchmark.getName(); if (solverBenchmark.isRankingBest()) { solverLabel += " (winner)"; }/*from w w w . j a v a 2 s. c o m*/ String planningProblemLabel = singleBenchmark.getProblemBenchmark().getName(); dataset.addValue(timeMillisSpend, solverLabel, planningProblemLabel); } } } CategoryAxis xAxis = new CategoryAxis("Data"); NumberAxis yAxis = new NumberAxis("Time spend"); yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat()); BarRenderer renderer = new BarRenderer(); ItemLabelPosition positiveItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(positiveItemLabelPosition); ItemLabelPosition negativeItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(negativeItemLabelPosition); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new MillisecondsSpendNumberFormat())); renderer.setBaseItemLabelsVisible(true); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Time spend summary (lower time is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); timeSpendSummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "timeSpendSummary.png"); OutputStream out = null; try { out = new FileOutputStream(timeSpendSummaryFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException("Problem writing timeSpendSummaryFile: " + timeSpendSummaryFile, e); } finally { IOUtils.closeQuietly(out); } }