List of usage examples for org.jfree.chart.axis CategoryAxis setCategoryLabelPositions
public void setCategoryLabelPositions(CategoryLabelPositions positions)
From source file:View.DialogoEstadisticas.java
private void creaGraficaHistorico(int[] selectedIndices) { // Fuente de Datos DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset(); String[] periodos;//ww w . j a va 2 s . c o m EdoRes e; for (int j = 0; j < selectedIndices.length; j++) { switch (selectedIndices[j]) { case 0://ventas for (Cuenta c : cuentas) { if (c.getId().equals("IN000")) { if (combrobarIntervalo(c.getPeriodo())) { line_chart_dataset.addValue(c.getSaldo(), c.getNombre(), formatPeriodo(c.getPeriodo())); } } } break; case 1: //clientes for (Cuenta c : cuentas) { if (c.getId().equals("AC003")) { if (combrobarIntervalo(c.getPeriodo())) { line_chart_dataset.addValue(c.getSaldo(), c.getNombre(), formatPeriodo(c.getPeriodo())); } } } break; case 2: //gastosadmin for (Cuenta c : cuentas) { if (c.getId().equals("GA001")) { if (combrobarIntervalo(c.getPeriodo())) { line_chart_dataset.addValue(c.getSaldo(), c.getNombre(), formatPeriodo(c.getPeriodo())); } } } break; case 3://costos for (Cuenta c : cuentas) { if (c.getId().equals("CO000")) { if (combrobarIntervalo(c.getPeriodo())) { line_chart_dataset.addValue(c.getSaldo(), c.getNombre(), formatPeriodo(c.getPeriodo())); } } } break; case 4://almacen for (Cuenta c : cuentas) { if (c.getId().equals("AC002")) { if (combrobarIntervalo(c.getPeriodo())) { line_chart_dataset.addValue(c.getSaldo(), c.getNombre(), formatPeriodo(c.getPeriodo())); } } } break; case 5://efectivo for (Indicador i : indicadores) { if (i.getNombre().equals("Efectivo")) { if (combrobarIntervalo(i.getPeriodo())) { line_chart_dataset.addValue(i.getValor(), i.getNombre(), formatPeriodo(i.getPeriodo())); } } } break; case 6://utilidad for (Cuenta c : cuentas) { if (c.getId().equals("CC001")) { if (combrobarIntervalo(c.getPeriodo())) { line_chart_dataset.addValue(c.getSaldo(), c.getNombre(), formatPeriodo(c.getPeriodo())); } } } break; case 7://gastosop for (Cuenta c : cuentas) { if (c.getId().equals("GA002")) { if (combrobarIntervalo(c.getPeriodo())) { line_chart_dataset.addValue(c.getSaldo(), c.getNombre(), formatPeriodo(c.getPeriodo())); } } } break; case 8://deudiv for (Cuenta c : cuentas) { if (c.getId().equals("AC004")) { if (combrobarIntervalo(c.getPeriodo())) { line_chart_dataset.addValue(c.getSaldo(), c.getNombre(), formatPeriodo(c.getPeriodo())); } } } break; case 9://pagos periodo for (Indicador i : indicadores) { if (i.getNombre().equals("Pagos del periodo")) { if (combrobarIntervalo(i.getPeriodo())) { line_chart_dataset.addValue(i.getValor(), i.getNombre(), formatPeriodo(i.getPeriodo())); } } } break; case 10://utilidadNeta periodo h.buscaPeriodos(); periodos = h.getPeriodos(); for (String p : periodos) { if (combrobarIntervalo(p)) { e = new EdoRes(p); line_chart_dataset.addValue(e.getUtN(), "Utilidad N", formatPeriodo(p)); } } break; case 11://utilidadBruta periodo h.buscaPeriodos(); periodos = h.getPeriodos(); for (String p : periodos) { if (combrobarIntervalo(p)) { e = new EdoRes(p); line_chart_dataset.addValue(e.getUtB(), "Utilidad B", formatPeriodo(p)); } } break; } } JFreeChart chart = ChartFactory.createLineChart("Estadsticas", "periodos", "monto ($)", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); if (chartPanel != null) { panelG.remove(chartPanel); } //grosor de linea de fx CategoryPlot p = chart.getCategoryPlot(); for (int j = 0; j < selectedIndices.length; j++) { p.getRenderer().setSeriesStroke(j, new BasicStroke(4)); } //color y grosor de grid chart.getCategoryPlot().setDomainGridlinesVisible(true); //grid visible p.setRangeGridlinePaint(Color.black); p.setDomainGridlinePaint(Color.black); p.setRangeGridlineStroke(new BasicStroke(1)); p.setDomainGridlineStroke(new BasicStroke(1)); //titulos de eje y en vertical CategoryAxis domainAxis = ((CategoryPlot) p).getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(723, 456)); chartPanel.setVisible(true); chartPanel.setSize(723, 456); panelG.add(chartPanel); panelG.revalidate(); panelG.repaint(); }
From source file:hr.restart.util.chart.ChartXY.java
/** * Creates a BAR CHART//from w ww . j av a2 s .com * @param dataset The org.jfree.data.CategoryDataset * @param title The title * @return org.jfree.chart.JFreeChart */ private JFreeChart createBarChart(final CategoryDataset dataset, String title, PlotOrientation orientation) { final JFreeChart chart = ChartFactory.createBarChart(title, // chart title "", // domain axis label "", // range axis label dataset, // data orientation, // the plot orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); // the subtitle from the combobox if (jcb != null) chart.addSubtitle(new TextTitle(jcb.getSelectedItem().toString())); //subtitles setted by the user. if (getSubtitles() != null) for (int i = 0; i < getSubtitles().size(); i++) { chart.addSubtitle(new TextTitle(getSubtitles().get(i).toString())); } final Plot plot = chart.getPlot(); // get a reference to the plot for further customisation... final CategoryPlot categoryPlot = (CategoryPlot) plot; categoryPlot.setNoDataMessage("NO DATA!"); categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.red, Color.blue, Color.green, Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue }); categoryPlot.setRenderer(renderer); renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); renderer.setItemLabelsVisible(true); // inside //renderer.setBaseItemLabelPaint(Color.white); Font font = new Font("SansSerif", Font.PLAIN, 7); Font derive = font.deriveFont(Font.BOLD); renderer.setBaseItemLabelFont(derive); // margin final CategoryAxis domainAxis = categoryPlot.getDomainAxis(); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); //domainAxis.setBottomCategoryLabelPosition(new CategoryLabelPosition(RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER)); domainAxis.setCategoryLabelPositions(new CategoryLabelPositions( new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_CENTER), // TOP new CategoryLabelPosition(RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER), // BOTTOM new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, CategoryLabelWidthType.RANGE, 0.30f), // LEFT new CategoryLabelPosition(RectangleAnchor.RIGHT, TextBlockAnchor.CENTER_RIGHT, CategoryLabelWidthType.RANGE, 0.30f) // RIGHT) )); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setPositiveItemLabelPosition(p); if (comboBoxOrientation != null) { if (comboBoxOrientation.getSelectedItem() == "Vertikalni") { domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0)); } } return chart; }
From source file:org.jax.pubarray.server.restful.GraphingResource.java
/** * Create a graph for the given configuration * @param graphConfiguration/* w ww .jav a 2 s .co m*/ * the key * @return * the graph */ @SuppressWarnings("unchecked") private JFreeChart createProbeIntensityGraph(ProbeIntensityGraphConfiguration graphConfiguration) { try { Connection connection = this.getConnection(); String[] probeIds = graphConfiguration.getProbeIds(); double[][] probeDataRows = new double[probeIds.length][]; for (int i = 0; i < probeIds.length; i++) { probeDataRows[i] = this.persistenceManager.getDataRowForProbeID(connection, probeIds[i]); } TableColumnMetadata orderBy = graphConfiguration.getOrderProbesBy(); final List<Comparable> orderByItems; if (orderBy != null) { LOG.info("We are ordering by: " + orderBy); orderByItems = this.persistenceManager.getDesignDataColumn(connection, orderBy); } else { orderByItems = null; } TableMetadata metadata = this.persistenceManager.getDataTableMetadata(connection); final CategoryDataset categoryDataset; if (graphConfiguration.getGroupReplicates()) { switch (graphConfiguration.getGroupedGraphType()) { case BOX_PLOT: { categoryDataset = new DefaultBoxAndWhiskerCategoryDataset(); } break; case SCATTER_PLOT: { categoryDataset = new DefaultMultiValueCategoryDataset(); } break; default: throw new IllegalArgumentException( "don't know how to deal with plot type: " + graphConfiguration.getGroupedGraphType()); } } else { categoryDataset = new DefaultCategoryDataset(); } // iterate through all of the selected probesets List<QualifiedColumnMetadata> termsOfInterest = Arrays.asList(graphConfiguration.getTermsOfInterest()); for (int rowIndex = 0; rowIndex < probeDataRows.length; rowIndex++) { double[] currRow = probeDataRows[rowIndex]; assert currRow.length == metadata.getColumnMetadata().length - 1; // should we log2 transform the data? if (graphConfiguration.getLog2TransformData()) { for (int i = 0; i < currRow.length; i++) { currRow[i] = Math.log(currRow[i]) / LOG2_FACTOR; } } // iterate through the columns in the data table (each column // represents a different array) List<ComparableContainer<Double, Comparable>> rowElemList = new ArrayList<ComparableContainer<Double, Comparable>>(); for (int colIndex = 0; colIndex < currRow.length; colIndex++) { // we use +1 indexing here because we want to skip over // the probesetId metadata and get right to the // array intensity metadata TableColumnMetadata colMeta = metadata.getColumnMetadata()[colIndex + 1]; // check to see if we need to skip this data if (!graphConfiguration.getIncludeDataFromAllArrays()) { // if it's one of the "terms of interest" we will keep // it. we're using a brute force search here boolean keepThisOne = false; for (QualifiedColumnMetadata termOfInterest : termsOfInterest) { if (termOfInterest.getTableName().equals(metadata.getTableName()) && termOfInterest.getName().equals(colMeta.getName())) { keepThisOne = true; break; } } if (!keepThisOne) { continue; } } final String columnName = colMeta.getName(); final Comparable columnKey; if (orderByItems == null) { columnKey = columnName; } else { // the ordering will be done on the selected // "order by" design criteria columnKey = new ComparableContainer<String, Comparable>(columnName, orderByItems.get(colIndex), !graphConfiguration.getGroupReplicates()); // TODO remove me!!!! System.out.println("For array " + columnName + " the order by " + "value is: " + orderByItems.get(colIndex)); // end of remove me } rowElemList .add(new ComparableContainer<Double, Comparable>(currRow[colIndex], columnKey, false)); } Collections.sort(rowElemList); if (graphConfiguration.getGroupReplicates()) { switch (graphConfiguration.getGroupedGraphType()) { case BOX_PLOT: { DefaultBoxAndWhiskerCategoryDataset dataset = (DefaultBoxAndWhiskerCategoryDataset) categoryDataset; for (int i = 0; i < rowElemList.size(); i++) { List<Double> groupList = new ArrayList<Double>(); groupList.add(rowElemList.get(i).getElement()); Comparable colKey = rowElemList.get(i).getComparable(); i++; for (; i < rowElemList.size() && rowElemList.get(i).getComparable().equals(colKey); i++) { groupList.add(rowElemList.get(i).getElement()); } i--; dataset.add(groupList, probeIds[rowIndex], colKey); } } break; case SCATTER_PLOT: { DefaultMultiValueCategoryDataset dataset = (DefaultMultiValueCategoryDataset) categoryDataset; for (int i = 0; i < rowElemList.size(); i++) { List<Double> groupList = new ArrayList<Double>(); groupList.add(rowElemList.get(i).getElement()); Comparable colKey = rowElemList.get(i).getComparable(); i++; for (; i < rowElemList.size() && rowElemList.get(i).getComparable().equals(colKey); i++) { groupList.add(rowElemList.get(i).getElement()); } i--; dataset.add(groupList, probeIds[rowIndex], colKey); } } break; } } else { DefaultCategoryDataset dataset = (DefaultCategoryDataset) categoryDataset; for (ComparableContainer<Double, Comparable> rowElem : rowElemList) { dataset.addValue(rowElem.getElement(), probeIds[rowIndex], rowElem.getComparable()); } } } CategoryAxis xAxis = new CategoryAxis(); if (graphConfiguration.getGroupReplicates() && orderBy != null) { xAxis.setLabel(orderBy.getName()); } else { if (orderBy != null) { xAxis.setLabel("Arrays (Ordered By " + orderBy.getName() + ")"); } else { xAxis.setLabel("Arrays"); } } xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); final NumberAxis yAxis; if (graphConfiguration.getLog2TransformData()) { yAxis = new NumberAxis("log2(Intensity)"); } else { yAxis = new NumberAxis("Intensity"); } yAxis.setAutoRange(true); yAxis.setAutoRangeIncludesZero(false); // TODO: this is a HACK to deal with auto-range bug in JFreeChart // which occurs when doing the grouped scatter plot if (graphConfiguration.getGroupReplicates() && graphConfiguration.getGroupedGraphType() == GroupedGraphType.SCATTER_PLOT) { double minVal = Double.POSITIVE_INFINITY; double maxVal = Double.NEGATIVE_INFINITY; for (double[] dataRow : probeDataRows) { for (double datum : dataRow) { if (datum > maxVal) { maxVal = datum; } if (datum < minVal) { minVal = datum; } } if (minVal != Double.POSITIVE_INFINITY && maxVal != Double.NEGATIVE_INFINITY && minVal != maxVal) { yAxis.setAutoRange(false); double margin = (maxVal - minVal) * 0.02; Range yRange = new Range(minVal - margin, maxVal + margin); yAxis.setRange(yRange); } } } // END HACK final CategoryItemRenderer renderer; if (graphConfiguration.getGroupReplicates()) { switch (graphConfiguration.getGroupedGraphType()) { case BOX_PLOT: { BoxAndWhiskerRenderer boxRenderer = new BoxAndWhiskerRenderer(); boxRenderer.setMaximumBarWidth(0.03); renderer = boxRenderer; } break; case SCATTER_PLOT: { renderer = new ScatterRenderer(); } break; default: throw new IllegalArgumentException( "don't know how to deal with plot type: " + graphConfiguration.getGroupedGraphType()); } } else { renderer = new LineAndShapeRenderer(); } Plot plot = new CategoryPlot(categoryDataset, xAxis, yAxis, renderer); return new JFreeChart("Intensity Values", plot); } catch (SQLException ex) { LOG.log(Level.SEVERE, "failed to generate image", ex); return null; } }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getChapterPareto(DefaultKeyedValues data, String title, String quantity, String range) { JFreeChart chart;// w w w . ja va 2s .c o m data.sortByValues(SortOrder.DESCENDING); KeyedValues cummulative = DataUtilities.getCumulativePercentages(data); CategoryDataset dataset = DatasetUtilities.createCategoryDataset(quantity, data); // create the chart... chart = ChartFactory.createBarChart(title, // chart title "Chapter", // domain axis label range, // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cummulative", cummulative); NumberAxis axis2 = new NumberAxis("Percent"); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis2.setUpperBound(1); axis2.setLowerBound(0); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java
private void createChart() { DefaultCategoryDataset vitalSignDataset = new DefaultCategoryDataset(); int selectedRow = vitalSignjTable.getSelectedRow(); Member member = (Member) vitalSignjTable.getValueAt(selectedRow, 0); ArrayList<VitalSign> vitalSignList = member.getVitalSignList().getVitalSignList(); /*At least 2 vital sign records needed to show chart */ if (vitalSignList.isEmpty() || vitalSignList.size() == 1) { JOptionPane.showMessageDialog(this, "No vital signs or only one vital sign found. At least 2 vital sign records needed to show chart!", "Warning", JOptionPane.INFORMATION_MESSAGE); return;/*from w ww . jav a 2 s. c o m*/ } for (VitalSign vitalSign : vitalSignList) { vitalSignDataset.addValue(vitalSign.getRespiratoryRate(), "RR", vitalSign.getTimestamp()); vitalSignDataset.addValue(vitalSign.getHeartRate(), "HR", vitalSign.getTimestamp()); vitalSignDataset.addValue(vitalSign.getBloodPressure(), "BP", vitalSign.getTimestamp()); vitalSignDataset.addValue(vitalSign.getTemperature(), "Temp", vitalSign.getTimestamp()); } JFreeChart vitalSignChart = ChartFactory.createBarChart3D("Vital Sign Chart", "Time Stamp", "Rate", vitalSignDataset, PlotOrientation.VERTICAL, true, false, false); vitalSignChart.setBackgroundPaint(Color.white); CategoryPlot vitalSignChartPlot = vitalSignChart.getCategoryPlot(); vitalSignChartPlot.setBackgroundPaint(Color.lightGray); CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis(); vitalSignDomainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis(); vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartFrame chartFrame = new ChartFrame("Chart", vitalSignChart); chartFrame.setVisible(true); chartFrame.setSize(500, 500); }
From source file:hudson.plugins.plot.Plot.java
/** * Generates the plot and stores it in the plot instance variable. * * @param forceGenerate/* w w w. ja v a 2 s. c o m*/ * if true, force the plot to be re-generated even if the on-disk * data hasn't changed */ private void generatePlot(boolean forceGenerate) { class Label implements Comparable<Label> { final private Integer buildNum; final private String buildDate; final private String text; public Label(String buildNum, String buildTime, String text) { this.buildNum = Integer.parseInt(buildNum); synchronized (DATE_FORMAT) { this.buildDate = DATE_FORMAT.format(new Date(Long.parseLong(buildTime))); } this.text = text; } public Label(String buildNum, String buildTime) { this(buildNum, buildTime, null); } public int compareTo(Label that) { return this.buildNum - that.buildNum; } @Override public boolean equals(Object o) { return o instanceof Label && ((Label) o).buildNum.equals(buildNum); } @Override public int hashCode() { return buildNum.hashCode(); } public String numDateString() { return "#" + buildNum + " (" + buildDate + ")"; } @Override public String toString() { return text != null ? text : numDateString(); } } // LOGGER.info("Determining if we should generate plot " + // getCsvFileName()); File csvFile = new File(project.getRootDir(), getCsvFileName()); if (csvFile.lastModified() == csvLastModification && plot != null && !forceGenerate) { // data hasn't changed so don't regenerate the plot return; } if (rawPlotData == null || csvFile.lastModified() > csvLastModification) { // data has changed or has not been loaded so load it now loadPlotData(); } // LOGGER.info("Generating plot " + getCsvFileName()); csvLastModification = csvFile.lastModified(); PlotCategoryDataset dataset = new PlotCategoryDataset(); for (String[] record : rawPlotData) { // record: series y-value, series label, build number, build date, // url int buildNum; try { buildNum = Integer.valueOf(record[2]); if (!reportBuild(buildNum) || buildNum > getRightBuildNum()) { continue; // skip this record } } catch (NumberFormatException nfe) { LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe); continue; // skip this record all together } Number value = null; try { value = Integer.valueOf(record[0]); } catch (NumberFormatException nfe) { try { value = Double.valueOf(record[0]); } catch (NumberFormatException nfe2) { LOGGER.log(Level.SEVERE, "Exception converting to number", nfe2); continue; // skip this record all together } } String series = record[1]; Label xlabel = getUrlUseDescr() ? new Label(record[2], record[3], descriptionForBuild(buildNum)) : new Label(record[2], record[3]); String url = null; if (record.length >= 5) url = record[4]; dataset.setValue(value, url, series, xlabel); } String urlNumBuilds = getURLNumBuilds(); int numBuilds; if (StringUtils.isBlank(urlNumBuilds)) { numBuilds = Integer.MAX_VALUE; } else { try { numBuilds = Integer.parseInt(urlNumBuilds); } catch (NumberFormatException nfe) { LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe); numBuilds = Integer.MAX_VALUE; } } dataset.clipDataset(numBuilds); plot = createChart(dataset); CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot(); categoryPlot.setDomainGridlinePaint(Color.black); categoryPlot.setRangeGridlinePaint(Color.black); categoryPlot.setDrawingSupplier(Plot.supplier); CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build()); categoryPlot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.03); domainAxis.setCategoryMargin(0.0); for (Object category : dataset.getColumnKeys()) { Label label = (Label) category; if (label.text != null) { domainAxis.addCategoryLabelToolTip(label, label.numDateString()); } else { domainAxis.addCategoryLabelToolTip(label, descriptionForBuild(label.buildNum)); } } // Replace the range axis by a logarithmic axis if the option is // selected if (isLogarithmic()) { LogarithmicAxis logAxis = new LogarithmicAxis(getYaxis()); logAxis.setExpTickLabelsFlag(true); categoryPlot.setRangeAxis(logAxis); } // optionally exclude zero as default y-axis value ValueAxis rangeAxis = categoryPlot.getRangeAxis(); if ((rangeAxis != null) && (rangeAxis instanceof NumberAxis)) { if (hasYaxisMinimum()) { ((NumberAxis) rangeAxis).setLowerBound(getYaxisMinimum()); } if (hasYaxisMaximum()) { ((NumberAxis) rangeAxis).setUpperBound(getYaxisMaximum()); } ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(!getExclZero()); } AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) categoryPlot.getRenderer(); int numColors = dataset.getRowCount(); for (int i = 0; i < numColors; i++) { renderer.setSeriesPaint(i, new Color(Color.HSBtoRGB((1f / numColors) * i, 1f, 1f))); } renderer.setBaseStroke(new BasicStroke(2.0f)); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(Messages.Plot_Build() + " {1}: {2}", NumberFormat.getInstance())); renderer.setBaseItemURLGenerator(new PointURLGenerator()); if (renderer instanceof LineAndShapeRenderer) { String s = getUrlStyle(); LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer; if ("lineSimple".equalsIgnoreCase(s)) { lasRenderer.setShapesVisible(false); // TODO: deprecated, may be unnecessary } else { lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary } } }
From source file:com.android.ddmuilib.HeapPanel.java
/** * Creates the chart below the statistics table *///from ww w . j a v a2s.com private void createChart() { mAllocCountDataSet = new DefaultCategoryDataset(); mChart = ChartFactory.createBarChart(null, "Size", "Count", mAllocCountDataSet, PlotOrientation.VERTICAL, false, true, false); // get the font to make a proper title. We need to convert the swt font, // into an awt font. Font f = mStatisticsBase.getFont(); FontData[] fData = f.getFontData(); // event though on Mac OS there could be more than one fontData, we'll only use // the first one. FontData firstFontData = fData[0]; java.awt.Font awtFont = SWTUtils.toAwtFont(mStatisticsBase.getDisplay(), firstFontData, true /* ensureSameSize */); mChart.setTitle(new TextTitle("Allocation count per size", awtFont)); Plot plot = mChart.getPlot(); if (plot instanceof CategoryPlot) { // get the plot CategoryPlot categoryPlot = (CategoryPlot) plot; // set the domain axis to draw labels that are displayed even with many values. CategoryAxis domainAxis = categoryPlot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); CategoryItemRenderer renderer = categoryPlot.getRenderer(); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { // get the key for the size of the allocation ByteLong columnKey = (ByteLong) dataset.getColumnKey(column); String rowKey = (String) dataset.getRowKey(row); Number value = dataset.getValue(rowKey, columnKey); return String.format("%1$d %2$s of %3$d bytes", value.intValue(), rowKey, columnKey.getValue()); } }); } mChartComposite = new ChartComposite(mStatisticsBase, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH, ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH, ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 3000, // max draw width. We don't want it to zoom, so we put a big number 3000, // max draw height. We don't want it to zoom, so we put a big number true, // off-screen buffer true, // properties true, // save true, // print false, // zoom true); // tooltips mChartComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); }
From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java
protected void setupCategoryChart(JFreeChart chart) { if (!(chart.getPlot() instanceof CategoryPlot)) return;/*from w ww . ja v a 2 s. c o m*/ CategoryPlot cp = chart.getCategoryPlot(); CategoryAxis catAxis = cp.getDomainAxis(); ValueAxis otherAxis = cp.getRangeAxis(); if (!chromeless) { String catAxisLabel = data.getColName(0); if (catAxisLabel == null) catAxisLabel = Translator.translate("Project/Task"); String otherAxisLabel = Translator.translate(getSetting("units")); if ((otherAxisLabel == null || otherAxisLabel.length() == 0) && data.numCols() == 1) otherAxisLabel = data.getColName(1); if (otherAxisLabel == null) otherAxisLabel = Translator.translate("Value"); String catLabels = getParameter("categoryLabels"); catAxis.setLabel(catAxisLabel); otherAxis.setLabel(otherAxisLabel); if ("vertical".equalsIgnoreCase(catLabels)) catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); else if ("none".equalsIgnoreCase(catLabels)) catAxis.setTickLabelsVisible(false); } if (data.numCols() == 1 && getParameter("noSkipLegend") == null) { chart.removeLegend(); chart.getPlot().setInsets(new RectangleInsets(5, 2, 2, 5)); } }
From source file:ReportGen.java
private void yearlyPreview() throws NumberFormatException { exportcounttableexcel.setEnabled(true); exportcounttablepdf.setEnabled(true); tableModel = (DefaultTableModel) dataTable.getModel(); tableModel.getDataVector().removeAllElements(); tableModel.fireTableDataChanged();//www. j av a2 s .c o m String str[] = { "Years", "Values" }; tableModel.setColumnIdentifiers(str); ChartPanel chartPanel; displaypane.removeAll(); displaypane.revalidate(); displaypane.repaint(); displaypane.setLayout(new BorderLayout()); //row String series1 = "Results"; //column String year[] = { "2014", "2015", "2016", "2017", "2018", "2019", "2020" }; dataset = new DefaultCategoryDataset(); dataset.addValue(0, series1, year[0]); dataset.addValue(1, series1, year[1]); dataset.addValue(2, series1, year[2]); dataset.addValue(3, series1, year[3]); dataset.addValue(4, series1, year[4]); dataset.addValue(5, series1, year[5]); dataset.addValue(6, series1, year[6]); chart = ChartFactory.createBarChart("181 North Place Residences Graph", // chart title "Years", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // 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... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); 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... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); chartPanel = new ChartPanel(chart); displaypane.add(chartPanel, BorderLayout.CENTER); }
From source file:ReportGen.java
private void defaultPreview() throws NumberFormatException { tableModel = (DefaultTableModel) dataTable.getModel(); tableModel.getDataVector().removeAllElements(); tableModel.fireTableDataChanged();/*from w w w.j ava2 s .c om*/ String str[] = { "X", "Y" }; tableModel.setColumnIdentifiers(str); exportcounttableexcel.setEnabled(false); exportcounttablepdf.setEnabled(false); // exportgraphtoimage.setEnabled(false); ChartPanel chartPanel; displaypane.removeAll(); displaypane.revalidate(); displaypane.repaint(); displaypane.setLayout(new BorderLayout()); //row String series1 = "Results"; //column String values[] = { "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-" }; int value[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; for (int i = 0; i < values.length; i++) { tableModel.addRow(new Object[] { values[i], value[i] }); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int c = 0; c < value.length; c++) { dataset.addValue(value[c], series1, values[c]); } chart = ChartFactory.createBarChart("181 North Place Residences Graph", // chart title "Default", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // 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... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); 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... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); chartPanel = new ChartPanel(chart); displaypane.add(chartPanel, BorderLayout.CENTER); }