List of usage examples for org.jfree.chart JFreeChart addSubtitle
public void addSubtitle(Title subtitle)
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample time series chart. * * @return a sample time series chart.//w w w. j av a2 s . c om */ public JFreeChart createTimeSeries1Chart() { // create a default chart based on some sample data... final String title = this.resources.getString("timeseries.sample1.title"); final String subtitle = this.resources.getString("timeseries.sample1.subtitle"); final String domain = this.resources.getString("timeseries.sample1.domain"); final String range = this.resources.getString("timeseries.sample1.range"); final String copyrightStr = this.resources.getString("timeseries.sample1.copyright"); final XYDataset data = DemoDatasetFactory.createTimeSeriesCollection3(); final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, data, true, true, false); // then customise it a little... final TextTitle title2 = new TextTitle(subtitle, new Font("SansSerif", Font.PLAIN, 12)); // title2.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.0)); chart.addSubtitle(title2); final TextTitle copyright = new TextTitle(copyrightStr, new Font("SansSerif", Font.PLAIN, 9)); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final XYPlot plot = chart.getXYPlot(); final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setVerticalTickLabels(true); return chart; }
From source file:cnu.eslab.fileTest.NewJFrame.java
public void PieGraphGenerate(String[] arGrop, double[] arValue, String arTitle, String arSubTitle) { // ?? ?./* w w w.j a v a 2 s.c o m*/ DefaultPieDataset data = new DefaultPieDataset(); data.setValue(arGrop[0], arValue[0]); //CPU data.setValue(arGrop[1], arValue[1]); //WIFI data.setValue(arGrop[5], arValue[5]); //3G data.setValue(arGrop[2], arValue[2]); //LED data.setValue(arGrop[3], arValue[3]); //GPS data.setValue(arGrop[4], arValue[4]); //AUDIO //offset data . RectangleInsets pieOffset = new RectangleInsets(50.0, 50.0, 50.0, 50.0); // ? ?. JFreeChart chart = ChartFactory.createPieChart(arTitle, data, true, true, false); TextTitle subTitle = new TextTitle(arSubTitle); chart.setBackgroundPaint(Color.WHITE); chart.addSubtitle(subTitle); PiePlot pieplot = (PiePlot) chart.getPlot(); pieplot.setNoDataMessage("No data available"); pieplot.setExplodePercent("LED", 0.20000000000000001D); pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} mW) ({2} percent)")); pieplot.setLabelBackgroundPaint(new Color(220, 220, 220)); pieplot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); //? /*pieplot.setSectionPaint(arGrop[0], new Color(0,0,0)); pieplot.setSectionPaint(arGrop[1], new Color(60,60,60)); pieplot.setSectionPaint(arGrop[2], new Color(120,120,120)); pieplot.setSectionPaint(arGrop[4], new Color(180,180,180));*/ //pieplot.setSimpleLabels(true); //pieplot.setSimpleLabelOffset(pieOffset); //?? offset? . pieplot.setInteriorGap(0.0D); // ?? ?. ChartPanel chartPanel = new ChartPanel(chart); JFrame f = new JFrame(""); f.setSize(600, 600); f.getContentPane().add(chartPanel); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:cnu.eslab.fileTest.NewJFrame.java
public void LineGraphGenerate(ArrayList<Integer> arList, String arTitle, String arSubTitle, String arLineName) { // ??? ?? .//from w w w.ja va 2 s .c om XYSeries series = new XYSeries(arLineName); for (int i = 0; i < arList.size(); i++) { // ? ? . series.add(i, arList.get(i)); } // ? . XYDataset dataset = new XYSeriesCollection(series); // ? ?. JFreeChart chart = ChartFactory.createXYLineChart(arTitle, "Time(sec)", "Power(mW)", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false); TextTitle subTitle = new TextTitle(arSubTitle); chart.setBackgroundPaint(Color.WHITE); chart.addSubtitle(subTitle); ChartPanel chartPanel = new ChartPanel(chart); JFrame f = new JFrame("Power consumption chart"); f.setSize(600, 600); f.getContentPane().add(chartPanel); // ? ? ? close ? . // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
protected void setLegendStyles(JFreeChart chart, UIChart comp) { Boolean showLegend = comp.getShowLegend(); if (showLegend != null && !showLegend) { return;// w w w . j av a 2 s. c om } UILegend legendcomp = comp.getLegend(); if (legendcomp == null) { if (showLegend != null && showLegend) { // Create default legend LegendTitle legend = new LegendTitle(chart.getPlot()); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); } } else { chart.addSubtitle(createLegend(chart, legendcomp)); } }
From source file:net.sf.jasperreports.components.spiderchart.FillSpiderChart.java
protected JFreeChart evaluateChart(byte evaluation) throws JRException { maxValue = (Double) fillContext.evaluate(getPlot().getMaxValueExpression(), evaluation); titleText = (String) fillContext.evaluate(getChartSettings().getTitleExpression(), evaluation); subtitleText = (String) fillContext.evaluate(getChartSettings().getSubtitleExpression(), evaluation); anchorName = (String) fillContext.evaluate(getChartSettings().getAnchorNameExpression(), evaluation); hyperlinkReference = (String) fillContext.evaluate(getChartSettings().getHyperlinkReferenceExpression(), evaluation);//from w w w .j a v a 2s . c o m hyperlinkAnchor = (String) fillContext.evaluate(getChartSettings().getHyperlinkAnchorExpression(), evaluation); hyperlinkPage = (Integer) fillContext.evaluate(getChartSettings().getHyperlinkPageExpression(), evaluation); hyperlinkTooltip = (String) fillContext.evaluate(getChartSettings().getHyperlinkTooltipExpression(), evaluation); hyperlinkParameters = JRFillHyperlinkHelper.evaluateHyperlinkParameters(getChartSettings(), expressionEvaluator, evaluation); dataset.evaluateDatasetRun(evaluation); dataset.finishDataset(); chartHyperlinkProvider = new CategoryChartHyperlinkProvider(dataset.getItemHyperlinks()); bookmarkLevel = getChartSettings().getBookmarkLevel(); SpiderWebPlot spiderWebPlot = new SpiderWebPlot((DefaultCategoryDataset) dataset.getCustomDataset()); if (getPlot().getAxisLineColor() != null) { spiderWebPlot.setAxisLinePaint(getPlot().getAxisLineColor()); } if (getPlot().getAxisLineWidth() != null) { spiderWebPlot.setAxisLineStroke(new BasicStroke(getPlot().getAxisLineWidth())); } if (getPlot().getBackcolor() != null) { spiderWebPlot.setBackgroundPaint(getPlot().getBackcolor()); } if (getPlot().getBackgroundAlpha() != null) { spiderWebPlot.setBackgroundAlpha(getPlot().getBackgroundAlpha()); } if (getPlot().getForegroundAlpha() != null) { spiderWebPlot.setForegroundAlpha(getPlot().getForegroundAlpha()); } if (getPlot().getHeadPercent() != null) { spiderWebPlot.setHeadPercent(getPlot().getHeadPercent()); } if (getPlot().getInteriorGap() != null) { spiderWebPlot.setInteriorGap(getPlot().getInteriorGap()); } if (getPlot().getLabelColor() != null) { spiderWebPlot.setLabelPaint(getPlot().getLabelColor()); } if (getPlot().getLabelFont() != null) { spiderWebPlot.setLabelFont(JRFontUtil.getAwtFont(getPlot().getLabelFont(), Locale.getDefault())); } if (getPlot().getLabelGap() != null) { spiderWebPlot.setAxisLabelGap(getPlot().getLabelGap()); } if (maxValue != null) { spiderWebPlot.setMaxValue(maxValue); } if (getPlot().getRotation() != null) { spiderWebPlot.setDirection(getPlot().getRotation().getRotation()); } if (getPlot().getStartAngle() != null) { spiderWebPlot.setStartAngle(getPlot().getStartAngle()); } if (getPlot().getTableOrder() != null) { spiderWebPlot.setDataExtractOrder(getPlot().getTableOrder().getOrder()); } if (getPlot().getWebFilled() != null) { spiderWebPlot.setWebFilled(getPlot().getWebFilled()); } spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator()); spiderWebPlot.setLabelGenerator(new StandardCategoryItemLabelGenerator()); Font titleFont = getChartSettings().getTitleFont() != null ? JRFontUtil.getAwtFont(getChartSettings().getTitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT; JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true); if (chartSettings.getBackcolor() != null) { jfreechart.setBackgroundPaint(chartSettings.getBackcolor()); } RectangleEdge titleEdge = getEdge(getChartSettings().getTitlePosition(), RectangleEdge.TOP); if (titleText != null) { TextTitle title = jfreechart.getTitle(); title.setText(titleText); if (getChartSettings().getTitleColor() != null) { title.setPaint(getChartSettings().getTitleColor()); } title.setFont(titleFont); title.setPosition(titleEdge); jfreechart.setTitle(title); } if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); subtitle.setText(subtitleText); if (getChartSettings().getSubtitleColor() != null) { subtitle.setPaint(getChartSettings().getSubtitleColor()); } if (getChartSettings().getSubtitleColor() != null) { Font subtitleFont = getChartSettings().getSubtitleFont() != null ? JRFontUtil.getAwtFont(getChartSettings().getSubtitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT; subtitle.setFont(subtitleFont); } subtitle.setPosition(titleEdge); jfreechart.addSubtitle(subtitle); } // Apply all of the legend formatting options LegendTitle legend = jfreechart.getLegend(); if (legend != null) { legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend())); if (legend.isVisible()) { if (getChartSettings().getLegendColor() != null) { legend.setItemPaint(getChartSettings().getLegendColor()); } if (getChartSettings().getLegendBackgroundColor() != null) { legend.setBackgroundPaint(getChartSettings().getLegendBackgroundColor()); } if (getChartSettings().getLegendFont() != null) { legend.setItemFont( JRFontUtil.getAwtFont(getChartSettings().getLegendFont(), Locale.getDefault())); } legend.setPosition(getEdge(getChartSettings().getLegendPosition(), RectangleEdge.BOTTOM)); } } return jfreechart; }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a basic wafermap chart with a random dataset * * @return a wafermap chart/* w ww. j a va 2 s. c o m*/ */ 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:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a basic wafermap chart with a random dataset * * @return a wafermap chart//from www . j av a2 s. c o m */ public JFreeChart createWaferMapChart() { final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(5); final JFreeChart chart = ChartFactory.createWaferMapChart("Wafer Map Demo", // 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:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a basic wafermap chart with a random dataset * * @return a wafermap chart//from ww w . j ava 2s . 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:uom.research.thalassemia.util.PieChartCreator.java
/** * Creates a chart./*from www . j a va2s . c om*/ * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data true, // no legend true, // tooltips false // no URL generation ); // set a custom background for the chart chart.setBackgroundPaint( new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY)); // customise the title position and font TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); // use gradients and white borders for the section colours int itemIndex = 0; for (Object col : pieDataset.getKeys()) { plot.setSectionPaint(col.toString(), gradientPaints[itemIndex]); if (itemIndex == pieDataset.getItemCount() - 1) { itemIndex = 0; } itemIndex++; } plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); return chart; }
From source file:skoa.helpers.Graficos.java
private void barras() { unificarDatosFicheros();/* ww w .j a v a2 s .c om*/ Vector<String> vectorOrdenUnidades = new Vector<String>(); vectorOrdenUnidades = ordenDeUnidades(); aplicarDiferencia(vectorOrdenUnidades); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset = obtenerSerieBarras(vectorOrdenUnidades); String unidad = ""; //for (int i=0;i<vectorOrdenUnidades.size();i++) unidad=unidad+vectorOrdenUnidades.elementAt(i)+", "; for (int i = 0; i < vectorOrdenUnidades.size(); i++) { if (vectorOrdenUnidades.elementAt(i).indexOf("W") >= 0 || vectorOrdenUnidades.elementAt(i).indexOf("L") >= 0 || vectorOrdenUnidades.elementAt(i).indexOf("m") >= 0 || vectorOrdenUnidades.elementAt(i).indexOf("B") >= 0) unidad = unidad + vectorOrdenUnidades.elementAt(i) + ", "; else if (vectorOrdenUnidades.elementAt(i).indexOf("C") >= 0) unidad = unidad + "C, "; else unidad = unidad + ", "; } unidad = unidad.substring(0, unidad.length() - 2); //Quita el ultimo espacio y la ultima coma. JFreeChart grafica = ChartFactory.createBarChart("Valores medidos de las direcciones de grupo", "Fechas", //titulo eje x "Mediciones (" + unidad + ")", dataset, PlotOrientation.VERTICAL, true, //leyenda true, false); if (fechaInicial.isEmpty()) { fechaInicial = fechaFinal = "?"; } TextTitle t = new TextTitle("desde " + fechaInicial + " hasta " + fechaFinal, new Font("SanSerif", Font.ITALIC, 12)); grafica.addSubtitle(t); CategoryPlot plot = grafica.getCategoryPlot(); //Modificar eje X CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); domainAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 8)); //Letra de las fechas ms pequea //Esconder las sombras de las barras del barchart. CategoryPlot categoryPlot = (CategoryPlot) grafica.getPlot(); BarRenderer renderer = new BarRenderer(); renderer.setShadowVisible(false); categoryPlot.setRenderer(renderer); //------------------------------------------------- try { ChartUtilities.saveChartAsJPEG(new File(ruta + "BarrasSmall.jpg"), grafica, 400, 300); ChartUtilities.saveChartAsJPEG(new File(ruta + "BarrasBig.jpg"), grafica, 900, 600); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }