List of usage examples for org.jfree.chart.axis CategoryAxis setMaximumCategoryLabelLines
public void setMaximumCategoryLabelLines(int lines)
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeBarTimeChartData.java
@Override public JFreeChart getJFreeChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double counts[] = ds.getCounts(); String legends[] = ds.getLegends(); int max_len = 0; for (int i = 0; i < ds.getNumSets(); i++) { if (legends != null && legends.length > i) { dataset.addValue(new Double(counts[i]), "Series-1", legends[i]); int leg_len = legends[i].length(); if (leg_len > max_len) { max_len = leg_len;//from w ww. j a v a 2s .c o m } //System.out.println(legends[i] + counts[i]); } else { dataset.addValue(new Double(counts[i]), "Series-1", Integer.toString(i)); } } CategoryDataset data = dataset; JFreeChart chart = ChartFactory.createBarChart(title, null, quantity, data, PlotOrientation.VERTICAL, false, // include legends false, // tooltips false // urls ); CategoryPlot categoryPlot = chart.getCategoryPlot(); CategoryAxis axis = categoryPlot.getDomainAxis(); if (max_len > 8 || ds.getNumSets() > 16 || (max_len * ds.getNumSets()) > 50) { axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); } Font tickLabelFont = axis.getTickLabelFont(); if (ds.getNumSets() > 24) { axis.setTickLabelFont(tickLabelFont.deriveFont(tickLabelFont.getSize() - 2.0F)); } Font labelFont = axis.getLabelFont(); axis.setMaximumCategoryLabelLines(3); //axis.setLabelFont(labelFont.d); // axis.setLabel("Pingu"); This works so we can modify return chart; }
From source file:desmoj.extensions.grafic.util.Plotter.java
/** * Build a JPanel with a histogram plot of a desmoJ histogram dataset * In the case histogram.getShowTimeSpansInReport() the data values are interpreted as * a timespan in a appropriate time unit. * @param histogram desmoJ histogram dataset * @return/*w w w . j av a 2 s. c o m*/ */ private JPanel getHistogramPlot(Histogram histogram) { JFreeChart chart; NumberFormat formatter = NumberFormat.getInstance(locale); HistogramDataSetAdapter dataSet = new HistogramDataSetAdapter(histogram, locale); String title = histogram.getName(); if (histogram.getDescription() != null) title = histogram.getDescription(); String xLabel = dataSet.getCategoryAxisLabel(); String yLabel = dataSet.getObservationAxisLabel(); chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataSet, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBaseItemLabelsVisible(true); StandardCategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", formatter); barrenderer.setBaseItemLabelGenerator(generator); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); //categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); categoryaxis.setMaximumCategoryLabelLines(4); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //numberaxis.setUpperMargin(0.1D); numberaxis.setNumberFormatOverride(formatter); return new ChartPanel(chart); }
From source file:stockit.Manager.java
private void displayBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayBtnActionPerformed // TODO add your handling code here: //panel.removeAll(); 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 {/*from www. ja v a 2 s . c o m*/ 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.createBarChart3D(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); panel.setLayout(new java.awt.BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); panel.removeAll(); panel.add(chartPanel, BorderLayout.CENTER); panel.validate(); panel.repaint(); } }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * DOC bZhou Comment method "decorateCategoryPlot". * /*from w ww . jav a2 s .c o m*/ * @param chart */ public static void decorateCategoryPlot(JFreeChart chart, PlotOrientation orientation) { CategoryPlot plot = chart.getCategoryPlot(); CategoryItemRenderer render = plot.getRenderer(); CategoryAxis domainAxis = plot.getDomainAxis(); // ADD msjian TDQ-5111 2012-4-9: set something look it well domainAxis.setCategoryMargin(0.1); domainAxis.setUpperMargin(0.05); domainAxis.setLowerMargin(0.05); domainAxis.setCategoryLabelPositionOffset(10); // TDQ-5111~ ValueAxis valueAxis = plot.getRangeAxis(); Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$ render.setBaseItemLabelFont(font); // MOD zshen 10998: change the font name 2010-01-16 font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setLabelFont(font); font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ valueAxis.setLabelFont(font); font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setTickLabelFont(font); valueAxis.setTickLabelFont(font); setLegendFont(chart); font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$ TextTitle title = chart.getTitle(); if (title != null) { title.setFont(font); } font = null; if (render instanceof BarRenderer) { CategoryDataset dataset = chart.getCategoryPlot().getDataset(); if (dataset != null) { int rowCount = dataset.getRowCount(); List<?> columnKeys = dataset.getColumnKeys(); if (!isContainCJKCharacter(columnKeys.toArray())) { domainAxis.setTickLabelFont(new Font("Tahoma", Font.PLAIN, 10));//$NON-NLS-1$ } ((BarRenderer) render).setItemMargin(-0.40 * rowCount); // TDQ-12621 add Tooltip for Lable for (Object colKey : columnKeys) { domainAxis.addCategoryLabelToolTip(colKey.toString(), colKey.toString()); } } domainAxis.setUpperMargin(0.1); // TDQ-12621 Only display in 1 line for the label, other chars will be displayed as "..." domainAxis.setMaximumCategoryLabelLines(1); // ADD msjian TDQ-5111 2012-4-9: set Bar Width and let it look well // not do this when the bar is horizontal Orientation if (orientation == null) { ((BarRenderer) render).setMaximumBarWidth(0.2); } // TDQ-5111~ } // ~10998 }