List of usage examples for org.jfree.chart.title TextTitle TextTitle
public TextTitle(String text)
From source file:hr.restart.util.chart.ChartXY.java
/** * Creates a PIE CHART/* w ww. j ava 2 s.c o m*/ * @param dataset The org.jfree.data.PieDataset * @param title The title * @return org.jfree.chart.JFreeChart */ private JFreeChart createPieChart(final PieDataset dataset, String title) { final JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data false, // include legend true, false); chart.setBackgroundPaint(Color.white); Plot plot = chart.getPlot(); // 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 PiePlot piePlot = (PiePlot) plot; piePlot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); piePlot.setNoDataMessage("NO DATA!"); piePlot.setCircular(false); piePlot.setLabelLinkPaint(Color.red); piePlot.setLabelGap(0.02); return chart; }
From source file:asl.util.PlotMaker.java
public void plotCoherence(double per[], double[] gamma, String plotString) { final String plotTitle = String.format("%04d%03d.%s.%s-%s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channelX, channelY); final String pngName = String.format("%s/%04d%03d.%s.%s-%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channelX, channelY, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotCoherence: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;//from ww w .jav a 2 s . c om } final String legend = String.format("%s--%s", channelX, channelY); final XYSeries series1 = new XYSeries(legend); for (int k = 0; k < gamma.length; k++) { series1.add(per[k], gamma[k]); } //final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer1.setSeriesShape(0, rectangle); renderer1.setSeriesShapesVisible(0, true); renderer1.setSeriesLinesVisible(0, false); Paint[] paints = new Paint[] { Color.red, Color.black }; renderer1.setSeriesPaint(0, paints[0]); final NumberAxis rangeAxis1 = new NumberAxis("Coherence, Gamma"); rangeAxis1.setRange(new Range(0, 1.2)); rangeAxis1.setTickUnit(new NumberTickUnit(0.1)); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(0.05, 10000)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, rangeAxis1, renderer1); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final JFreeChart chart = new JFreeChart(xyplot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:hr.restart.util.chart.ChartXY.java
/** * Creates a BAR CHART// w ww . j a va 2 s .c o m * @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.openmrs.web.servlet.ShowGraphServlet.java
/** * The main method for this class. It will create a JFreeChart object to be written to the * response.//from w ww .j ava 2s . com * * @param request the current request will all the parameters needed * @return JFreeChart object to be rendered * @should set value axis label to given units * @should set value axis label to concept numeric units if given units is null */ protected JFreeChart getChart(HttpServletRequest request) { // All available GET parameters String patientId = request.getParameter("patientId"); // required String conceptId1 = request.getParameter("conceptId"); // required String conceptId2 = request.getParameter("conceptId2"); String chartTitle = request.getParameter("chartTitle"); String units = request.getParameter("units"); String minRangeString = request.getParameter("minRange"); String maxRangeString = request.getParameter("maxRange"); String hideDate = request.getParameter("hideDate"); Patient patient = Context.getPatientService().getPatient(Integer.parseInt(patientId)); // Set date range to passed values, otherwise set a default date range to the last 12 months Calendar cal = Calendar.getInstance(); Date fromDate = getFromDate(request.getParameter("fromDate")); Date toDate = getToDate(request.getParameter("toDate")); // Swap if fromDate is after toDate if (fromDate.getTime() > toDate.getTime()) { Long temp = fromDate.getTime(); fromDate.setTime(toDate.getTime()); toDate.setTime(temp); } // Graph parameters Double minRange = null; Double maxRange = null; Double normalLow = null; Double normalHigh = null; Double criticalLow = null; Double criticalHigh = null; String timeAxisTitle = null; String rangeAxisTitle = null; boolean userSpecifiedMaxRange = false; boolean userSpecifiedMinRange = false; // Fetching obs List<Obs> observations1 = new ArrayList<Obs>(); List<Obs> observations2 = new ArrayList<Obs>(); Concept concept1 = null, concept2 = null; if (conceptId1 != null) { concept1 = Context.getConceptService().getConcept(Integer.parseInt(conceptId1)); } if (conceptId2 != null) { concept2 = Context.getConceptService().getConcept(Integer.parseInt(conceptId2)); } if (concept1 != null) { observations1 = Context.getObsService().getObservationsByPersonAndConcept(patient, concept1); chartTitle = concept1.getName().getName(); rangeAxisTitle = ((ConceptNumeric) concept1).getUnits(); minRange = ((ConceptNumeric) concept1).getLowAbsolute(); maxRange = ((ConceptNumeric) concept1).getHiAbsolute(); normalLow = ((ConceptNumeric) concept1).getLowNormal(); normalHigh = ((ConceptNumeric) concept1).getHiNormal(); criticalLow = ((ConceptNumeric) concept1).getLowCritical(); criticalHigh = ((ConceptNumeric) concept1).getHiCritical(); // Only get observations2 if both concepts share the same units; update chart title and ranges if (concept2 != null) { String concept2Units = ((ConceptNumeric) concept2).getUnits(); if (concept2Units != null && concept2Units.equals(rangeAxisTitle)) { observations2 = Context.getObsService().getObservationsByPersonAndConcept(patient, concept2); chartTitle += " + " + concept2.getName().getName(); if (((ConceptNumeric) concept2).getHiAbsolute() != null && ((ConceptNumeric) concept2).getHiAbsolute() > maxRange) { maxRange = ((ConceptNumeric) concept2).getHiAbsolute(); } if (((ConceptNumeric) concept2).getLowAbsolute() != null && ((ConceptNumeric) concept2).getLowAbsolute() < minRange) { minRange = ((ConceptNumeric) concept2).getLowAbsolute(); } } else { log.warn("Units for concept id: " + conceptId2 + " don't match units for concept id: " + conceptId1 + ". Only displaying " + conceptId1); concept2 = null; // nullify concept2 so that the legend isn't shown later } } } else { chartTitle = "Concept " + conceptId1 + " not found"; rangeAxisTitle = "Value"; } // Overwrite with user-specified values, otherwise use default values if (units != null && units.length() > 0) { rangeAxisTitle = units; } if (minRangeString != null) { minRange = Double.parseDouble(minRangeString); userSpecifiedMinRange = true; } if (maxRangeString != null) { maxRange = Double.parseDouble(maxRangeString); userSpecifiedMaxRange = true; } if (chartTitle == null) { chartTitle = ""; } if (rangeAxisTitle == null) { rangeAxisTitle = ""; } if (minRange == null) { minRange = 0.0; } if (maxRange == null) { maxRange = 200.0; } // Create data set TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeries series1, series2; // Interval-dependent units Class<? extends RegularTimePeriod> timeScale = null; if (toDate.getTime() - fromDate.getTime() <= 86400000) { // Interval <= 1 day: minutely timeScale = Minute.class; timeAxisTitle = "Time"; } else if (toDate.getTime() - fromDate.getTime() <= 259200000) { // Interval <= 3 days: hourly timeScale = Hour.class; timeAxisTitle = "Time"; } else { timeScale = Day.class; timeAxisTitle = "Date"; } if (concept1 == null) { series1 = new TimeSeries("NULL", Hour.class); } else { series1 = new TimeSeries(concept1.getName().getName(), timeScale); } if (concept2 == null) { series2 = new TimeSeries("NULL", Hour.class); } else { series2 = new TimeSeries(concept2.getName().getName(), timeScale); } // Add data points for concept1 for (Obs obs : observations1) { if (obs.getValueNumeric() != null && obs.getObsDatetime().getTime() >= fromDate.getTime() && obs.getObsDatetime().getTime() < toDate.getTime()) { cal.setTime(obs.getObsDatetime()); if (timeScale == Minute.class) { Minute min = new Minute(cal.get(Calendar.MINUTE), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series1.addOrUpdate(min, obs.getValueNumeric()); } else if (timeScale == Hour.class) { Hour hour = new Hour(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series1.addOrUpdate(hour, obs.getValueNumeric()); } else { Day day = new Day(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series1.addOrUpdate(day, obs.getValueNumeric()); } } } // Add data points for concept2 for (Obs obs : observations2) { if (obs.getValueNumeric() != null && obs.getObsDatetime().getTime() >= fromDate.getTime() && obs.getObsDatetime().getTime() < toDate.getTime()) { cal.setTime(obs.getObsDatetime()); if (timeScale == Minute.class) { Minute min = new Minute(cal.get(Calendar.MINUTE), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series2.addOrUpdate(min, obs.getValueNumeric()); } else if (timeScale == Hour.class) { Hour hour = new Hour(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series2.addOrUpdate(hour, obs.getValueNumeric()); } else { Day day = new Day(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); series2.addOrUpdate(day, obs.getValueNumeric()); } } } // Add series to dataset dataset.addSeries(series1); if (!series2.isEmpty()) { dataset.addSeries(series2); } // As of JFreeChart 1.0.11 the default background color is dark grey instead of white. // This line restores the original white background. ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart chart = null; // Show legend only if more than one series if (concept2 == null) { chart = ChartFactory.createTimeSeriesChart(chartTitle, timeAxisTitle, rangeAxisTitle, dataset, false, false, false); } else { chart = ChartFactory.createTimeSeriesChart(chartTitle, timeAxisTitle, rangeAxisTitle, dataset, true, false, false); } // Customize title font Font font = new Font("Arial", Font.BOLD, 12); TextTitle title = chart.getTitle(); title.setFont(font); chart.setTitle(title); // Add subtitle, unless 'hideDate' has been passed if (hideDate == null) { TextTitle subtitle = new TextTitle(fromDate.toString() + " - " + toDate.toString()); subtitle.setFont(font); chart.addSubtitle(subtitle); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("No Data Available"); // Add abnormal/critical range background color (only for single-concept graphs) if (concept2 == null) { IntervalMarker abnormalLow, abnormalHigh, critical; if (normalHigh != null) { abnormalHigh = new IntervalMarker(normalHigh, maxRange, COLOR_ABNORMAL); plot.addRangeMarker(abnormalHigh); } if (normalLow != null) { abnormalLow = new IntervalMarker(minRange, normalLow, COLOR_ABNORMAL); plot.addRangeMarker(abnormalLow); } if (criticalHigh != null) { critical = new IntervalMarker(criticalHigh, maxRange, COLOR_CRITICAL); plot.addRangeMarker(critical); } if (criticalLow != null) { critical = new IntervalMarker(minRange, criticalLow, COLOR_CRITICAL); plot.addRangeMarker(critical); } // there is data outside of the absolute lower limits for this concept (or of what the user specified as minrange) if (plot.getRangeAxis().getLowerBound() < minRange) { IntervalMarker error = new IntervalMarker(plot.getRangeAxis().getLowerBound(), minRange, COLOR_ERROR); plot.addRangeMarker(error); } if (plot.getRangeAxis().getUpperBound() > maxRange) { IntervalMarker error = new IntervalMarker(maxRange, plot.getRangeAxis().getUpperBound(), COLOR_ERROR); plot.addRangeMarker(error); } } // Visuals XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesFilled(true); renderer.setBaseShapesVisible(true); } // Customize the plot (range and domain axes) // Modify x-axis (datetime) DateAxis timeAxis = (DateAxis) plot.getDomainAxis(); if (timeScale == Day.class) { timeAxis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy")); } timeAxis.setRange(fromDate, toDate); // Set y-axis range (values) NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (userSpecifiedMinRange) { minRange = (rangeAxis.getLowerBound() < minRange) ? rangeAxis.getLowerBound() : minRange; } if (userSpecifiedMaxRange) { // otherwise we just use default range maxRange = (rangeAxis.getUpperBound() > maxRange) ? rangeAxis.getUpperBound() : maxRange; } rangeAxis.setRange(minRange, maxRange); return chart; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * *//*from w w w .j a v a 2s. c om*/ protected void configureChart(JFreeChart jfreeChart) throws JRException { if (getChart().getModeValue() == ModeEnum.OPAQUE) { jfreeChart.setBackgroundPaint(getChart().getBackcolor()); } else { jfreeChart.setBackgroundPaint(null); } RectangleEdge titleEdge = getEdge(getChart().getTitlePositionValue(), RectangleEdge.TOP); if (jfreeChart.getTitle() != null) { TextTitle title = jfreeChart.getTitle(); title.setPaint(getChart().getTitleColor()); title.setFont(fontUtil.getAwtFont(getFont(getChart().getTitleFont()), getLocale())); title.setPosition(titleEdge); } String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression()); if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); subtitle.setPaint(getChart().getSubtitleColor()); subtitle.setFont(fontUtil.getAwtFont(getFont(getChart().getSubtitleFont()), getLocale())); subtitle.setPosition(titleEdge); jfreeChart.addSubtitle(subtitle); } // Apply all of the legend formatting options LegendTitle legend = jfreeChart.getLegend(); if (legend != null) { legend.setItemPaint(getChart().getLegendColor()); if (getChart().getOwnLegendBackgroundColor() == null)// in a way, legend backcolor inheritance from chart is useless { legend.setBackgroundPaint(null); } else { legend.setBackgroundPaint(getChart().getLegendBackgroundColor()); } legend.setItemFont(fontUtil.getAwtFont(getFont(getChart().getLegendFont()), getLocale())); legend.setPosition(getEdge(getChart().getLegendPositionValue(), RectangleEdge.BOTTOM)); } configurePlot(jfreeChart.getPlot()); }
From source file:hr.restart.util.chart.ChartXYZ.java
/** * Creates a LINE CHART.// w ww .j a va 2 s .c om * * @param dataset The org.jfree.data.CategoryDataset * @param title The title * @return org.jfree.chart.JFreeChart */ final private JFreeChart createLineChart(final CategoryDataset dataset, String title) { // create the chart... final JFreeChart chart = ChartFactory.createLineChart(title, // chart title "", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); //print the subtitles java.util.List subs = getSubtitles(); if (subs != null) for (int i = 0; i < subs.size(); i++) { chart.addSubtitle(new TextTitle(subs.get(i).toString())); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final StandardLegend legend = (StandardLegend) chart.getLegend(); legend.setDisplaySeriesShapes(true); legend.setShapeScaleX(1.5); legend.setShapeScaleY(1.5); legend.setDisplaySeriesLines(true); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); //plot.setBackgroundPaint(Color.lightGray); //plot.setRangeGridlinePaint(Color.white); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setDrawShapes(true); adjustLineRenderer(renderer); // renderer.setSeriesStroke( // 0, new BasicStroke( // 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, // 1.0f, new float[] {10.0f, 6.0f}, 0.0f // ) // ); // renderer.setSeriesStroke( // 1, new BasicStroke( // 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, // 1.0f, new float[] {6.0f, 6.0f}, 0.0f // ) // ); // renderer.setSeriesStroke( // 2, new BasicStroke( // 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, // 1.0f, new float[] {2.0f, 6.0f}, 0.0f // ) // ); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortCounterXYplotPanel.java
private JFreeChart createChart() { // 1. counter value ///*from w w w . j a v a 2s . c o m*/ // -- see worker thread for following axis -- // // 2. delta/period // // -- if error counter -- // 3. include xmit and rcv traffic deltas? (own scale) // // // -- if traffic counter -- // 3. include rate and utilization values? // SMT_UpdateService updateService = SMT_UpdateService.getInstance(); OMS_Collection history = updateService.getCollection(); if ((history == null) || (history.getSize() < 2)) { // need at least two datapoints to this chart to make sense logger.severe("OMS Delta unavailable, cannot createChart(), must wait for more historical snapshots"); MessageManager.getInstance().postMessage( new SmtMessage(SmtMessageType.SMT_MSG_SEVERE, "Cannot build chart without historical data")); return null; } MessageManager.getInstance() .postMessage(new SmtMessage(SmtMessageType.SMT_MSG_INFO, "Worker Building Plot")); long deltaPeriod = history.getAveDeltaSeconds(); // the primary dataset of the desired counter which will be axis1 XYDataset dataset1 = createDataset(history); // setup the chart for the desired counter JFreeChart chart = ChartFactory.createTimeSeriesChart( PortCounter.getName() + " [" + Vertex.getName() + " port " + Port.getPortNumber() + "]", "Time of Day", PortCounterAxisLabel.COUNTS.getName(), dataset1, true, true, false); chart.addSubtitle(new TextTitle("Port Counter Activity (" + deltaPeriod + " sec. delta)")); XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainPannable(true); plot.setRangePannable(true); plot.getRangeAxis().setFixedDimension(15.0); return chart; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * //w w w .j av a 2s . c om * DOC zshen Comment method "createMatchRuleBarChart". * * @param title * @param dataset * @return */ public static JFreeChart createMatchRuleBarChart(String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset) { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart localJFreeChart = ChartFactory.createBarChart(null, categoryAxisLabel, valueAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false); localJFreeChart.addSubtitle(new TextTitle( Messages.getString("DataChart.title", sumItemCount(dataset), sumGroupCount(dataset)))); //$NON-NLS-1$ CategoryPlot plot = (CategoryPlot) localJFreeChart.getPlot(); // get real color list from ChartDecorator.COLOR_LIST dataset.getColumnKeys() List<Color> currentColorList = null; try { currentColorList = getCurrentColorList(dataset.getColumnKeys()); } catch (NumberFormatException e) { log.warn(e, e); currentColorList = ChartDecorator.COLOR_LIST; } BarRenderer barRenderer = new TalendBarRenderer(true, currentColorList); barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); barRenderer.setBaseItemLabelsVisible(true); // remove the shadow barRenderer.setShadowVisible(Boolean.FALSE); plot.setRenderer(barRenderer); CategoryAxis localCategoryAxis = plot.getDomainAxis(); localCategoryAxis.setCategoryMargin(0.25D); localCategoryAxis.setUpperMargin(0.02D); localCategoryAxis.setLowerMargin(0.02D); NumberAxis localNumberAxis = (NumberAxis) plot.getRangeAxis(); localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); localNumberAxis.setUpperMargin(0.1D); return localJFreeChart; }
From source file:org.leo.benchmark.Benchmark.java
/** * Create a chartpanel/*from w w w.ja v a 2 s . c o m*/ * * @param title title * @param dataName name of the data * @param clazzResult data mapped by classes * @param catItemLabelGenerator label generator * @return the chartPanel */ @SuppressWarnings("serial") private ChartPanel createChart(String title, String dataName, Map<Class<? extends Collection<?>>, Long> clazzResult, AbstractCategoryItemLabelGenerator catItemLabelGenerator) { // sort data by class name List<Class<? extends Collection<?>>> clazzes = new ArrayList<Class<? extends Collection<?>>>( clazzResult.keySet()); Collections.sort(clazzes, new Comparator<Class<? extends Collection<?>>>() { @Override public int compare(Class<? extends Collection<?>> o1, Class<? extends Collection<?>> o2) { return o1.getCanonicalName().compareTo(o2.getCanonicalName()); } }); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); // add the data to the dataset for (Class<? extends Collection<?>> clazz : clazzes) { dataSet.addValue(clazzResult.get(clazz), clazz.getName(), title.split(" ")[0]); } // create the chart JFreeChart chart = ChartFactory.createBarChart3D(null, null, dataName, dataSet, PlotOrientation.HORIZONTAL, false, true, false); chart.addSubtitle(new TextTitle(title)); // some customization in the style CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(new Color(250, 250, 250)); plot.setDomainGridlinePaint(new Color(255, 200, 200)); plot.setRangeGridlinePaint(Color.BLUE); plot.getDomainAxis().setVisible(false); plot.getRangeAxis().setLabelFont(new Font("arial", Font.PLAIN, 10)); BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer(); // display the class name in the bar chart for (int i = 0; i < clazzResult.size(); i++) { renderer.setSeriesItemLabelGenerator(i, new StandardCategoryItemLabelGenerator() { @Override public String generateLabel(CategoryDataset dataset, int row, int column) { String label = " " + dataset.getRowKey(row).toString(); if (dataset.getValue(row, column).equals(timeout * 1000000)) { label += " (Timeout)"; } return label; } }); renderer.setSeriesItemLabelsVisible(i, true); ItemLabelPosition itemPosition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0); renderer.setSeriesPositiveItemLabelPosition(i, itemPosition); renderer.setSeriesNegativeItemLabelPosition(i, itemPosition); } ItemLabelPosition itemPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0); renderer.setPositiveItemLabelPositionFallback(itemPosition); renderer.setNegativeItemLabelPositionFallback(itemPosition); renderer.setShadowVisible(false); // create the chartpanel ChartPanel chartPanel = new ChartPanel(chart); chart.setBorderVisible(true); return chartPanel; }
From source file:hr.restart.util.chart.ChartXYZ.java
/** * Creates a BAR CHART./*from w w w .ja v a 2 s . c o m*/ * * @param dataset The org.jfree.data.CategoryDataset * @param title The title * @return org.jfree.chart.JFreeChart */ final private JFreeChart createBarChart(final CategoryDataset dataset, String title) { final JFreeChart chart = ChartFactory.createBarChart(title, // chart title "", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // include legend true, false); chart.setBackgroundPaint(Color.white); //print the subtitles java.util.List subs = getSubtitles(); if (subs != null) { for (int i = 0; i < subs.size(); i++) { chart.addSubtitle(new TextTitle(subs.get(i).toString())); } } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // 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); renderer.setItemMargin(getItemMargin()); adjustBarRenderer(renderer); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryMargin(getCategoryMargin()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }