List of usage examples for org.jfree.chart.title TextTitle TextTitle
public TextTitle(String text, Font font)
From source file:skoa.helpers.Graficos.java
/********************************************************************************************************* * FUNCIONES PARA CREAR LOS GRFICOS DE LA CONSULTA D! MANIPULANDO LOS DATOS OBTENIDOS DE LAS CONSULTAS.* *********************************************************************************************************/ private void difPorc() { //Aplicarle la frmula a los valores de las dos direcciones, obteniendo un slo fichero. aplicarFormula(1); //Se le aplica con porcentajes. //En este tipo de consultas, buscamos el tipo que es y la unidad, para que se vean. String tipo = unidad.substring(0, unidad.indexOf("\t")); unidad = unidad.substring(unidad.indexOf("\t") + 1); if (unidad.indexOf("C") >= 0) unidad = "C"; TimeSeries serie = obtenerSerieEvolucion2(); //Reutilizamos este cdigo. TimeSeriesCollection dataset = new TimeSeriesCollection(serie); //Slo se obtiene una curva. JFreeChart grafica = ChartFactory.createTimeSeriesChart("Valores medidos de las direcciones de grupo", //titulo "Fechas", //titulo eje x "Mediciones en " + tipo + " " + "(" + unidad + ")", //titulo eje y dataset, //dataset true, //leyenda true, //tooltips false); //configure chart to generate URLs? //Dar color a cada categoria grafica.setBackgroundPaint(Color.WHITE); //Color del fondo del grfico if (fechaInicial.equals("") & fechaFinal.equals("")) { //Si estn vacas es porque no hay resultados para ese intervalo. fechaInicial = " ? "; fechaFinal = " ? "; }/*w w w . j av a2 s . co m*/ TextTitle t = new TextTitle("desde " + fechaInicial + " hasta " + fechaFinal, new Font("SanSerif", Font.ITALIC, 12)); grafica.addSubtitle(t); try { ChartUtilities.saveChartAsJPEG(new File(ruta + "DiferenciasSmall.jpg"), grafica, 400, 300); ChartUtilities.saveChartAsJPEG(new File(ruta + "DiferenciasBig.jpg"), grafica, 900, 600); } catch (IOException e1) { System.err.println("Problem occurred creating chart."); } }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a basic wafermap chart with a random dataset * * @return a wafermap chart//from www. ja va 2 s.c om */ public JFreeChart createWaferMapChartValueIndexed() { final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(500); final JFreeChart chart = ChartFactory.createWaferMapChart("Wafer Map Demo - Value Indexed", // title dataset, // wafermapdataset PlotOrientation.VERTICAL, // vertical = notchdown true, // legend false, // tooltips false); // final Legend legend = chart.getLegend(); // legend.setAnchor(Legend.EAST); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final TextTitle copyright = new TextTitle("JFreeChart WaferMapPlot", new Font("SansSerif", Font.PLAIN, 9)); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); return chart; }
From source file:skoa.helpers.Graficos.java
private void difAbs() { //Aplicarle la frmula a los valores de las dos direcciones, obteniendo un slo fichero. aplicarFormula(2); //Se le aplica con porcentajes. String tipo = unidad.substring(0, unidad.indexOf("\t")); if (tipo.contentEquals("ABS")) tipo = "DIF"; unidad = unidad.substring(unidad.indexOf("\t") + 1); if (unidad.indexOf("C") >= 0) unidad = "C"; TimeSeries serie = obtenerSerieEvolucion2(); //Reutilizamos este cdigo. TimeSeriesCollection dataset = new TimeSeriesCollection(serie); //Slo se obtiene una curva. JFreeChart grafica = ChartFactory.createTimeSeriesChart("Valores medidos de las direcciones de grupo", //titulo "Fechas", //titulo eje x "Mediciones en " + tipo + " " + "(" + unidad + ")", //titulo eje y dataset, //dataset true, //leyenda true, //tooltips false); //configure chart to generate URLs? //Dar color a cada categoria grafica.setBackgroundPaint(Color.WHITE); //Color del fondo del grafico if (fechaInicial.equals("") & fechaFinal.equals("")) { //Si estan vacas es porque no hay resultados para ese intervalo. fechaInicial = " ? "; fechaFinal = " ? "; }/*from www.j a v a2 s . c o m*/ TextTitle t = new TextTitle("desde " + fechaInicial + " hasta " + fechaFinal, new Font("SanSerif", Font.ITALIC, 12)); grafica.addSubtitle(t); try { ChartUtilities.saveChartAsJPEG(new File(ruta + "DiferenciasSmall.jpg"), grafica, 400, 300); ChartUtilities.saveChartAsJPEG(new File(ruta + "DiferenciasBig.jpg"), grafica, 900, 600); } catch (IOException e1) { System.err.println("Problem occurred creating chart."); } }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a basic wafermap chart with a random dataset * * @return a wafermap chart/*from ww w . j a va 2s.c om*/ */ public JFreeChart createWaferMapChartPositionIndexed() { final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(500); final WaferMapPlot plot = new WaferMapPlot(dataset); final WaferMapRenderer renderer = new WaferMapRenderer(35, WaferMapRenderer.POSITION_INDEX); plot.setRenderer(renderer); final JFreeChart chart = new JFreeChart("Wafer Map Demo - Position Indexed", JFreeChart.DEFAULT_TITLE_FONT, plot, true); // final Legend legend = chart.getLegend(); // legend.setAnchor(Legend.EAST); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final TextTitle copyright = new TextTitle("JFreeChart WaferMapPlot", new Font("SansSerif", Font.PLAIN, 9)); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); return chart; }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private void setTitle(JFreeChart chart, String title, Font titleFont, Color foregroundColor, List<cfCHARTTITLEData> titles) throws cfmRunTimeException { if (titles.size() > 0) { // One or more CFCHARTTITLE tags were specified so use them to configure // the chart titles for (int i = 0; i < titles.size(); i++) { cfCHARTTITLEData data = titles.get(i); Font font = getFont(data.getFont(), data.getFontBold(), data.getFontItalic(), data.getFontSize()); TextTitle textTitle = new TextTitle(data.getTitle(), font); textTitle.setPaint(convertStringToColor(data.getLabelColor())); textTitle.setBackgroundPaint(convertStringToColor(data.getBackgroundColor())); String pos = data.getPosition(); if (pos.equals("top")) textTitle.setPosition(RectangleEdge.TOP); else if (pos.equals("bottom")) textTitle.setPosition(RectangleEdge.BOTTOM); else if (pos.equals("left")) textTitle.setPosition(RectangleEdge.LEFT); else if (pos.equals("right")) textTitle.setPosition(RectangleEdge.RIGHT); if (!data.getShowBorder()) textTitle.setBorder(BlockBorder.NONE); else//from w w w . j ava 2 s . c o m textTitle.setBorder(new BlockBorder()); textTitle.setPadding(data.getPadding(), data.getPadding(), data.getPadding(), data.getPadding()); textTitle.setMargin(data.getMargin(), data.getMargin(), data.getMargin(), data.getMargin()); chart.addSubtitle(textTitle); } } else { // A CFCHARTTITLE tag was NOT specified so use the CFCHART attributes to // configure the chart title if (title == null) return; TextTitle textTitle = new TextTitle(title, titleFont); textTitle.setPaint(foregroundColor); // Add a border around the title to match CFMX 7 textTitle.setBorder(new BlockBorder()); textTitle.setPadding(10, 10, 10, 10); textTitle.setMargin(5, 5, 5, 5); chart.setTitle(textTitle); } }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_/* w w w . j a v a 2 s . c o m*/ * * @param pt1 _more_ * * @throws Exception _more_ */ protected void processReadout(FlythroughPoint pt1) throws Exception { Font font = new Font("Dialog", Font.BOLD, 22); dials = new ArrayList<JComponent>(); if ((readoutLabel == null) || (pt1 == null)) { return; } List<ReadoutInfo> samples = new ArrayList<ReadoutInfo>(); readoutLabel.setText(readout.getReadout(pt1.getEarthLocation(), showReadout, true, samples)); if (!showReadout) { return; } List comps = new ArrayList(); for (FlythroughDecorator decorator : decorators) { decorator.handleReadout(pt1, samples); } for (ReadoutInfo info : samples) { Real r = info.getReal(); if (r == null) { continue; } Unit unit = info.getUnit(); if (unit == null) { unit = r.getUnit(); } String name = ucar.visad.Util.cleanTypeName(r.getType()); String unitSuffix = ""; if (unit != null) { unitSuffix = " [" + unit + "]"; } double v = r.getValue(unit); if (v == v) { v = Misc.parseNumber(Misc.format(v)); } JLabel label = new JLabel(name.replace("_", " ")); label.setFont(font); DefaultValueDataset dataset = new DefaultValueDataset(new Double(v)); MeterPlot plot = new MeterPlot(dataset); if (info.getRange() != null) { Range range = info.getRange(); plot.setRange(new org.jfree.data.Range(range.getMin(), range.getMax())); } if (unit != null) { plot.setUnits(unit.toString()); } else { plot.setUnits(""); } plot.setDialBackgroundPaint(Color.white); plot.setTickLabelsVisible(true); plot.setValueFont(font); plot.setTickLabelFont(font); plot.setTickLabelPaint(Color.darkGray); plot.setTickPaint(Color.black); plot.setValuePaint(Color.black); JFreeChart chart = new JFreeChart("", plot); TextTitle title = new TextTitle(" " + label.getText() + " ", font); title.setBackgroundPaint(Color.gray); title.setPaint(Color.white); chart.setTitle(title); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(dialDimension); chartPanel.setSize(new Dimension(150, 150)); plot.setBackgroundPaint(new Color(255, 255, 255, 0)); plot.setBackgroundImageAlpha(0.0f); chart.setBackgroundPaint(new Color(255, 255, 255, 0)); chartPanel.setBackground(new Color(255, 255, 255, 0)); comps.add(chartPanel); dials.add(chartPanel); } readoutDisplay.removeAll(); updateDashboard(); }
From source file:org.jfree.chart.ChartFactory.java
/** * Creates a pie chart with default settings that compares 2 datasets. * The color of each section will be determined by the move from the value * for the same key in {@code previousDataset}. ie if value1 > value2 * then the section will be in green (unless {@code greenForIncrease} * is {@code false}, in which case it would be {@code red}). * Each section can have a shade of red or green as the difference can be * tailored between 0% (black) and percentDiffForMaxScale% (bright * red/green)./*from w ww. jav a 2 s . c o m*/ * <p> * For instance if {@code percentDiffForMaxScale} is 10 (10%), a * difference of 5% will have a half shade of red/green, a difference of * 10% or more will have a maximum shade/brightness of red/green. * <P> * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * <p> * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit * Xhenseval</a>. * * @param title the chart title ({@code null} permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param previousDataset the dataset for the last run, this will be used * to compare each key in the dataset * @param percentDiffForMaxScale scale goes from bright red/green to black, * percentDiffForMaxScale indicate the change * required to reach top scale. * @param greenForIncrease an increase since previousDataset will be * displayed in green (decrease red) if true. * @param locale the locale ({@code null} not permitted). * @param subTitle displays a subtitle with color scheme if true * @param showDifference create a new dataset that will show the % * difference between the two datasets. * * @return A pie chart. * * @since 1.0.7 */ public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset, int percentDiffForMaxScale, boolean greenForIncrease, Locale locale, boolean subTitle, boolean showDifference) { PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); List<Comparable> keys = dataset.getKeys(); DefaultPieDataset series = null; if (showDifference) { series = new DefaultPieDataset(); } double colorPerPercent = 255.0 / percentDiffForMaxScale; for (Comparable key : keys) { Number newValue = dataset.getValue(key); Number oldValue = previousDataset.getValue(key); if (oldValue == null) { if (greenForIncrease) { plot.setSectionPaint(key, Color.GREEN); } else { plot.setSectionPaint(key, Color.RED); } if (showDifference) { assert series != null; // suppress compiler warning series.setValue(key + " (+100%)", newValue); } } else { double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0; double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent); if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); } else { plot.setSectionPaint(key, new Color((int) shade, 0, 0)); } if (showDifference) { assert series != null; // suppress compiler warning series.setValue( key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue); } } } if (showDifference) { plot.setDataset(series); } JFreeChart chart = new JFreeChart(title, plot); if (subTitle) { TextTitle subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle); } currentTheme.apply(chart); return chart; }
From source file:org.jfree.chart.ChartFactory.java
/** * Creates a pie chart with default settings that compares 2 datasets. * The color of each section will be determined by the move from the value * for the same key in {@code previousDataset}. ie if value1 > value2 * then the section will be in green (unless {@code greenForIncrease} * is {@code false}, in which case it would be {@code red}). * Each section can have a shade of red or green as the difference can be * tailored between 0% (black) and percentDiffForMaxScale% (bright * red/green)./*from ww w. j a v a2s . c o m*/ * <p> * For instance if {@code percentDiffForMaxScale} is 10 (10%), a * difference of 5% will have a half shade of red/green, a difference of * 10% or more will have a maximum shade/brightness of red/green. * <P> * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * <p> * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit * Xhenseval</a>. * * @param title the chart title ({@code null} permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param previousDataset the dataset for the last run, this will be used * to compare each key in the dataset * @param percentDiffForMaxScale scale goes from bright red/green to black, * percentDiffForMaxScale indicate the change * required to reach top scale. * @param greenForIncrease an increase since previousDataset will be * displayed in green (decrease red) if true. * @param subTitle displays a subtitle with color scheme if true * @param showDifference create a new dataset that will show the % * difference between the two datasets. * * @return A pie chart. */ public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset, int percentDiffForMaxScale, boolean greenForIncrease, boolean subTitle, boolean showDifference) { PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); plot.setToolTipGenerator(new StandardPieToolTipGenerator()); List<Comparable> keys = dataset.getKeys(); DefaultPieDataset series = null; if (showDifference) { series = new DefaultPieDataset(); } double colorPerPercent = 255.0 / percentDiffForMaxScale; for (Comparable key : keys) { Number newValue = dataset.getValue(key); Number oldValue = previousDataset.getValue(key); if (oldValue == null) { if (greenForIncrease) { plot.setSectionPaint(key, Color.GREEN); } else { plot.setSectionPaint(key, Color.RED); } if (showDifference) { assert series != null; // suppresses compiler warning series.setValue(key + " (+100%)", newValue); } } else { double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0; double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent); if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); } else { plot.setSectionPaint(key, new Color((int) shade, 0, 0)); } if (showDifference) { assert series != null; // suppresses compiler warning series.setValue( key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue); } } } if (showDifference) { plot.setDataset(series); } JFreeChart chart = new JFreeChart(title, plot); if (subTitle) { TextTitle subtitle; subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle); } currentTheme.apply(chart); return chart; }
From source file:org.jfree.chart.ChartFactory.java
/** * Creates a chart that displays multiple pie plots. The chart object * returned by this method uses a {@link MultiplePiePlot} instance as the * plot.//from w w w .j a v a 2 s. c o m * * @param title the chart title ({@code null} permitted). * @param dataset the dataset ({@code null} permitted). * @param order the order that the data is extracted (by row or by column) * ({@code null} not permitted). * * @return A chart. */ public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order) { ParamChecks.nullNotPermitted(order, "order"); MultiplePiePlot plot = new MultiplePiePlot(dataset); plot.setDataExtractOrder(order); plot.setBackgroundPainter(null); plot.setBorderPainter(null); JFreeChart pieChart = new JFreeChart(new PiePlot3D(null)); TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); seriesTitle.setPosition(RectangleEdge.BOTTOM); pieChart.setTitle(seriesTitle); pieChart.removeLegend(); pieChart.setBackgroundPainter(null); plot.setPieChart(pieChart); PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setToolTipGenerator(tooltipGenerator); JFreeChart chart = new JFreeChart(title, plot); currentTheme.apply(chart); return chart; }