List of usage examples for org.jfree.chart.axis CategoryAxis setMaximumCategoryLabelLines
public void setMaximumCategoryLabelLines(int lines)
From source file:org.jfree.chart.demo.CategoryLabelPositionsDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart("CategoryLabelPositionsDemo1", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setMaximumCategoryLabelLines(0x7fffffff); categoryaxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.78539816339744828D)); return jfreechart; }
From source file:unalcol.termites.boxplots.SucessfulRatesHybrid.java
private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) { JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18)); jfreechart.setBackgroundPaint(new Color(221, 223, 238)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinePaint(Color.gray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer renderer = (BarRenderer) categoryplot.getRenderer(); //categoryplot.setBackgroundPaint(new Color(221, 223, 238)); renderer.setSeriesPaint(0, new Color(130, 165, 70)); renderer.setSeriesPaint(1, new Color(220, 165, 70)); renderer.setSeriesPaint(4, new Color(255, 165, 70)); renderer.setDrawBarOutline(false);/*from ww w .jav a2 s. c om*/ renderer.setShadowVisible(false); // renderer.setMaximumBarWidth(1); renderer.setGradientPaintTransformer(null); renderer.setDefaultBarPainter(new StandardBarPainter()); categoryplot.setRenderer(renderer); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperMargin(0.25D); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null)); numberaxis.setRange(0, 100); //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12); numberaxis.setTickLabelFont(font); CategoryAxis axisd = categoryplot.getDomainAxis(); ValueAxis axisr = categoryplot.getRangeAxis(); axisd.setTickLabelFont(font); axisr.setTickLabelFont(font); axisd.setMaximumCategoryLabelLines(5); final ChartPanel chartPanel = new ChartPanel(jfreechart); chartPanel.setPreferredSize(new java.awt.Dimension(1300, 370)); FileOutputStream output; try { output = new FileOutputStream("sucessrates1" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 1300, 370, null); } catch (FileNotFoundException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } return jfreechart; }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * Creates a JFreeChart based on the current query results produced by the * given chart.//w w w . j a v a2 s .co m * * @param c * The chart from which to produce a JFreeChart component. Must * not be null. * @return A chart based on the data and settings in the given chart, or * null if the given chart is not sufficiently configured (for * example, if its type is not set) or it is currently unable to * produce a result set. */ public static JFreeChart createChartFromQuery(Chart c) throws SQLException, QueryInitializationException, InterruptedException { logger.debug("Creating JFreeChart for Wabit chart " + c); ChartType chartType = c.getType(); if (chartType == null) { logger.debug("Returning null (chart's type is not set)"); return null; } final JFreeChart chart; if (chartType.getDatasetType().equals(DatasetType.CATEGORY)) { JFreeChart categoryChart = createCategoryChart(c); logger.debug("Made a new category chart: " + categoryChart); if (categoryChart != null && categoryChart.getPlot() instanceof CategoryPlot) { double rotationRads = Math.toRadians(c.getXAxisLabelRotation()); CategoryLabelPositions clp; if (Math.abs(rotationRads) < 0.05) { clp = CategoryLabelPositions.STANDARD; } else if (rotationRads < 0) { clp = CategoryLabelPositions.createUpRotationLabelPositions(-rotationRads); } else { clp = CategoryLabelPositions.createDownRotationLabelPositions(rotationRads); } CategoryAxis domainAxis = categoryChart.getCategoryPlot().getDomainAxis(); domainAxis.setMaximumCategoryLabelLines(5); domainAxis.setCategoryLabelPositions(clp); } chart = categoryChart; } else if (chartType.getDatasetType().equals(DatasetType.XY)) { JFreeChart xyChart = createXYChart(c); logger.debug("Made a new XY chart: " + xyChart); chart = xyChart; } else { throw new IllegalStateException("Unknown chart dataset type " + chartType.getDatasetType()); } if (chart != null) { makeChartNice(chart); } return chart; }
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]); }//from ww w .j av a2s .co 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.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:stockit.allStocks.java
private void stockPerfmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stockPerfmActionPerformed // TODO add your handling code here: DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int row = table.getSelectedRow(); if (row != -1) { //dataset.setValue(, "", table.getValueAt(0,1).toString()); String selectedStock = table.getValueAt(row, 0).toString(); try {//w w w . j av a 2 s. com DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); ResultSet rs = stmt .executeQuery("Select stock_daily_performance.Closing_Price, stock_daily_performance.Date\n" + "FROM stock_daily_performance, stock\n" + "WHERE stock_daily_performance.StockID = stock.StockID AND stock.StockID = '" + selectedStock + "'" + "AND Date IN\n" + "( Select * from\n" + "(\n" + "SELECT Date \n" + "FROM stock_daily_performance \n" + "WHERE StockID = stockID \n" + "ORDER BY Date ASC\n" + ") temp_table)\n" + " "); while (rs.next()) { String formattedDate = rs.getString("Date"); int closing_price = rs.getInt("Closing_Price"); System.out.println("Closing Price: " + closing_price); System.out.println("Date: " + formattedDate); dataset.setValue(closing_price, "value", formattedDate); } dbcon.con.close(); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } String stockName = table.getValueAt(row, 1).toString(); JFreeChart chart = ChartFactory.createLineChart(stockName + " Stock Performance", "Date", "Value", dataset, PlotOrientation.VERTICAL, false, false, false); Color c = new Color(240, 240, 240, 0); chart.setBackgroundPaint(c); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(Color.BLACK); //set interval of Y-axis ticks (tick every 5 units) NumberAxis yAxis = (NumberAxis) catPlot.getRangeAxis(); yAxis.setTickUnit(new NumberTickUnit(5)); //set y-axis labels as currency types ($) NumberFormat currency = NumberFormat.getCurrencyInstance(); yAxis.setNumberFormatOverride(currency); //setting number of lines an x-axis label is displayed on CategoryAxis categoryAxis = catPlot.getDomainAxis(); categoryAxis.setMaximumCategoryLabelLines(4); graphPanel.setLayout(new java.awt.BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); graphPanel.removeAll(); graphPanel.add(chartPanel, BorderLayout.CENTER); graphPanel.validate(); graphPanel.repaint(); } }
From source file:Interface.ResultadoJanela.java
public JFreeChart gerarGrafico(CategoryDataset dataSet) { JFreeChart chart = ChartFactory.createBarChart3D("Resultado da Localizao de Defeitos", //Titulo " ", // Eixo X "Probabilidade (%)", //Eixo Y dataSet, // Dados para o grafico PlotOrientation.VERTICAL, //Orientacao do grafico true, true, true); // exibir: legendas, tooltips, url chart.setBackgroundPaint(Color.getHSBColor(0, 0, (float) 0.835)); // Set the background colour of the chart CategoryPlot p = chart.getCategoryPlot(); // Get the Plot object for a bar graph p.setBackgroundPaint(Color.white); // Modify the plot background p.setRangeGridlinePaint(Color.BLACK); CategoryAxis axis = p.getDomainAxis(); axis.setTickLabelFont(new Font("Helvetica", Font.PLAIN, 10)); axis.setMaximumCategoryLabelWidthRatio(1.0f); axis.setMaximumCategoryLabelLines(2); p.setDomainAxis(axis);/* www . j a v a 2 s .c o m*/ return chart; }
From source file:org.matsim.contrib.analysis.christoph.DistanceDistribution.java
private void writeDistanceDistributionClass(DistributionClass distributionClass, int iteration, OutputDirectoryHierarchy outputDirectoryHierarchy) { String fileName = outputDirectoryHierarchy.getIterationFilename(iteration, "DistanceDistribution_" + distributionClass.name); double[] referenceShare = new double[distributionClass.distributionBins.size()]; double[] simulationShare = new double[distributionClass.distributionBins.size()]; // accumulate total count int count = 0; for (DistanceBin distanceBin : distributionClass.distributionBins) { count += distanceBin.count;//from ww w .j av a 2s. c o m } try { BufferedWriter writer = IOUtils.getBufferedWriter(fileName + ".txt"); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("low" + "\t"); stringBuffer.append("high" + "\t"); stringBuffer.append("reference share" + "\t"); stringBuffer.append("simulation share"); writer.write(stringBuffer.toString()); writer.newLine(); int i = 0; log.info("Distance distribution for class " + distributionClass.name); for (DistanceBin distanceBin : distributionClass.distributionBins) { referenceShare[i] = distanceBin.referenceShare; simulationShare[i] = (double) distanceBin.count / (double) count; stringBuffer = new StringBuffer(); stringBuffer.append(distanceBin.low + "\t"); stringBuffer.append(distanceBin.high + "\t"); stringBuffer.append(distanceBin.referenceShare + "\t"); stringBuffer.append(String.valueOf(simulationShare[i])); log.info("\t" + stringBuffer.toString()); writer.write(stringBuffer.toString()); writer.newLine(); i++; } writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } String title = "Distance distribution for class " + distributionClass.name; String xAxisLabel = "Distance class"; String yAxisLabel = "Share"; String[] categories = new String[distributionClass.distributionBins.size()]; int i = 0; for (DistanceBin distanceBin : distributionClass.distributionBins) { categories[i++] = distanceBin.low + "\n" + " .. " + "\n" + distanceBin.high; } BarChart chart = new BarChart(title, xAxisLabel, yAxisLabel, categories); CategoryPlot plot = chart.getChart().getCategoryPlot(); CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setMaximumCategoryLabelLines(3); chart.addMatsimLogo(); chart.addSeries("reference share", referenceShare); chart.addSeries("simulation share", simulationShare); chart.saveAsPng(fileName + ".png", 1024, 768); }
From source file:com.att.aro.main.ProperSessionTerminationPanel.java
/** * Initializes the Panel for Proper Session Termination plot. *///from www.j a v a2 s .com 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. *///from w w w . j a v a 2s . c om 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); }