List of usage examples for org.jfree.chart.plot PiePlot setLabelLinkStroke
public void setLabelLinkStroke(Stroke stroke)
From source file:uom.research.thalassemia.util.PieChartCreator.java
/** * Creates a chart.//from w w w . j a v a 2s .co m * * @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:semaforo.Semaforo.java
public static void SemaforoGrafico(JFreeChart chart) { // set a custom background for the chart chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK)); // customise the title position and font TextTitle t = chart.getTitle();//from w ww.ja v a 2 s . co m t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 0)); PiePlot plot = null; plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.00); plot.setOutlineVisible(true); // use gradients and white borders for the section colours plot.setBaseSectionOutlinePaint(Color.BLACK); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 0)); plot.setLabelLinkPaint(Color.BLACK); plot.setLabelLinkStroke(new BasicStroke(0.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(null); plot.setLabelBackgroundPaint(Color.BLACK); plot.setLabelShadowPaint(Color.BLACK); // add a subtitle giving the data source // Mostramos la grafica dentro del jPanel1 panel = new ChartPanel(chart); panel.setBackground(Color.BLACK); panel.repaint(); jPanel3.setLayout(null); jPanel3.setLayout(new java.awt.BorderLayout()); jPanel3.remove(panel); jPanel3.add(panel); jPanel3.repaint(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); jTabbedPane1.setPreferredSize(new Dimension(screenSize.width, screenSize.height)); }
From source file:semaforo.Semaforo.java
public static void editGrafico() { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2);//from ww w . j av a2s .c o m double cfd = 0.0; double bull = 0.0; double bear = 0.0; if (countCfd != 0) cfd = (countCfd * 100) / (countBear + countBull + countCfd); if (countBull != 0) bull = ((countBull * 100) / (countBear + countBull + countCfd)); if (countBear != 0) bear = ((countBear * 100) / (countBear + countBull + countCfd)); Semaforo.l1.setText("CFD (" + String.format("%.2f", cfd) + "%)"); Semaforo.l2.setText("BULL (" + String.format("%.2f", bull) + "%)"); Semaforo.l3.setText("BEAR (" + String.format("%.2f", bear) + "%)"); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("CFD (" + cfd + "%)", new Integer((int) countCfd)); pieDataset.setValue("BULL (" + bull + "%)", new Integer((int) countBull)); pieDataset.setValue("BEAR (" + bear + "%)", new Integer((int) countBear)); JFreeChart chart = null; chart = ChartFactory.createPieChart("", // chart title pieDataset, // data false, // no legend false, // tooltips false // no URL generation ); // set a custom background for the chart chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK)); // 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, 0)); PiePlot plot = null; plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.00); plot.setOutlineVisible(true); // use gradients and white borders for the section colours plot.setBaseSectionOutlinePaint(Color.BLACK); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 0)); plot.setLabelLinkPaint(Color.BLACK); plot.setLabelLinkStroke(new BasicStroke(0.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(null); plot.setLabelBackgroundPaint(Color.BLACK); plot.setLabelShadowPaint(Color.BLACK); // add a subtitle giving the data source // Mostramos la grafica dentro del jPanel1 Semaforo.panel.setChart(chart); }