List of usage examples for org.jfree.chart.title TextTitle TextTitle
public TextTitle(String text)
From source file:org.jfree.chart.demo.ImageMapDemo5.java
/** * Creates a chart.//from ww w .j a va 2 s . com * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setAnchor(StandardLegend.SOUTH); chart.setBackgroundPaint(Color.white); final TextTitle subtitle = new TextTitle("An area chart demonstration. We use this subtitle " + " as an example of what happens when you get a really long title or subtitle."); subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12)); subtitle.setPosition(RectangleEdge.TOP); // subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05)); subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM); chart.addSubtitle(subtitle); final CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java
private void buildMainChart(String title, String subTitle, String xAxisLabel, String yAxisLabel, String fileName) {//from w w w. j a v a2 s .c om final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createMatrixDataSet()); final JFreeChart chart = ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.addSubtitle(new TextTitle(subTitle)); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE)); chart.removeLegend(); // Perform customizations starts here ... final XYPlot plot1 = chart.getXYPlot(); plot1.setDomainGridlinesVisible(false); plot1.setRangeGridlinesVisible(false); plot1.setForegroundAlpha(0.5f); plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel())); plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel())); // Custumize the domain axis ( y ) final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setRange(-1, this.array.length); // Custumize the range axis ( y ) final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setRange(-1, this.array.length); // Create custom renderer StandardXYItemRenderer ren = new CustomRenderer(false); ren.setSeriesItemLabelPaint(0, Color.BLACK); plot1.setRenderer(ren); this.mainChart = chart; }
From source file:mt.LengthDistribution.java
public static void GetLengthDistributionArray(ArrayList<File> AllMovies, double[] calibration) { ArrayList<Double> maxlist = new ArrayList<Double>(); for (int i = 0; i < AllMovies.size(); ++i) { double maxlength = LengthDistribution.Lengthdistro(AllMovies.get(i)); if (maxlength != Double.NaN && maxlength > 0) maxlist.add(maxlength);/*w w w . ja v a2s .c o m*/ } Collections.sort(maxlist); int min = 0; int max = (int) Math.round(maxlist.get(maxlist.size() - 1)) + 1; XYSeries counterseries = new XYSeries("MT length distribution"); XYSeries Logcounterseries = new XYSeries("MT Log length distribution"); final ArrayList<Point> points = new ArrayList<Point>(); for (int length = 0; length < max; ++length) { HashMap<Integer, Integer> frameseed = new HashMap<Integer, Integer>(); int count = 0; for (int i = 0; i < AllMovies.size(); ++i) { File file = AllMovies.get(i); double currentlength = LengthDistribution.Lengthdistro(file); ArrayList<FLSobject> currentobject = Tracking.loadMTStat(file); if (currentlength > length) { for (int index = 0; index < currentobject.size(); ++index) { ArrayList<Integer> seedlist = new ArrayList<Integer>(); if (currentobject.get(index).length >= length) { seedlist.add(currentobject.get(index).seedID); if (frameseed.get(currentobject.get(index).Framenumber) != null && frameseed.get(currentobject.get(index).Framenumber) != Double.NaN) { int currentcount = frameseed.get(currentobject.get(index).Framenumber); frameseed.put(currentobject.get(index).Framenumber, seedlist.size() + currentcount); } else if (currentobject.get(index) != null) frameseed.put(currentobject.get(index).Framenumber, seedlist.size()); } } } } // Get maxima length, count int maxvalue = Integer.MIN_VALUE; for (int key : frameseed.keySet()) { int Count = frameseed.get(key); if (Count >= maxvalue) maxvalue = Count; } if (maxvalue != Integer.MIN_VALUE) { counterseries.add(length, maxvalue); if (maxvalue > 0) { Logcounterseries.add((length), Math.log(maxvalue)); points.add(new Point(new double[] { length, Math.log(maxvalue) })); } } } final XYSeriesCollection dataset = new XYSeriesCollection(); final XYSeriesCollection nofitdataset = new XYSeriesCollection(); dataset.addSeries(counterseries); nofitdataset.addSeries(counterseries); final XYSeriesCollection Logdataset = new XYSeriesCollection(); Logdataset.addSeries(Logcounterseries); final JFreeChart chart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", dataset); final JFreeChart nofitchart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", nofitdataset); // Fitting line to log of the length distribution interpolation.Polynomial poly = new interpolation.Polynomial(1); try { poly.fitFunction(points); } catch (NotEnoughDataPointsException e) { // TODO Auto-generated catch block e.printStackTrace(); } DisplayPoints.display(nofitchart, new Dimension(800, 500)); dataset.addSeries(Tracking.drawexpFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Exponential fit")); NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setMaximumFractionDigits(3); TextTitle legendText = new TextTitle("Mean Length" + " : " + nf.format(-1.0 / poly.getCoefficients(1)) + " " + "Standard Deviation" + " : " + nf.format(poly.SSE)); legendText.setPosition(RectangleEdge.RIGHT); DisplayPoints.display(chart, new Dimension(800, 500)); chart.addSubtitle(legendText); final JFreeChart logchart = ChartFactory.createScatterPlot("MT Log length distribution", "Number of MT", "Length (micrometer)", Logdataset); // DisplayPoints.display(logchart, new Dimension(800, 500)); for (int i = 1; i >= 0; --i) System.out.println(poly.getCoefficients(i) + " " + "x" + " X to the power of " + i); // Logdataset.addSeries(Tracking.drawFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Straight line fit")); WriteLengthdistroFile(AllMovies, counterseries, 0); }
From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java
private JFreeChart getMemoryChart(int intervalSize, List<MemoryData> memory) { if (null == memory || memory.isEmpty()) { return null; }//from w ww . ja va 2 s . c om JFreeChart chart; TimeSeries freeSeries = new TimeSeries("Free"); TimeSeries maxSeries = new TimeSeries("Max"); TimeSeries totalSeries = new TimeSeries("Total"); memory.remove(memory.size() - 1); for (MemoryData memoryEntry : memory) { freeSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getFreeMemory()); maxSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getMaxMemory()); totalSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getTotalMemory()); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(freeSeries); dataset.addSeries(maxSeries); dataset.addSeries(totalSeries); chart = ChartFactory.createTimeSeriesChart("eID Trust Service Memory Usage History", "Time (interval size " + intervalSize + " msec)", "Memory", dataset, true, false, false); chart.addSubtitle(new TextTitle( memory.get(0).getDate().toString() + " - " + memory.get(memory.size() - 1).getDate().toString())); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); ValueAxis valueAxis = plot.getRangeAxis(); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); plot.setRenderer(renderer); return chart; }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.HierarchicalBarChart.java
private void buildFinalChart(String title, String subTitle, String xAxisLabel, String yAxisLabel, int height, int width, String filename, Chart.Scale scaleMode, Chart.LegendFormat legendFormatMode, int alpha) { @SuppressWarnings("unchecked") Vector<Counter>[] vec = new Vector[this.timers.length]; boolean exist; // create the dataset... for (int i = 0; i < this.timers.length; i++) { vec[i] = new Vector<Counter>(); @SuppressWarnings("unchecked") Iterator<Element> it = this.timers[i].getDescendants(); while (it.hasNext()) { try { Element elt = (Element) it.next(); String name = elt.getAttributeValue("name"); double value = Double.valueOf(elt.getAttributeValue("avg")); exist = false;/* w w w.ja v a2 s . c om*/ for (int j = 0; j < vec[i].size(); j++) { if (((Counter) vec[i].get(j)).getName().equals(name)) { ((Counter) vec[i].get(j)).addValue(value); exist = true; break; } } if (!exist) { vec[i].add(new Counter(name, value)); } } catch (ClassCastException e) { continue; } } } CategoryDataset dataset = null; try { dataset = DatasetUtilities.createCategoryDataset(toSeries(vec[0]), this.categories, toDataset(vec)); } catch (IllegalArgumentException e) { e.printStackTrace(); throw new IllegalArgumentException( "Benchmark names must have different names. Be sure that your filter contains correct timers names"); } // create the chart... final CategoryAxis categoryAxis = new CategoryAxis(xAxisLabel); final ValueAxis valueAxis = new NumberAxis(yAxisLabel); final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, new HierarchicalBarRenderer()); plot.setOrientation(PlotOrientation.VERTICAL); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.addSubtitle(new TextTitle(subTitle)); // set the background color for the chart... chart.setBackgroundPaint(Color.white); final HierarchicalBarRenderer renderer = (HierarchicalBarRenderer) plot.getRenderer(); renderer.setItemMargin(0.01); renderer.setDatasetTree(this.timers); renderer.setSeries(toSeries(vec[0])); renderer.setAlpha(alpha); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryMargin(HierarchicalBarChart.CATEGORY_MARGIN); domainAxis.setUpperMargin(0.05); domainAxis.setLowerMargin(0.05); try { if ((filename == null) || "".equals(filename)) { throw new RuntimeException( "The output filename for the HierarchicalBarChart cannot be null or empty !"); } ChartUtilities.saveChartAsPNG(XMLHelper.createFileWithDirs(filename + ".png"), chart, width, height); Utilities.saveChartAsSVG(chart, new Rectangle(width, height), XMLHelper.createFileWithDirs(filename + ".svg")); } catch (java.io.IOException e) { System.err.println("Error writing chart image to file"); e.printStackTrace(); } }
From source file:edu.ucla.stat.SOCR.chart.demo.AreaChartDemo1.java
/** * Creates a Area chart./* ww w.j av a 2s. c om*/ * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createAreaChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); if (isDemo) { TextTitle subtitle = new TextTitle("An area chart demonstration. We use this subtitle as an " + "example of what happens when you get a really long title or " + "subtitle."); subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12)); subtitle.setPosition(RectangleEdge.TOP); subtitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05, 0.05, 0.05, 0.05)); subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM); chart.addSubtitle(subtitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); AreaRenderer renderer = (AreaRenderer) plot.getRenderer(); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); if (isDemo) { domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); } NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); return chart; }
From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java
/** * Create JFreeChart graph using the supplied parameters. * * @param chartType One of the many chart types. * @param conf Chart configuration//www . ja va 2s .c o m * @param is Inputstream containing chart data * @return Initialized chart or NULL in case of issues. * @throws IOException Thrown when a problem is reported while parsing XML data. */ public static JFreeChart createJFreeChart(String chartType, Configuration conf, InputStream is) throws XPathException { logger.debug("Generating " + chartType); // Currently two dataset types supported CategoryDataset categoryDataset = null; PieDataset pieDataset = null; try { if ("PieChart".equals(chartType) || "PieChart3D".equals(chartType) || "RingChart".equals(chartType)) { logger.debug("Reading XML PieDataset"); pieDataset = DatasetReader.readPieDatasetFromXML(is); } else { logger.debug("Reading XML CategoryDataset"); categoryDataset = DatasetReader.readCategoryDatasetFromXML(is); } } catch (IOException ex) { throw new XPathException(ex.getMessage()); } finally { try { is.close(); } catch (IOException ex) { // } } // Return chart JFreeChart chart = null; // Big chart type switch if ("AreaChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("BarChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createBarChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("BarChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("LineChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createLineChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("LineChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createLineChart3D(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("MultiplePieChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createMultiplePieChart(conf.getTitle(), categoryDataset, conf.getOrder(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("MultiplePieChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createMultiplePieChart3D(conf.getTitle(), categoryDataset, conf.getOrder(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("PieChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createPieChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("PieChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createPieChart3D(conf.getTitle(), pieDataset, conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("RingChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createRingChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setPieChartParameters(chart, conf); } else if ("SpiderWebChart".equalsIgnoreCase(chartType)) { SpiderWebPlot plot = new SpiderWebPlot(categoryDataset); if (conf.isGenerateTooltips()) { plot.setToolTipGenerator(new StandardCategoryToolTipGenerator()); } chart = new JFreeChart(conf.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false); if (conf.isGenerateLegend()) { LegendTitle legend = new LegendTitle(plot); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); } else { TextTitle subTitle = new TextTitle(" "); subTitle.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(subTitle); } setCategoryChartParameters(chart, conf); } else if ("StackedAreaChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createStackedAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("StackedBarChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createStackedBarChart(conf.getTitle(), conf.getDomainAxisLabel(), conf.getRangeAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("StackedBarChart3D".equalsIgnoreCase(chartType)) { chart = ChartFactory.createStackedBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else if ("WaterfallChart".equalsIgnoreCase(chartType)) { chart = ChartFactory.createWaterfallChart(conf.getTitle(), conf.getCategoryAxisLabel(), conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls()); setCategoryChartParameters(chart, conf); } else { logger.error("Illegal chartype. Choose one of " + "AreaChart BarChart BarChart3D LineChart LineChart3D " + "MultiplePieChart MultiplePieChart3D PieChart PieChart3D " + "RingChart SpiderWebChart StackedAreaChart StackedBarChart " + "StackedBarChart3D WaterfallChart"); } setCommonParameters(chart, conf); return chart; }
From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java
public void setLineChart(String title, String subtitle, String xlabel, String ylabel) { XYSeriesCollection dataset = new XYSeriesCollection(); chart = ChartFactory.createXYLineChart(title, // chart title xlabel, // x axis label ylabel, // y axis label dataset, // data chartOrientation, showLegend, // include legend true, // tooltips false // urls );// ww w . j a v a2s . c o m if (showLegend) { LegendTitle chartTitle = chart.getLegend(); chartTitle.setPosition(legendPosition); } if (subtitle != null && !"".equals(subtitle)) { TextTitle subtitle1 = new TextTitle(subtitle); chart.addSubtitle(subtitle1); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); //can use this code to modify charts for book. DO NOT USE FOR NORMAL FUNCTIONING // NumberAxis yaxis = (NumberAxis)plot.getRangeAxis(); // yaxis.setTickUnit(new NumberTickUnit(.1)); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); // this.addEPSMenuItem(this, panel.getPopupMenu());//remove this line for public release versions panel.setPreferredSize(new Dimension(width, height)); chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); }
From source file:org.gridchem.client.gui.charts.UsageChart.java
private void init() { removeAll();/* w w w. j a va2s . com*/ String title = ""; if (CURRENT_CHARTTYPE.equals(ChartType.JOB)) { // dataset = createJobDataset(projectTable); dataset = new DefaultPieDataset(); } else if (CURRENT_CHARTTYPE.equals(ChartType.PROJECT)) { dataset = createProjectDataset(projectCollabTable); title = "CCG Utilization by Project"; } else if (CURRENT_CHARTTYPE.equals(ChartType.RESOURCE)) { dataset = createResourceDataset(projectCollabTable); title = "CCG Utilization by Resource"; } else if (CURRENT_CHARTTYPE.equals(ChartType.USER)) { dataset = createUserDataset(projectCollabTable); title = "CCG Utilization by User"; } chart = ChartFactory.createPieChart(title, // chart title dataset, // data false, // include legend true, // tooltips? false // URLs? ); if (projectCollabTable.size() == 1) { ProjectBean project = projectCollabTable.keySet().iterator().next(); chart.addSubtitle( new TextTitle("Project " + project.getName() + " expires on " + project.getEndDate())); } ((PiePlot) chart.getPlot()).setCircular(true); // ((PiePlot)chart.getPlot()).setExplodePercent(new Integer(defaultProjectIndex), 25); if (CURRENT_CHARTTYPE.equals(ChartType.JOB)) { chart.getPlot().setNoDataMessage("Comprehensive job information is not currently available."); } chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(size); setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; c.weighty = 1.0; c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.BOTH; add(chartPanel, c); GridBagConstraints c1 = new GridBagConstraints(); c1.weightx = 0; c1.weighty = 0; c1.gridx = 0; c1.gridy = 1; c1.fill = GridBagConstraints.BOTH; add(navPanel, c1); revalidate(); // setPreferredSize(size); }
From source file:com.polivoto.vistas.acciones.Datos.java
private JFreeChart createChartBar(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart("Votacion", "Opciones", "Total de votos", dataset, PlotOrientation.VERTICAL, true, true, true); try {//from ww w . j a v a2 s . c o m chart.addSubtitle(new TextTitle(ac.getPreguntas().getJSONObject(pox).getString("pregunta"))); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white)); CategoryPlot plot = chart.getCategoryPlot(); org.jfree.chart.axis.CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D)); // final CategoryItemRenderer itemRenderer = new CustomRenderer( // new Paint[] {Color.green, Color.red, Color.blue, Color.yellow, Color.magenta, Color.cyan, Color.pink, Color.lightGray} // ); //// itemRenderer.setBaseItemLabelsVisible(true); //// BarRenderer barRenderer = (BarRenderer)itemRenderer; //// barRenderer.setItemMargin(0.2D); //// plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, new java.awt.Color(147, 60, 45))); //// // StandardCategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("{0}: {2} %", new DecimalFormat("0")); // // // plot.setNoDataMessage("SIN DATOS!"); // // //// renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); // itemRenderer.setItemLabelsVisible(true); // final ItemLabelPosition p = new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0 // ); // itemRenderer.setPositiveItemLabelPosition(p); // plot.setRenderer(itemRenderer); // change the margin at the top of the range axis... final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); } catch (JSONException ex) { Logger.getLogger(Datos.class.getName()).log(Level.SEVERE, null, ex); } return chart; }