List of usage examples for org.jfree.chart StandardChartTheme createLegacyTheme
public static ChartTheme createLegacyTheme()
From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java
/** Creates a new instance of JFreeChartHandler */ public ChartHandler() { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); }
From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesbarchart.ResultsProccessor.java
public void writeToFile(String outName) throws FileNotFoundException, UnsupportedEncodingException, IOException { calcMeans();/*from www . ja v a 2 s .co m*/ calcAvgRulesBySeed(); // Create JFreeChart Dataset DefaultCategoryDataset dataset = new DefaultCategoryDataset(); HashMap<String, Double> measuresFirst = algorithmMeasures.entrySet().iterator().next().getValue(); for (Map.Entry<String, Double> measure : measuresFirst.entrySet()) { String measureName = measure.getKey(); //Double measureValue = measure.getValue(); dataset.clear(); for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); Double measureValue = entry.getValue().get(measureName); // Parse algorithm name to show it correctly String aName = alg.substring(0, alg.length() - 1); int startAlgName = aName.lastIndexOf("/"); aName = aName.substring(startAlgName + 1); dataset.addValue(measureValue, aName, measureName); ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart barChart = ChartFactory.createBarChart("Assotiation Rules Measures", measureName, measureName, dataset, PlotOrientation.VERTICAL, true, true, false); StandardChartTheme.createLegacyTheme().apply(barChart); CategoryItemRenderer renderer = barChart.getCategoryPlot().getRenderer(); // Black and White int numItems = algorithmMeasures.size(); for (int i = 0; i < numItems; i++) { Color color = Color.DARK_GRAY; if (i % 2 == 1) { color = Color.LIGHT_GRAY; } renderer.setSeriesPaint(i, color); renderer.setSeriesOutlinePaint(i, Color.BLACK); } int width = 640 * 2; /* Width of the image */ int height = 480 * 2; /* Height of the image */ // JPEG File BarChart = new File(outName + "_" + measureName + "_barchart.jpg"); ChartUtilities.saveChartAsJPEG(BarChart, barChart, width, height); // SVG SVGGraphics2D g2 = new SVGGraphics2D(width, height); Rectangle r = new Rectangle(0, 0, width, height); barChart.draw(g2, r); File BarChartSVG = new File(outName + "_" + measureName + "_barchart.svg"); SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement()); } } /* for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); HashMap<String, Double> measures = entry.getValue(); for (Map.Entry<String, Double> entry1 : measures.entrySet()) { String measureName = entry1.getKey(); Double measureValue = entry1.getValue(); dataset.addValue(measureValue, alg, measureName); } } */ }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * This is a helper method for creating charts and is split off as it does * only the chart creation and tweaking of a category chart. All of the * decisions for what columns are defined as what and how the data is stored * should be done in the method that calls this. * <p>/* w w w . ja v a 2 s .c om*/ * Given a dataset and other chart properties this will create an * appropriate JFreeChart. * @param c * * @param dataset * The data to create a chart from. * @param chartType * The type of chart to create for the category dataset. * @param legendPosition * The position where the legend should appear. * @param chartName * The title of the chart. * @param yaxisName * The title of the Y axis. * @param xaxisName * The title of the X axis. * @return A JFreeChart that represents the dataset given. */ private static JFreeChart createCategoryChartFromDataset(Chart c, CategoryDataset dataset, ChartType chartType, LegendPosition legendPosition, String chartName, String yaxisName, String xaxisName) { if (chartType == null || dataset == null) { return null; } boolean showLegend = !legendPosition.equals(LegendPosition.NONE); JFreeChart chart; ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); BarRenderer.setDefaultBarPainter(new StandardBarPainter()); if (chartType == ChartType.BAR) { chart = ChartFactory.createBarChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL, showLegend, true, false); } else if (chartType == ChartType.PIE) { chart = createPieChart(chartName, dataset, TableOrder.BY_ROW, showLegend, true, false); } else if (chartType == ChartType.CATEGORY_LINE) { chart = ChartFactory.createLineChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL, showLegend, true, false); } else { throw new IllegalArgumentException("Unknown chart type " + chartType + " for a category dataset."); } if (chart == null) return null; if (legendPosition != LegendPosition.NONE) { chart.getLegend().setPosition(legendPosition.getRectangleEdge()); //chart.getTitle().setPadding(4,4,15,4); } if (chart.getPlot() instanceof MultiplePiePlot) { MultiplePiePlot mplot = (MultiplePiePlot) chart.getPlot(); PiePlot plot = (PiePlot) mplot.getPieChart().getPlot(); plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE); if (showLegend) { // for now, legend and items labels are mutually exclusive. Could make this a user pref. plot.setLabelGenerator(null); } } if (!c.isAutoYAxisRange()) { CategoryPlot plot = chart.getCategoryPlot(); ValueAxis axis = plot.getRangeAxis(); axis.setAutoRange(false); axis.setRange(c.getYAxisMinRange(), c.getYAxisMaxRange()); } return chart; }
From source file:org.opennms.netmgt.charts.ChartUtils.java
/** * Helper method that returns the JFreeChart to an output stream written in JPEG format. * * @param chartName a {@link java.lang.String} object. * @param out a {@link java.io.OutputStream} object. * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. * @throws java.io.IOException if any.//from w w w. j ava 2s . c o m * @throws java.sql.SQLException if any. */ public static void getBarChartPNG(String chartName, OutputStream out) throws MarshalException, ValidationException, IOException, SQLException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); BarChart chartConfig = getBarChartConfigByName(chartName); JFreeChart chart = getBarChart(chartName); if (chartConfig.getChartBackgroundColor() != null) { setChartBackgroundColor(chartConfig, chart); } if (chartConfig.getPlotBackgroundColor() != null) { setPlotBackgroundColor(chartConfig, chart); } ImageSize imageSize = chartConfig.getImageSize(); int hzPixels; int vtPixels; if (imageSize == null) { hzPixels = 400; vtPixels = 400; } else { hzPixels = imageSize.getHzSize().getPixels(); vtPixels = imageSize.getVtSize().getPixels(); } ChartUtilities.writeChartAsPNG(out, chart, hzPixels, vtPixels, false, 6); }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * /* w ww . j a v a 2s . c o m*/ * DOC zhaoxinyi Comment method "createGanttChart". * * @return */ public static JFreeChart createGanttChart(String chartAxies, Object ganttDataset) { // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ JFreeChart chart = ChartFactory.createGanttChart("", // chart title //$NON-NLS-1$ Messages.getString("TopChartFactory.Categories"), // domain axis label //$NON-NLS-1$ chartAxies, // range axis label (TaskSeriesCollection) ganttDataset, // data true, // include legend true, // tooltips false // urls ); // ADD TDQ-5251 msjian 2012-7-31: do not display the shadow CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); // TDQ-5251~ 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 w w.j a v a2 s . c o m * * @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:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * /*from w w w. ja v a 2s . co m*/ * mzhao create bar chart with default bar render class. * * @param titile * @param dataset * @param showLegend * @return */ public static JFreeChart createBarChart(String titile, CategoryDataset dataset, boolean showLegend) { // MOD hcheng for 6965,Use 2D bar charts instead of 3D bar charts // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ JFreeChart chart = ChartFactory.createBarChart(null, titile, Messages.getString("TopChartFactory.count"), //$NON-NLS-1$ dataset, PlotOrientation.VERTICAL, showLegend, true, false); ChartDecorator.decorateBarChart(chart, new TalendBarRenderer(true, ChartDecorator.COLOR_LIST)); return chart; }
From source file:jhplot.HChart.java
/** * Set a custom theme for chart.. It can be: LEGACY_THEME, JFREE_THEME, * DARKNESS_THEME//from w w w. ja v a2s .co m * * @param s * a theme, can be either LEGACY_THEME, JFREE_THEME, * DARKNESS_THEME */ public void setTheme(String s) { if (s.equals("LEGACY_THEME")) { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); applyThemeToChart(); } else if (s.equals("JFREE_THEME")) { ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme()); applyThemeToChart(); } else if (s.equals("DARKNESS_THEME")) { ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme()); applyThemeToChart(); } }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * create bar chart./*from w w w .j av a2s.c o m*/ * * @param titile * @param dataset * @return */ public static JFreeChart createBarChartByKCD(String title, CategoryDataset dataset, Object cusmomerDataset) { // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ JFreeChart createBarChart = ChartFactory.createBarChart(null, Messages.getString("TopChartFactory.Value"), //$NON-NLS-1$ title, dataset, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot plot = createBarChart.getCategoryPlot(); if (cusmomerDataset != null) { plot.setDataset(1, new EncapsulationCumstomerDataset(dataset, cusmomerDataset)); } CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelPaint(NULL_FIELD, Color.RED); domainAxis.setTickLabelPaint(NULL_FIELD2, Color.RED); domainAxis.setTickLabelPaint(EMPTY_FIELD, Color.RED); // ADD TDQ-5251 msjian 2012-7-31: do not display the shadow BarRenderer renderer = new TalendBarRenderer(false, ChartDecorator.COLOR_LIST); renderer.setShadowVisible(false); // TDQ-5251~ plot.setRenderer(renderer); return createBarChart; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * /* ww w . j ava 2 s.c o m*/ * 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; }