List of usage examples for org.jfree.chart.plot PiePlot setLegendLabelToolTipGenerator
public void setLegendLabelToolTipGenerator(PieSectionLabelGenerator generator)
From source file:org.jfree.expdemo.SelectionDemo6Pie.java
private static JFreeChart createChart(final PieDataset dataset, DatasetSelectionExtension ext) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", // chart title dataset, // dataset true, // include legend true, false);// w w w . ja v a 2 s . com final PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("One", new Color(160, 160, 255)); plot.setSectionPaint("Two", new Color(128, 128, 255 - 32)); plot.setSectionPaint("Three", new Color(96, 96, 255 - 64)); plot.setSectionPaint("Four", new Color(64, 64, 255 - 96)); plot.setSectionPaint("Five", new Color(32, 32, 255 - 128)); plot.setSectionPaint("Six", new Color(0, 0, 255 - 144)); plot.setNoDataMessage("No data available"); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)")); plot.setLabelBackgroundPaint(new Color(220, 220, 220)); plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); plot.setSimpleLabels(true); plot.setInteriorGap(0.1); //pie plots done use abstract renderers need to react to selection on our own final PieCursor cursor = new PieCursor(); ext.addSelectionChangeListener(new SelectionChangeListener() { public void selectionChanged(SelectionChangeEvent event) { for (int i = 0; i < dataset.getItemCount(); i++) { cursor.setPosition(dataset.getKey(i)); if (event.getSelectionExtension().isSelected(cursor)) { plot.setExplodePercent(cursor.key, 0.15); } else { plot.setExplodePercent(cursor.key, 0.0); } } } }); return chart; }
From source file:org.jfree.chart.demo.selection.SelectionDemo6Pie.java
private static JFreeChart createChart(final PieDataset dataset, DatasetSelectionExtension<PieCursor<String>> ext) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", dataset); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("One", new Color(160, 160, 255)); plot.setSectionPaint("Two", new Color(128, 128, 255 - 32)); plot.setSectionPaint("Three", new Color(96, 96, 255 - 64)); plot.setSectionPaint("Four", new Color(64, 64, 255 - 96)); plot.setSectionPaint("Five", new Color(32, 32, 255 - 128)); plot.setSectionPaint("Six", new Color(0, 0, 255 - 144)); plot.setNoDataMessage("No data available"); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)")); plot.setLabelBackgroundPaint(new Color(220, 220, 220)); plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); plot.setSimpleLabels(true);//from w w w . j a v a 2s .c o m plot.setInteriorGap(0.1); //pie plots done use abstract renderers need to react to selection on our own final PieCursor<String> cursor = new PieCursor<String>(); ext.addChangeListener(new SelectionChangeListener<PieCursor<String>>() { public void selectionChanged(SelectionChangeEvent<PieCursor<String>> event) { for (int i = 0; i < dataset.getItemCount(); i++) { cursor.setPosition((String) dataset.getKey(i)); if (event.getSelectionExtension().isSelected(cursor)) { plot.setExplodePercent(cursor.key, 0.15); } else { plot.setExplodePercent(cursor.key, 0.0); } } } }); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.PieChartDemo2.java
/** * Creates a sample chart.//ww w .jav a2 s .c om * * @param dataset the dataset. * * @return A chart. */ protected JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title dataset, // dataset !legendPanelOn, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setNoDataMessage("No data available"); for (int i = 0; i < pulloutFlag.length; i++) { //System.out.println("\""+pulloutFlag[i]+"\""); if (isPullout(i)) { Comparable key = dataset.getKey(i); plot.setExplodePercent(key, 0.30); } } plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); if (rotateOn) { Rotator rotator = new Rotator(plot); rotator.start(); } setCategorySummary(dataset); return chart; }
From source file:edu.jhuapl.graphs.controller.GraphController.java
public GraphObject createPieGraph(GraphDataInterface graphData, Encoding encoding) { GraphObject graph = null;// w ww . j a v a 2 s . co m Map<String, Object> graphMetaData = new HashMap<String, Object>(); List<PointInterface> points = new ArrayList<PointInterface>(); setPieGraphMetaData(graphData, graphMetaData, points); // I'm ashamed of this code in so many ways String graphTitle = (String) graphMetaData.get(GraphSource.GRAPH_TITLE); try { // add the created chart properties JFreeChartGraphSource graphSource = new JFreeChartGraphSource(); graphSource.setData(Arrays.asList(new DataSeries(points, new HashMap<String, Object>()))); graphSource.setParams(graphMetaData); graphSource.initialize(); if (graphData.showLegend()) { PiePlot plot = (PiePlot) graphSource.getChart().getPlot(); // use rectangles as the legend shapes plot.setLegendItemShape(new Rectangle(7, 8)); // generate tooltip for the legend items in the following format: "lineSetLabels - count" if (graphData.percentBased()) { plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0} - {1} ({2})", new DecimalFormat("#.##"), new DecimalFormat("#.##%"))); } else { plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0} - {1} ({2})", new DecimalFormat("#"), new DecimalFormat("#.##%"))); } } // render the graph to get the image map RenderedGraph renderedGraph = graphSource.renderGraph(graphData.getGraphWidth(), graphData.getGraphHeight(), encoding); String extension = ".dat"; switch (encoding) { case JPEG: extension = ".jpg"; break; case PNG: case PNG_WITH_TRANSPARENCY: extension = ".png"; break; } String imageFileName = getCleanValue(graphTitle) + "_piegraph" + extension; // get the image map String imageMapName = "imageMap" + graphDataId; String imageMap = appendImageMapTarget(renderedGraph.getImageMap(imageMapName), graphData.getLineSetURLTarget()); try { // store away the graph data file graphDataHandler.putGraphData(graphData, graphDataId); graph = new GraphObject(graphSource, renderedGraph, imageFileName, imageMapName, imageMap, graphDataId); } catch (GraphException e) { System.out.println(e.getMessage()); e.printStackTrace(); } } catch (GraphException e) { System.out.println("Could not create pie graph " + graphTitle); e.printStackTrace(); } return graph; }
From source file:cnu.eslab.fileTest.NewJFrame.java
public void PieGraphGenerate(String[] arGrop, double[] arValue, String arTitle, String arSubTitle) { // ?? ?.// w w w . j a va 2s . 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); }