List of usage examples for org.jfree.chart JFreeChart getPlot
public Plot getPlot()
From source file:Util.PacketGenerator.java
public static void GenerateGraph() { try {/*from ww w.j a v a 2s .c om*/ for (int j = 6; j <= 6; j++) { File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\Real.csv"); for (int k = 1; k <= 4; k++) { File simu = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".csv"); FileInputStream simuFIS = new FileInputStream(simu); DataInputStream simuDIS = new DataInputStream(simuFIS); BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS)); FileInputStream realFIS = new FileInputStream(real); DataInputStream realDIS = new DataInputStream(realFIS); BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS)); String lineSimu = simuBR.readLine(); String lineReal = realBR.readLine(); XYSeries matrix = new XYSeries("Matriz", false, true); while (lineSimu != null && lineReal != null) { lineSimu = lineSimu.replaceAll(",", "."); String[] simuMatriz = lineSimu.split(";"); String[] realMatriz = lineReal.split(";"); for (int i = 0; i < simuMatriz.length; i++) { try { Integer valorReal = Integer.parseInt(realMatriz[i]); Float valorSimu = Float.parseFloat(simuMatriz[i]); matrix.add(valorReal.doubleValue() / 1000.0, valorSimu.doubleValue() / 1000.0); } catch (NumberFormatException ex) { } } lineSimu = simuBR.readLine(); lineReal = realBR.readLine(); } simuFIS.close(); simuDIS.close(); simuBR.close(); realFIS.close(); realDIS.close(); realBR.close(); double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1; XYSeries middle = new XYSeries("Referncia"); ; middle.add(0, 0); middle.add(maxPlot, maxPlot); XYSeries max = new XYSeries("Superior 20%"); max.add(0, 0); max.add(maxPlot, maxPlot * 1.2); XYSeries min = new XYSeries("Inferior 20%"); min.add(0, 0); min.add(maxPlot, maxPlot * 0.8); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(middle); dataset.addSeries(matrix); dataset.addSeries(max); dataset.addSeries(min); JFreeChart chart; if (k == 4) { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "CMO-MT", dataset); } else { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "CMO-MT", "Zhao", dataset); } chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 13)); chart.getLegend().setItemFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 10)); chart.getXYPlot().getDomainAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getDomainAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); chart.getXYPlot().getRangeAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getRangeAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 0.1f }, 0.0f)); renderer.setSeriesShape(1, new Ellipse2D.Float(-1.5f, -1.5f, 3f, 3f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesPaint(1, Color.BLACK); renderer.setSeriesPaint(2, Color.BLACK); renderer.setSeriesPaint(3, Color.BLACK); int width = (int) (192 * 1.5f); /* Width of the image */ int height = (int) (144 * 1.5f); /* Height of the image */ File XYChart = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".jpeg"); ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
public static JFreeChart createBasicChart(String title, XYSeriesCollection dataset, String xAxisLabel, String yAxisLabel) {/*from w w w. j av a 2s. c o m*/ JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Palatino"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); LegendTitle subtitle = (LegendTitle) chart.getSubtitles().get(0); subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); Ellipse2D.Float shape = new Ellipse2D.Float(-2.5f, -2.5f, 5.0f, 5.0f); renderer.setSeriesShape(0, shape); } return chart; }
From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java
/** * /*from w ww. j a va 2 s . co m*/ * @param clusters */ public static void buildKMeansChart(final List<Instances> clusters) { final XYSeriesCollection dataset = new XYSeriesCollection(); final JFreeChart chart = ChartFactory.createScatterPlot("", // title "X", "Y", // axis labels dataset, // dataset PlotOrientation.VERTICAL, true, // legend? yes true, // tooltips? yes false // URLs? no ); final XYPlot xyPlot = (XYPlot) chart.getPlot(); ((NumberAxis) xyPlot.getDomainAxis()).setTickUnit(new NumberTickUnit(2.0)); ((NumberAxis) xyPlot.getRangeAxis()).setTickUnit(new NumberTickUnit(2.0)); Attribute clsAttribute = null; int nbClass = 1; Instances cluster0 = clusters.get(0); if (cluster0.classIndex() != -1) { clsAttribute = cluster0.classAttribute(); nbClass = clsAttribute.numValues(); } if (nbClass <= 1) { dataset.addSeries(new XYSeries("Serie #1", false)); } else { for (int i = 0; i < nbClass; i++) { dataset.addSeries(new XYSeries(clsAttribute.value(i), false)); } } final XYToolTipGenerator gen = new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { return "TODO"; } }; for (int i = 0; i < nbClass; i++) { dataset.getSeries(i).clear(); xyPlot.getRenderer().setSeriesToolTipGenerator(i, gen); } final int nbClusters = clusters.size(); for (int i = 0; i < nbClusters; i++) { Instances instances = clusters.get(i); final int nbInstances = instances.numInstances(); for (int j = 0; j < nbInstances; j++) { final Instance oInst = instances.instance(j); dataset.getSeries(i).add(oInst.value(0), oInst.value(1)); } } final TitledBorder titleBorder = new TitledBorder("Kmeans of projection"); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(1200, 900)); chartPanel.setBorder(titleBorder); chartPanel.setBackground(Color.WHITE); JXFrame frame = new JXFrame(); frame.getContentPane().add(chartPanel); frame.setVisible(true); frame.pack(); }
From source file:Data.java
/** * Creates a chart.// w ww.j av a 2 s. com * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Graphique des tempratures et humidits", // title "Date", // x-axis label "Temperture/Humidit", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("d.M.yy HH:mm:ss")); return chart; }
From source file:com.voterData.graph.Graph.java
public static JFreeChart getEthnicityDistbn(Map<String, Double> dataMap) { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); for (String key : dataMap.keySet()) { if (key.equals("HL_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "DEM", "HL_2008"); } else if (key.equals("HL_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "REP", "HL_2008"); } else if (key.equals("HL_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "UNA", "HL_2008"); } else if (key.equals("NL_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "DEM", "NL_2008"); } else if (key.equals("NL_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "REP", "NL_2008"); } else if (key.equals("NL_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "UNA", "NL_2008"); } else if (key.equals("UN_Dem_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "DEM", "UN_2008"); } else if (key.equals("UN_Rep_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "REP", "UN_2008"); } else if (key.equals("UN_Una_2008")) { defaultcategorydataset.addValue(dataMap.get(key), "UNA", "UN_2008"); } else if (key.equals("HL_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "DEM", "HL_2012"); } else if (key.equals("HL_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "REP", "HL_2012"); } else if (key.equals("HL_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "UNA", "HL_2012"); } else if (key.equals("NL_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "DEM", "NL_2012"); } else if (key.equals("NL_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "REP", "NL_2012"); } else if (key.equals("NL_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "UNA", "NL_2012"); } else if (key.equals("UN_Dem_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "DEM", "UN_2012"); } else if (key.equals("UN_Rep_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "REP", "UN_2012"); } else if (key.equals("UN_Una_2012")) { defaultcategorydataset.addValue(dataMap.get(key), "UNA", "UN_2012"); }//from w ww. j a va 2 s. c om } JFreeChart jfreechart = ChartFactory.createStackedBarChart("Ethnicity based Distribution", "Ethnicity_Year", "Total Count", defaultcategorydataset, PlotOrientation.HORIZONTAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); StackedBarRenderer renderer = (StackedBarRenderer) categoryplot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setSeriesPaint(0, Color.green); renderer.setSeriesPaint(1, Color.blue); renderer.setSeriesPaint(2, Color.red); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator()); renderer.setItemLabelsVisible(true); categoryplot.setRenderer(renderer); return jfreechart; }
From source file:org.jfree.chart.demo.SurveyResultsDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart(null, null, null, categorydataset, PlotOrientation.HORIZONTAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle texttitle = new TextTitle( "Figure 7 | I. Resources - The site offers users relevant, informative and educational resources"); texttitle.setHorizontalAlignment(HorizontalAlignment.LEFT); texttitle.setBackgroundPaint(Color.red); texttitle.setPaint(Color.white); jfreechart.setTitle(texttitle);//from w w w . j av a 2s . c om CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setOutlinePaint(null); categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePosition(CategoryAnchor.END); categoryplot.setDomainGridlineStroke(new BasicStroke(0.5F)); categoryplot.setDomainGridlinePaint(Color.black); categoryplot.setRangeGridlinesVisible(false); categoryplot.clearRangeMarkers(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setVisible(false); categoryaxis.setCategoryMargin(0.5D); categoryplot.getRangeAxis().setVisible(false); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setSeriesPaint(0, new Color(156, 164, 74)); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelFont(new Font("SansSerif", 1, 10)); ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); barrenderer.setBasePositiveItemLabelPosition(itemlabelposition); CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("1. White papers are available.", "Category 1", 0.0D); categorytextannotation.setFont(new Font("SansSerif", 1, 12)); categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation); CategoryTextAnnotation categorytextannotation1 = new CategoryTextAnnotation( "2. White papers enhance users understanding of the firm and its expertise.", "Category 2", 0.0D); categorytextannotation1.setFont(new Font("SansSerif", 0, 12)); categorytextannotation1.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation1.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation1); CategoryTextAnnotation categorytextannotation2 = new CategoryTextAnnotation( "3. White papers are relevant to the firm's prospects and clients.", "Category 3", 0.0D); categorytextannotation2.setFont(new Font("SansSerif", 0, 12)); categorytextannotation2.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation2.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation2); CategoryTextAnnotation categorytextannotation3 = new CategoryTextAnnotation( "4. White papers are relevant to the firm's positioning.", "Category 4", 0.0D); categorytextannotation3.setFont(new Font("SansSerif", 0, 12)); categorytextannotation3.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation3.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation3); CategoryTextAnnotation categorytextannotation4 = new CategoryTextAnnotation( "5. Case studies are available.", "Category 5", 0.0D); categorytextannotation4.setFont(new Font("SansSerif", 1, 12)); categorytextannotation4.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation4.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation4); CategoryTextAnnotation categorytextannotation5 = new CategoryTextAnnotation( "6. Case studies enhance users understanding of the firm and its expertise.", "Category 6", 0.0D); categorytextannotation5.setFont(new Font("SansSerif", 0, 12)); categorytextannotation5.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation5.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation5); CategoryTextAnnotation categorytextannotation6 = new CategoryTextAnnotation( "7. Case studies are relevant to the firm's prospects and clients.", "Category 7", 0.0D); categorytextannotation6.setFont(new Font("SansSerif", 0, 12)); categorytextannotation6.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation6.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation6); CategoryTextAnnotation categorytextannotation7 = new CategoryTextAnnotation( "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0D); categorytextannotation7.setFont(new Font("SansSerif", 0, 12)); categorytextannotation7.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation7.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation7); CategoryTextAnnotation categorytextannotation8 = new CategoryTextAnnotation( "9. Case studies are available.", "Category 9", 0.0D); categorytextannotation8.setFont(new Font("SansSerif", 1, 12)); categorytextannotation8.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation8.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation8); CategoryTextAnnotation categorytextannotation9 = new CategoryTextAnnotation( "10. Case studies enhance users understanding of the firm and its expertise.", "Category 10", 0.0D); categorytextannotation9.setFont(new Font("SansSerif", 0, 12)); categorytextannotation9.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation9.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation9); CategoryTextAnnotation categorytextannotation10 = new CategoryTextAnnotation( "11. Case studies are relevant to the firm's prospects and clients.", "Category 11", 0.0D); categorytextannotation10.setFont(new Font("SansSerif", 0, 12)); categorytextannotation10.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation10.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation10); CategoryTextAnnotation categorytextannotation11 = new CategoryTextAnnotation( "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0D); categorytextannotation11.setFont(new Font("SansSerif", 0, 12)); categorytextannotation11.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation11.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation11); CategoryTextAnnotation categorytextannotation12 = new CategoryTextAnnotation( "13. Users can easily access resources based on viewer interest.", "Category 13", 0.0D); categorytextannotation12.setFont(new Font("SansSerif", 1, 12)); categorytextannotation12.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation12.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation12); CategoryTextAnnotation categorytextannotation13 = new CategoryTextAnnotation( "14. Access to additional hyperlinks enhances users's ability to find relevant information.", "Category 14", 0.0D); categorytextannotation13.setFont(new Font("SansSerif", 1, 12)); categorytextannotation13.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation13.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation13); CategoryTextAnnotation categorytextannotation14 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.", "Overall", 0.0D); categorytextannotation14.setFont(new Font("SansSerif", 1, 12)); categorytextannotation14.setTextAnchor(TextAnchor.BOTTOM_LEFT); categorytextannotation14.setCategoryAnchor(CategoryAnchor.START); categoryplot.addAnnotation(categorytextannotation14); return jfreechart; }
From source file:weka.core.ChartUtils.java
/** * Create a pie chart from summary data (i.e. a list of values and their * corresponding frequencies)./* w w w .j av a2 s . c o m*/ * * @param values a list of values for the chart * @param freqs a list of corresponding frequencies * @param showLabels true if the chart will show labels * @param showLegend true if the chart will show a legend * @param additionalArgs optional arguments to the renderer (may be null) * @return a pie chart * @throws Exception if a problem occurs */ protected static JFreeChart getPieChartFromSummaryData(List<String> values, List<Double> freqs, boolean showLabels, boolean showLegend, List<String> additionalArgs) throws Exception { if (values.size() != freqs.size()) { throw new Exception("Number of bins should be equal to number of frequencies!"); } String plotTitle = "Pie Chart"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; String xLabel = getOption(additionalArgs, "-x-label"); xLabel = xLabel == null ? "" : xLabel; String yLabel = getOption(additionalArgs, "-y-label"); yLabel = yLabel == null ? "" : yLabel; DefaultPieDataset dataset = new DefaultPieDataset(); for (int i = 0; i < values.size(); i++) { String binLabel = values.get(i); Number freq = freqs.get(i); dataset.setValue(binLabel, freq); } JFreeChart chart = ChartFactory.createPieChart(plotTitle, // chart title dataset, // data showLegend, // include legend false, false); PiePlot plot = (PiePlot) chart.getPlot(); if (!showLabels) { plot.setLabelGenerator(null); } else { plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); // plot.setCircular(false); plot.setLabelGap(0.02); } chart.setBackgroundPaint(java.awt.Color.white); chart.setTitle(new TextTitle(plotTitle, new Font("SansSerif", Font.BOLD, 12))); return chart; }
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
public static JFreeChart buildBarChart(DefaultCategoryDataset dataset, PlotOrientation orientation, int hSize, int vSize) { JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data orientation, // the plot orientation false, // include legend false, // tooltips false // generate urls );/*from w w w . jav a 2s . co m*/ CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA!"); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); plot.setRenderer(renderer); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.15); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(hSize, vSize)); chart.setBackgroundPaint(Color.white); return chart; }
From source file:org.jfree.graphics2d.demo.SVGTimeSeriesChartDemo1.java
/** * Creates a chart./*www.j a v a 2 s. c o m*/ * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", null, "US cents/lb", dataset); String fontName = "Palatino"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf", new Font(fontName, Font.PLAIN, 14))); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(false); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.setRangeGridlinePaint(Color.GRAY); plot.setDomainGridlinePaint(Color.GRAY); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setDrawSeriesLineAsPath(true); // set the default stroke for all series renderer.setAutoPopulateSeriesStroke(false); renderer.setDefaultStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, new Color(24, 123, 58)); renderer.setSeriesPaint(2, new Color(149, 201, 136)); renderer.setSeriesPaint(3, new Color(1, 62, 29)); renderer.setSeriesPaint(4, new Color(81, 176, 86)); renderer.setSeriesPaint(5, new Color(0, 55, 122)); renderer.setSeriesPaint(6, new Color(0, 92, 165)); } return chart; }
From source file:canreg.client.analysis.Tools.java
public static String getChartData(JFreeChart chart, String separatingCharacter, boolean quotesOn) { String endLine = "\n"; String quotes = ""; if (quotesOn) { quotes = "\""; }// www .j a v a2s . co m StringBuilder stringBuilder = new StringBuilder(); String plotType = chart.getPlot().getPlotType(); // System.out.println("Plot Type: " + plotType); if (plotType.equalsIgnoreCase("Pie Plot")) { PiePlot plot = (PiePlot) chart.getPlot(); PieDataset dataset = plot.getDataset(); Comparable key; for (int i = 0; i < dataset.getKeys().size(); i++) { key = dataset.getKey(i); stringBuilder.append(quotes).append(key).append(quotes).append(separatingCharacter).append(quotes) .append(dataset.getValue(key)).append(quotes).append(endLine); } } else if (plotType.equalsIgnoreCase("Category Plot")) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryDataset dataset = plot.getDataset(); Comparable rowkey; Comparable columnkey; for (int r = 0; r < dataset.getRowCount(); r++) { rowkey = dataset.getRowKey(r); columnkey = dataset.getColumnKey(r); // this is weird... but it works! stringBuilder.append(quotes).append(columnkey).append(quotes).append(separatingCharacter) .append(quotes).append(dataset.getValue(rowkey, columnkey)).append(quotes).append(endLine); } } return stringBuilder.toString(); }