You are on page 1of 30

import java.awt.

RenderingHints;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.FastScatterPlot;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
* A demo of the fast scatter plot.
*
*/
public class FastScatterPlotDemo extends ApplicationFrame {

/** A constant for the number of items in the sample dataset. */


private static final int COUNT = 500000;

/** The data. */


private float[][] data = new float[2][COUNT];

/**
* Creates a new fast scatter plot demo.
*
* @param title the frame title.
*/
public FastScatterPlotDemo(final String title) {

super(title);
populateData();
final NumberAxis domainAxis = new NumberAxis("X");
domainAxis.setAutoRangeIncludesZero(false);
final NumberAxis rangeAxis = new NumberAxis("Y");
rangeAxis.setAutoRangeIncludesZero(false);
final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis,
rangeAxis);
final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
// chart.setLegend(null);

// force aliasing of the rendered content..


chart.getRenderingHints().put
(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

final ChartPanel panel = new ChartPanel(chart, true);


panel.setPreferredSize(new java.awt.Dimension(500, 270));
// panel.setHorizontalZoom(true);
// panel.setVerticalZoom(true);
panel.setMinimumDrawHeight(10);
panel.setMaximumDrawHeight(2000);
panel.setMinimumDrawWidth(20);
panel.setMaximumDrawWidth(2000);

setContentPane(panel);

//
****************************************************************************
// * JFREECHART DEVELOPER GUIDE
*
// * The JFreeChart Developer Guide, written by David Gilbert, is available
*
// * to purchase from Object Refinery Limited:
*
// *
*
// * http://www.object-refinery.com/jfreechart/guide.html
*
// *
*
// * Sales are used to provide funding for the JFreeChart project - please
*
// * support us so that we can continue developing free software.
*
//
****************************************************************************

/**
* Populates the data array with random values.
*/
private void populateData() {

for (int i = 0; i < this.data[0].length; i++) {


final float x = (float) i + 100000;
this.data[0][i] = x;
this.data[1][i] = 100000 + (float) Math.random() * COUNT;
}

/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(final String[] args) {

final FastScatterPlotDemo demo = new FastScatterPlotDemo("Fast Scatter


Plot Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}
import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYDotRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

// Referenced classes of package demo:


// SampleXYDataset2

public class ScatterPlotDemo2 extends ApplicationFrame


{

public ScatterPlotDemo2(String s)
{
super(s);
JPanel jpanel = createDemoPanel();
jpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(jpanel);
}

private static JFreeChart createChart(XYDataset xydataset)


{
JFreeChart jfreechart = ChartFactory.createScatterPlot("Scatter Plot Demo
2", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false);
XYPlot xyplot = (XYPlot)jfreechart.getPlot();
XYDotRenderer xydotrenderer = new XYDotRenderer();
xydotrenderer.setDotWidth(2);
xydotrenderer.setDotHeight(2);
xyplot.setRenderer(xydotrenderer);
NumberAxis numberaxis = (NumberAxis)xyplot.getDomainAxis();
numberaxis.setAutoRangeIncludesZero(false);
return jfreechart;
}

public static JPanel createDemoPanel()


{
JFreeChart jfreechart = createChart(new SampleXYDataset2());
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setVerticalAxisTrace(true);
chartpanel.setHorizontalAxisTrace(true);
chartpanel.setPopupMenu(null);
chartpanel.setDomainZoomable(true);
chartpanel.setRangeZoomable(true);
return chartpanel;
}

public static void main(String args[])


{
ScatterPlotDemo2 scatterplotdemo2 = new ScatterPlotDemo2("Scatter Plot
Demo 2");
scatterplotdemo2.pack();
RefineryUtilities.centerFrameOnScreen(scatterplotdemo2);
scatterplotdemo2.setVisible(true);
}
}

public ScatterPlotDemo(String title) {

super(title);

XYSeriesCollection dataset = new XYSeriesCollection();

XYSeries series1 = new XYSeries("Series 1");


series1.add(1.0, 4.5);
series1.add(4.4, 3.2);
dataset.addSeries(series1);

XYSeries series2 = new XYSeries("Series 2");


series2.add(3.2, 8.5);
series2.add(4.9, 3.7);
dataset.addSeries(series2);

XYLineAndShapeRenderer xylineandshaperenderer =
(XYLineAndShapeRenderer)plot.getRenderer();

XYItemRenderer xyitem = plot.getRenderer();


xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new
ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);

<%@ page contentType="text/html;charset=GBK"%>


<%@ page import = "org.jfree.chart.ChartFactory,
org.jfree.chart.JFreeChart,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.chart.title.TextTitle,
org.jfree.data.time.TimeSeries,
org.jfree.data.time.Month,
org.jfree.data.time.TimeSeriesCollection,
java.awt.Font"%>
<%
//����ͳ��ʱ����
TimeSeries timeSeries = new TimeSeries("���۹�blog����ͳ��", Month.class);

//ʱ�������� ���
TimeSeriesCollection lineDataset = new TimeSeriesCollection();

//������ ���
timeSeries.add(new Month(1, 2007), 11200);
timeSeries.add(new Month(2, 2007), 9000);
timeSeries.add(new Month(3, 2007), 6200);
timeSeries.add(new Month(4, 2007), 8200);
timeSeries.add(new Month(5, 2007), 8200);
timeSeries.add(new Month(6, 2007), 12200);
timeSeries.add(new Month(7, 2007), 13200);
timeSeries.add(new Month(8, 2007), 8300);
timeSeries.add(new Month(9, 2007), 12400);
timeSeries.add(new Month(10, 2007), 12500);
timeSeries.add(new Month(11, 2007), 13600);
timeSeries.add(new Month(12, 2007), 12500);

lineDataset.addSeries(timeSeries);
JFreeChart chart = ChartFactory.createTimeSeriesChart("����ͳ��ʱ����", "�·�",
"����", lineDataset, true, true, true);

//�����ӱ���
TextTitle subtitle = new TextTitle("2007���", new Font("����", Font.BOLD, 12));
chart.addSubtitle(subtitle);
//���������
chart.setTitle(new TextTitle("���۹�blog����ͳ��", new Font("e��", Font.ITALIC,
15)));
chart.setAntiAlias(true);

String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);

String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;

%>
<img src="<%= graphURL %>"width=500 height=300 border=0 usemap="#<%= filename %>">

��ʱ������Ҫ��ʾ���� ����ֵ������������Ҫ���������һ��Ķ�����JFreeChart chart =


ChartFactory.createTimeSeriesChart������TextTitle subtitle = new
TextTitle����ǰ�������µĴ��룺
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer xylineandshaperenderer =
(XYLineAndShapeRenderer)plot.getRenderer();
//������ ���ɫ
plot.setBackgroundPaint(Color.white);
//�������������ɫ
plot.setDomainGridlinePaint(Color.pink);
//������������ɫ
plot.setRangeGridlinePaint(Color.pink);
//�������� ��xy��ľ���
plot.setAxisOffset(new RectangleInsets(0D, 0D, 0D, 10D));
//��������� ���ʾ�� �
xylineandshaperenderer.setBaseShapesVisible(true);
//����������ʾ���� ��ֵ
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new
ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class LineChartDemo1 extends ApplicationFrame


{
public LineChartDemo1(final String title)
{
super(title);
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}
public static CategoryDataset createDataset()
{
final String series1 = "First";
final String series2 = "Second";
final String series3 = "Third";
final String type1 = "Type 1";
final String type2 = "Type 2";
final String type3 = "Type 3";
final String type4 = "Type 4";
final String type5 = "Type 5";
final String type6 = "Type 6";
final String type7 = "Type 7";
final String type8 = "Type 8";
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

dataset.addValue(1.0, series1, type1);


dataset.addValue(4.0, series1, type2);
dataset.addValue(3.0, series1, type3);
dataset.addValue(5.0, series1, type4);
dataset.addValue(5.0, series1, type5);
dataset.addValue(7.0, series1, type6);
dataset.addValue(7.0, series1, type7);
dataset.addValue(8.0, series1, type8);
dataset.addValue(5.0, series2, type1);
dataset.addValue(7.0, series2, type2);
dataset.addValue(6.0, series2, type3);
dataset.addValue(8.0, series2, type4);
dataset.addValue(4.0, series2, type5);
dataset.addValue(4.0, series2, type6);
dataset.addValue(2.0, series2, type7);
dataset.addValue(1.0, series2, type8);
dataset.addValue(4.0, series3, type1);
dataset.addValue(3.0, series3, type2);
dataset.addValue(2.0, series3, type3);
dataset.addValue(3.0, series3, type4);
dataset.addValue(6.0, series3, type5);
dataset.addValue(3.0, series3, type6);
dataset.addValue(4.0, series3, type7);
dataset.addValue(3.0, series3, type8);
return dataset;
}
private JFreeChart createChart(final CategoryDataset dataset)
{
final JFreeChart chart = ChartFactory.createLineChart(
"Line Chart Demo 1", // chart title
"Type", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot
.getRenderer();
renderer.setShapesFilled(false);
renderer.setUseFillPaint(false);
renderer.setSeriesStroke(0, new BasicStroke(2.0f,
BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
new float[] { 10.0f, 6.0f }, 0.0f));
renderer.setSeriesStroke(1, new BasicStroke(2.0f,
BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
new float[] { 6.0f, 6.0f }, 0.0f));
renderer.setSeriesStroke(2, new BasicStroke(2.0f,
BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
new float[] { 2.0f, 6.0f }, 0.0f));
return chart;
}
public static void main(final String[] args)
{
final LineChartDemo1 demo = new LineChartDemo1("Line Chart Demo");

demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}

plot.getDomainAxis().setVisible(true);
plot.getDomainAxis().setLabelFont(new Font("����", Font.PLAIN, 12));
plot.getDomainAxis().setLabelPaint(Color.BLACK);
plot.getDomainAxis().setTickLabelFont(new Font("����", Font.PLAIN, 12));
plot.getDomainAxis().setTickLabelPaint(Color.BLACK);
plot.getDomainAxis().setTickLabelsVisible(true);

plot.getRangeAxis().setVisible(true);
plot.getRangeAxis().setLabelFont(new Font("����", Font.PLAIN, 12));
plot.getRangeAxis().setLabelPaint(Color.BLACK);
plot.getRangeAxis().setTickLabelFont(new Font("����", Font.PLAIN, 12));
plot.getRangeAxis().setTickLabelPaint(Color.BLACK);
plot.getRangeAxis().setVerticalTickLabels(false);
plot.getRangeAxis().setLabelAngle(0.0D);

plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinesVisible(true);

���³��http://www.diybl.com/course/3_program/java/javashl/20071126/87642.html
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class ScatterPlotDemo extends ApplicationFrame {

public ScatterPlotDemo(String title) {

super(title);

XYSeriesCollection dataset = new XYSeriesCollection();

XYSeries series1 = new XYSeries("Series 1");


series1.add(1.0, 4.5);
series1.add(4.4, 3.2);
dataset.addSeries(series1);

XYSeries series2 = new XYSeries("Series 2");


series2.add(3.2, 8.5);
series2.add(4.9, 3.7);
dataset.addSeries(series2);
JFreeChart chart = ChartFactory.createScatterPlot(
"Scatter Plot Demo", // title
"X", "Y", // axis labels
dataset, // dataset
PlotOrientation.VERTICAL,
true, // legend? yes
true, // tooltips? yes
false // URLs? no
);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);

public static void main(String[] args) {


ScatterPlotDemo demo = new ScatterPlotDemo("Scatter Plot Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}

NumberAxis numAxis = (NumberAxis)xyplot.getRangeAxis();


DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
//����y��ʾ��ʽ
numAxis.setAutoTickUnitSelection(false);//�������� �ǩ�Ƿ��Զ�ȷ��
double rangetick = 0.1D;
numAxis.setTickUnit(new NumberTickUnit(rangetick)); //y� λ���Ϊ0.1

DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();


dateaxis.setTickUnit(new DateTickUnit(1, 1, new SimpleDateFormat("MMM-
yyyy")));
dateaxis.setVerticalTickLabels(true);

XYSeries xyseries = new XYSeries("allyes"); //�Ȳ���XYSeries ����


xyseries.add(20070801, 220000);
xyseries.add(20070802, 210000);
xyseries.add(20070803, 250000D);
xyseries.add(20070804, 450000D);
xyseries.add(20070805, 270000D);
xyseries.add(20070806, 280000D);
xyseries.add(20070807, 290000D);
xyseries.add(20070808, 500000D);

XYSeries xyseries1 = new XYSeries("direct");


xyseries1.add(20070801, 230000D);
xyseries1.add(20070802, 240000D);
xyseries1.add(20070803, 250000D);
xyseries1.add(20070804, 260000D);
xyseries1.add(20070805, 270000D);
xyseries1.add(20070806, 480000D);
xyseries1.add(20070807, 290000D);
xyseries1.add(20070808, 250000D);

XYSeries xyseries2 = new XYSeries("iplus");


xyseries2.add(20070801, 240000D);
xyseries2.add(20070802, 280000D);
xyseries2.add(20070803, 270000D);
xyseries2.add(20070804, 290000D);
xyseries2.add(20070805, 230000D);
xyseries2.add(20070806, 310000D);
xyseries2.add(20070807, 400000D);
xyseries2.add(20070808, 220000D);

XYSeriesCollection xyseriescollection = new XYSeriesCollection();


//����XYSeriesCollection�����XYSeries ����
xyseriescollection.addSeries(xyseries);
xyseriescollection.addSeries(xyseries1);
xyseriescollection.addSeries(xyseries2);

import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.DefaultCategoryDataset;

public class TestLineChart {

public static void createLineChart() throws IOException, Exception {

/* // ����һ����������ļ���Ķ���

// �½�һ��άJfreeChart����
JFreeChart[] jfreechart = new JFreeChart[2];
String ChartTitle = "";

JFreeChart chart = ChartFactory.createLineChart(ChartTitle, //


����(��һ�� �ı���)
"", // x �����
"", // y �����
getLineDataset(), // ���
PlotOrientation.VERTICAL, // ��ʾ����
true, // ��ʾ ��
true, false);

// ���ñ���ɫ
chart.setBackgroundPaint(new Color(193, 193, 193));

CategoryPlot categoryPlot = chart.getCategoryPlot();


// ����������м �ֱ���ɫ��
categoryPlot.setBackgroundPaint(new Color(233, 233, 233));
// x�� // ���������� �ɼ�
categoryPlot.setDomainGridlinesVisible(false);
categoryPlot.setDomainGridlinePaint(Color.WHITE);// ����ɫ��
// y�� //��������� �ɼ�
categoryPlot.setRangeGridlinesVisible(true);
categoryPlot.setRangeGridlinePaint(Color.BLACK);// ����ɫ��

categoryPlot.setNoDataMessage("û�����");
categoryPlot.setNoDataMessagePaint(Color.BLUE);
categoryPlot.setNoDataMessageFont(new Font("�� ",Font.PLAIN,35));

// ����������֮��ľ���
// plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

// ��ȡ x �����
CategoryAxis domainAxis = categoryPlot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);//
X��45��б
// ���þ��� Ƭ�� ���
domainAxis.setLowerMargin(0.0);
// ���þ��� Ƭ� ���
domainAxis.setUpperMargin(0.0);

// ��ȡ y �����
NumberAxis yAxis = (NumberAxis) categoryPlot.getRangeAxis();
// ����y����Сֵ
yAxis.setLowerBound(0.0D);
// ����Legend��� ����
// ((JFreeChart) chart).getLegend().setPosition(RectangleEdge.RIGHT);

NumberFormat nf =new DecimalFormat("0.0");


yAxis.setNumberFormatOverride(nf);//����y��� ֱ‫ٷ‬ȷ�ʽ��ʾ

// ����y��ʾ��ʽ ����y��� һ���Զ�� �� �

yAxis.setAutoTickUnitSelection(false);// �������� �ǩ�Ƿ��Զ�ȷ��


double rangetick = 5D;
yAxis.setTickUnit(new NumberTickUnit(rangetick)); // y� λ���Ϊ0.1

LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer)


categoryPlot
.getRenderer();
lineandshaperenderer.setBaseShapesVisible(true); // series � ���� �ɼ�

lineandshaperenderer.setBaseLinesVisible(true); // series � ���� ����l� ɼ�

// ��ʾ�۵����
lineandshaperenderer
.setBaseItemLabelGenerator(new
StandardCategoryItemLabelGenerator());
lineandshaperenderer.setBaseItemLabelsVisible(false);*/

String rateTitle = "";


JFreeChart chart2= ChartFactory.createLineChart(rateTitle, // ����(�
‫� ���ڶ‬ı���)
"", // x �����
"", // y �����
getLineDataset(), // ���
PlotOrientation.VERTICAL, // ��ʾ����
true, // ��ʾ ��
true, false);

// ���ñ���ɫ
chart2.setBackgroundPaint(new Color(193, 193, 193));

CategoryPlot plot2 = chart2.getCategoryPlot();


// ��ȡ x �����
// ����������м �ֱ���ɫ��
plot2.setBackgroundPaint(new Color(233, 233, 233));
// x�� // ���������� �ɼ�
plot2.setDomainGridlinesVisible(false);
plot2.setDomainGridlinePaint(Color.WHITE);// ����ɫ��
// y�� //��������� �ɼ�
plot2.setRangeGridlinesVisible(true);
plot2.setRangeGridlinePaint(Color.BLACK);// ����ɫ��

CategoryAxis axis2 = plot2.getDomainAxis();


axis2.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
// ���þ��� Ƭ�� ���
axis2.setLowerMargin(0.0);
// ���þ��� Ƭ� ���
axis2.setUpperMargin(0.0);

// ��ȡ y �����
NumberAxis numAxis2 = (NumberAxis) plot2.getRangeAxis();
// ����y����Сֵ
// numAxis2.setLowerBound(0.00D);
// ����Legend��λ�� ���λ��(Ĭ��λ���� �ε�����)
// ((JFreeChart)
// chart).getLegend().setPosition(RectangleEdge.RIGHT);

// ����y��ʾ��ʽ ����y��� һ���Զ�� �� �

//numAxis2.setAutoTickUnitSelection(false);// �������� �ǩ�Ƿ��Զ�ȷ��

// double rangetick = 0.05;


// numAxis2.setTickUnit(new NumberTickUnit(rangetick)); // y� λ���Ϊ0.1

// NumberFormat nf2 = NumberFormat.getPercentInstance();


// numAxis2.setNumberFormatOverride(nf2);// ����y��� ֱ‫ٷ‬ȷ�ʽ��ʾ

// ��ʾ�ֱ‫�ٷ‬
NumberFormat nf22 = new DecimalFormat("00.00%");
numAxis2.setNumberFormatOverride(nf22);// ����y��� ֱ‫ٷ‬ȷ�ʽ��ʾ

// ����ʹ��������С��λ��Ϊ����
// numAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

// �Զ������������ �Χʱ�� �Χ����С���(δȷ��)


//numAxis2.setAutoRangeMinimumSize(0.05d);;

// void setTickUnit(NumberTickUnit unit)�������� �ǩ(δȷ��)


// ����Ҫ��AutoTickUnitSelection��false��
// numAxis2.setTickUnit(new NumberTickUnit(5));
// numAxis2.setAutoTickUnitSelection(false);

LineAndShapeRenderer lineandshaperenderer2 = (LineAndShapeRenderer) plot2

.getRenderer();
lineandshaperenderer2.setBaseShapesVisible(true); // series� ���� �ɼ�

lineandshaperenderer2.setBaseLinesVisible(true); // series� ���� ����l� ɼ�

// ��ʾ�۵����
lineandshaperenderer2
.setBaseItemLabelGenerator(new
StandardCategoryItemLabelGenerator());
lineandshaperenderer2.setBaseItemLabelsVisible(false);

// ���õ�һ�������� �"���"Ϊ��ɫ�����һ�� ���ж������ ɷֱ�����


// lineandshaperenderer2.setSeriesFillPaint(0, new
// Color(193,193,193)); //��
// lineandshaperenderer2.setUseFillPaint(true); //Ӧ��

ChartFrame frame = new ChartFrame("TestPieChart", chart2);


frame.pack();
frame.setVisible(true);

private static DefaultCategoryDataset getLineDataset()


throws UnsupportedEncodingException, Exception {
boolean flag = true;

DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();


// ȡ����� ���ֶ����ͣ���Ҫ��
String[] rate = { "java", "c++", "vb" };

String values = "0";


// ��ʼ�������
if(flag){
for (int i = 0; i < rate.length; i++) {
// ����ʱ���ʽ
String datam = "000000";// ��ʽYYYYMM
// ��ȡ��������
// �ȳ�ʼ��һ��ֵ

// ȡ�õ�ǰ ������
String Type = rate[i];

// ��һ��:��ʼ������ ����� ��‫���ݣ‬ÿ����0.0� D


for (int h = 1; h <= 30; h++) {
datam = "02";
String end = "";
if (h < 10) {
end = 0 + Integer.toString(h);
} else {
end = Integer.toString(h);
}
datam = datam + end;
categoryDataset.addValue(Math.random(), rate[i], getDay(datam));

//���Ҫ��ʾ20% ���������Ϊ0.2
//categoryDataset.addValue(22.22d,rate[i],getDay(datam));
}
}
}
return categoryDataset;

// X��ʱ��IJ��� ��:���ַ�"20090103"‫��ת‬Ϊ"1��03��"���ַ�
private static String getDay(String dayStr) {
// ���Ϊ� �� ��Ȳ�����8λ��ֱ�ӷ���
if ("".equals(dayStr)) {
return dayStr;
} else if (8 != dayStr.length()) {
return dayStr;
} else {
String month = dayStr.substring(4, 6);
if (month.startsWith("0")) {
month = month.substring(1, 2);
}
month = month + "��";
String date = dayStr.substring(6, 8) + "��";
String day = month + date;
return day;
}

// �������ַ�‫��ת‬Ϊdouble����
private static double getDouble(String valueStr) {
if (valueStr.endsWith("%")) {
valueStr = valueStr.substring(0, valueStr.length() - 1);
// System.out.println("� �‫;)"��ת‬
}
if ("".equals(valueStr)) {
return 0.0d;
}
if (null == valueStr) {
return 0.0d;
}
double value = Double.parseDouble(valueStr);
return value;
}

private double getNumber(String valueStr) {


if (valueStr.endsWith("%")) {
valueStr = valueStr.substring(0, valueStr.length() - 1);
// System.out.println("� �‫;)"��ת‬
}
if ("".equals(valueStr)) {
return 0;
}
if (null == valueStr) {
return 0;
}

return Integer.parseInt(valueStr);
}
public static void main(String[] args) throws IOException, Exception {
createLineChart();
}

import java.text.SimpleDateFormat;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.StandardXYItemRenderer;
import org.jfree.data.XYDataset;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
* A time series demo, with monthly data, where the tick unit on the axis is set
to
* one month also (this switches off the auto tick unit selection, and *can*
result in
* overlapping labels).
*
* @author David Gilbert
*/
public class TimeSeriesDemo3 extends ApplicationFrame {

/**
* A demonstration application showing a quarterly time series containing a
null value.
*
* @param title the frame title.
*/
public TimeSeriesDemo3(String title) {
super(title);

TimeSeries series1 = new TimeSeries("Series 1", Month.class);


series1.add(new Month(1, 2002), 500.2);
series1.add(new Month(2, 2002), 694.1);
series1.add(new Month(3, 2002), 734.4);
series1.add(new Month(4, 2002), 453.2);
series1.add(new Month(5, 2002), 500.2);
series1.add(new Month(6, 2002), 345.6);
series1.add(new Month(7, 2002), 500.2);
series1.add(new Month(8, 2002), 694.1);
series1.add(new Month(9, 2002), 734.4);
series1.add(new Month(10, 2002), 453.2);
series1.add(new Month(11, 2002), 500.2);
series1.add(new Month(12, 2002), 345.6);

TimeSeries series2 = new TimeSeries("Series 2", Month.class);


series2.add(new Month(1, 2002), 234.1);
series2.add(new Month(2, 2002), 623.7);
series2.add(new Month(3, 2002), 642.5);
series2.add(new Month(4, 2002), 651.4);
series2.add(new Month(5, 2002), 643.5);
series2.add(new Month(6, 2002), 785.6);
series2.add(new Month(7, 2002), 234.1);
series2.add(new Month(8, 2002), 623.7);
series2.add(new Month(9, 2002), 642.5);
series2.add(new Month(10, 2002), 651.4);
series2.add(new Month(11, 2002), 643.5);
series2.add(new Month(12, 2002), 785.6);

TimeSeriesCollection dataset = new TimeSeriesCollection();


dataset.addSeries(series1);
dataset.addSeries(series2);

JFreeChart chart = createChart(dataset);

ChartPanel chartPanel = new ChartPanel(chart);


chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);

//
****************************************************************************
// * JFREECHART DEVELOPER GUIDE
*
// * The JFreeChart Developer Guide, written by David Gilbert, is available
*
// * to purchase from Object Refinery Limited:
*
// *
*
// * http://www.object-refinery.com/jfreechart/guide.html
*
// *
*
// * Sales are used to provide funding for the JFreeChart project - please
*
// * support us so that we can continue developing free software.
*
//
****************************************************************************

/**
* Creates a new chart.
*
* @param dataset the dataset.
*
* @return The dataset.
*/
private JFreeChart createChart(XYDataset dataset) {
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Time Series Demo 3",
"Time",
"Value",
dataset,
true,
true,
false
);
XYPlot plot = chart.getXYPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1,
new SimpleDateFormat("MMM-yyyy")));
axis.setVerticalTickLabels(true);

StandardXYItemRenderer renderer = (StandardXYItemRenderer)


plot.getRenderer();
renderer.setPlotShapes(true);
renderer.setSeriesShapesFilled(0, Boolean.TRUE);
renderer.setSeriesShapesFilled(1, Boolean.FALSE);

return chart;
}

/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {

TimeSeriesDemo3 demo = new TimeSeriesDemo3("Time Series Demo 3");


demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}
import java.io.File;
import java.text.SimpleDateFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
public class TimeSeriesExample
{
public static void main(String[] args)
{
// ������һ��ʱ����
TimeSeries pop1 = new TimeSeries("Population1", Day.class);
pop1.add(new Day(10, 1, 2004), 100);
pop1.add(new Day(10, 2, 2004), 150);
pop1.add(new Day(10, 3, 2004), 250);
pop1.add(new Day(10, 4, 2004), 275);
pop1.add(new Day(10, 5, 2004), 325);
pop1.add(new Day(10, 6, 2004), 425);

// ����һ��ʱ� �
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(pop1);
dataset.addSeries(pop2);

// ����ʱ��
// JFreeChart chart = ChartFactory.createTimeSeriesChart("����"��"x���‫"־‬,"y���

‫"־‬,"�������",� ���ʾ ��,� ������ʾ,� ����ñ����ŵ�ַ);


JFreeChart chart = ChartFactory.createTimeSeriesChart("� �
ͳ
��ʱ�� ","Date","Population",dataset,true,true,false);

try{
// ���� ����ʾ���
ChartFrame cf = new ChartFrame("ʱ�� ",chart);
cf.pack();
// ���� Ƭ��С
cf.setSize(500,300);
// ���� �οɼ�
cf.setVisible(true);

// // ���� Ƭ��ָ���ļ���
// //ChartUtilities.saveChartAsJPEG(new File("C:\\TimeSeriesChart1.jpg"),
chart, 500, 300);
} catch (Exception e){
System.err.println("Problem occurred creating chart.");
}
}
}

XYPlot plot = (XYPlot) chart.getPlot();

DateAxis axis = (DateAxis) plot.getDomainAxis();

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");


axis.setDateFormatOverride(format);//����x���� �λ� �����·�ʽ��ʾ

MM-dd-yyyy

Math.random()*100;(���100�Ļ�д��

XYLineAndShapeRenderer
xylinerenderer=(XYLineAndShapeRenderer)xyplot.getRenderer();

XYBarRenderer BarRender=new XYBarRenderer();


plot.setRenderer(BarRender);

CategoryPlot plot=chart.getCategoryPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setRangeGridlinePaint(Color.BLUE);//����������ɫ
plot.setDomainGridlinePaint(Color.BLACK);//����������ɫ
plot.setDomainGridlinesVisible(true);//��ʾ��������
plot.setRangeGridlinesVisible(true);//��ʾ��������

LineAndShapeRenderer renderer =
(LineAndShapeRenderer)plot.getRenderer();
DecimalFormat decimalformat1 = new DecimalFormat("##.##");//��

���ʾ���ֵ�ĸ�ʽ
renderer.setItemLabelGenerator(new
StandardCategoryItemLabelGenerator("{2}", decimalformat1));
//�������������������ǩ�������
renderer.setItemLabelsVisible(true);//�������ǩ��ʾ
renderer.setBaseItemLabelsVisible(true);//�����ǩ��ʾ
//�����⼸��;����� ���趨�ĸ�ʽ��ʾ���ֵ

renderer.setShapesFilled(Boolean.TRUE);//���� ���ʾʵ�ĵ�С ��
renderer.setShapesVisible(true);//������ʾС ��

XYLineAndShapeRenderer xylineandshaperenderer =
(XYLineAndShapeRenderer)plot.getRenderer();

xylineandshaperenderer.setBaseShapesVisible(true);//��������� ���ʾ�� �

xylineandshaperenderer.setShape(new CurveCircle( -1.0d,


-1.0d, 2.0d));

RECTANGLE_SHAPE
Ellipse2D.Double(double x, double y, double w, double h)

new Font("SansSerif", Font.BOLD, 16);

xylineandshaperenderer.setSeriesFillPaint(0, Color.red); //���õ�һ��������

����Ϊ��ɫ�����һ�� ���ж������ ɷֱ�����

xylineandshaperenderer.setUseFillPaint(true);

//x���ϵĿ̶ȵ������ʱ������ʱ���

timeseriescollection.setDomainIsPointsInTime(true);

//�����������b
DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
dateaxis.setTickUnit(new DateTickUnit(1, 1, new SimpleDateFormat("MMM-
yyyy")));
dateaxis.setVerticalTickLabels(true);

//����ʱ����Ϊһ��
dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY,1));//����ʱ����Ϊһ��

TextTitle�
void setFont(Font font)��������
void setPaint(Paint paint)����������ɫ
void setText(String text)��������
void setItemLabelAnchorOffset(double offset)�� �ǩ������ ��ƫ��

void setItemLabelAnchorOffset(double offset)�� �ǩ������ ��ƫ��

void setItemLabelsVisible(boolean visible)�� �ǩ�Ƿ�ɼ�

void setItemLabelFont(Font font)�� �ǩ������

void setItemLabelPaint(Paint paint)�� �ǩ��������ɫ

void setItemLabelPosition(ItemLabelPosition position)�� �ǩλ��


void setPositiveItemLabelPosition(ItemLabelPosition position)�����ǩλ��
void setNegativeItemLabelPosition(ItemLabelPosition position)�����ǩλ��
void setOutLinePaint(Paint paint) �α ��������ɫ

void setOutLineStroke(Stroke stroke) �α ������ʴ�


void setPaint(Paint paint)���з��� �ε���ɫ
void setShape(Shape shape)���з��� �ε���‫� ��������״‬ĵ

void setStroke(Stroke stroke)���з��� �εıʴ��������� ��� �

void setSeriesItemLabelsVisible(int series,boolean visible)ָ��������� �ǩ�Ƿ�ɼ�

void setSeriesItemLabelFont(int series,Font font)ָ��������� �ǩ������

void setSeriesItemLabelPaint(int series,Paint paint)ָ��������� �ǩ��������ɫ

void setSeriesItemLabelPosition(int series,ItemLabelPosition position)�� �ǩλ��


void setSeriesPositiveItemLabelPosition(int series,ItemLabelPosition
position)�����ǩλ��
void setSeriesNegativeItemLabelPosition(int series,ItemLabelPosition
position)�����ǩλ��
void setSeriesOutLinePaint(int series,Paint paint)ָ������� �α ��������ɫ

void setSeriesOutLineStroke(int series,Stroke stroke)ָ������� �α ������ʴ�

void setSeriesPaint(int series,Paint paint)ָ������ �ε���ɫ

void setSeriesShape(int series,Shape shape)ָ������ �ε���‫� ��������״‬ĵ

void setSeriesStroke(int series,Stroke stroke)ָ������ �εıʴ��������� ��� �

AbstractCategoryItemRenderer(AbstractRenderer)�

void setLabelGenerator(CategoryLabelGenerator generator)�� �ǩ�ĸ�ʽ


void setToolTipGenerator(CategoryToolTipGenerator generator)MAP��������ϵ���ʾ��ʽ
void setItemURLGenerator(CategoryURLGenerator generator)MAP����ȡt�Ӹ�ʽ
void setSeriesLabelGenerator(int series,CategoryLabelGenerator generator)ָ���������

�ǩ�ĸ�ʽ
void setSeriesToolTipGenerator(int series,CategoryToolTipGenerator generator)ָ

�������MAP��������ϵ���ʾ��ʽ

void setSeriesItemURLGenerator(int series,CategoryURLGenerator generator)ָ

�������MAP����ȡt�Ӹ�ʽ

StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")

new StandardXYToolTipGenerator(
StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")
)

xyplot.setBackgroundPaint(Color.lightGray); //�趨 �������ʾ���ֱ���ɫ

xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); //�趨������� �������ʾ���

‫���־‬
xyplot.setDomainGridlinePaint(Color.white); //�����������ɫ
xyplot.setRangeGridlinePaint(Color.white); //���� �����ɫ

NumberAxis numAxis = (NumberAxis)xyplot.getRangeAxis();


DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
Axis�
void setVisible(boolean flag)������ �ɼ�
void setAxisLinePaint(Paint paint)�����������ɫ��3D����Ч��
void setAxisLineStroke(Stroke stroke)���������ʴ���3D����Ч��
void setAxisLineVisible(boolean visible)���������� �ɼ�3D����Ч��
void setFixedDimension(double dimension)�����‫��ڸ‬ϱ��жԶ����������ã�
void setLabel(String label)��������
void setLabelFont(Font font)������������
void setLabelPaint(Paint paint)����������ɫ
void setLabelAngle(double angle)`����������‫�ת‬Ƕȣ�����������‫��ת‬
void setTickLabelFont(Font font)�������ֵ����

void setTickLabelPaint(Paint paint)�������ֵ��ɫ

void setTickLabelsVisible(boolean flag)�������ֵ� ���ʾ


void setTickMarkPaint(Paint paint)���������ɫ
void setTickMarkStroke(Stroke stroke)������ ʴ�
void setTickMarksVisible(boolean flag)�������� ���ʾ
ValueAxis(Axis)�

void setAutoRange(boolean auto)�Զ������������ �Χ

void setAutoRangeMinimumSize(double size)�Զ������������ �Χʱ�� �Χ����С���

void setAutoTickUnitSelection(boolean flag)�������� �ǩ�Ƿ��Զ�ȷ����Ĭ��Ϊtrue��

void setFixedAutoRange(double length)�����̶���

�Χ������100�Ļ�������ʾMAXVALUE��MAXVALUE-100�Ƕ��� �Χ��
void setInverted(boolean flag)������ ���Ĭ��Ϊfalse��
void setLowerMargin(double margin)������£�� �

void setUpperMargin(double margin)������ ��ң�� �

void setLowerBound(double min)������ϵ���ʾ��Сֵ

void setUpperBound(double max)������ϵ���ʾ���ֵ


void setPositiveArrowVisible(boolean visible)� ���ʾ����� ��3D����Ч��
void setNegativeArrowVisible(boolean visible)� ���ʾ����� ��3D����Ч��
void setVerticalTickLabels(boolean flag)������� �ǩ�Ƿ���‫ֱ����ת‬

void setStandardTickUnits(TickUnitSource source)��������

�ǩ������ֻ��ʾ�����ǩ����Ҫ��AutoTickUnitSelection��false��

NumberAxis(ValueAxis)�

void setAutoRangeIncludesZero(boolean flag)�Ƿ�ǿ�����Զ�ѡ����� �Χ�а�0

void setAutoRangeStickyZero(boolean flag)� �ǿ�������������а�0����ʹ0������ �Χ��

void setNumberFormatOverride(NumberFormat formatter)������� �ǩ����ʾ��ʽ

void setTickUnit(NumberTickUnit unit)��������

�ǩ����Ҫ��AutoTickUnitSelection��false��

DateAxis(ValueAxis)�
void setMaximumDate(Date maximumDate)�������ϵ���С����
void setMinimumDate(Date minimumDate)�������ϵ��������
void setRange(Date lower,Date upper)����� Χ
void setDateFormatOverride(DateFormat formatter)���������‫�ڱ‬ǩ����ʾ��ʽ
void setTickUnit(DateTickUnit unit)����������
‫�ڱ‬ǩ����Ҫ��AutoTickUnitSelection��false��
void setTickMarkPosition(DateTickMarkPosition position)���
‫�ڱ‬ǩλ�ã�������org.jfree.chart.axis.DateTickMarkPosition���ж��壩
CategoryAxis(Axis)�

void setCategoryMargin(double margin)������ �

void setLowerMargin(double margin)�������£�� �

void setUpperMargin(double margin)������� ��ң�� �

void setVerticalCategoryLabels(boolean flag)���������� ���‫ֱ����ת‬


void setMaxCategoryLabelWidthRatio(float ratio)����������ǩ�������

void setDataset(PieDataset dataset) ������1�� �

void setIgnoreNullValues(boolean flag) ������ֵ�ķ���


void setCircular(boolean flag) �� � �һ������
void setStartAngle(double angle) �� �ij�ʼ�Ƕ�
void setDirection(Rotation direction) �� ����‫����ת‬

void setExplodePercent(int section,double percent) ��ȡ���ǿ 飨 1ά�� �ķ����±

�Լ���ȡ��4�ľ��루 0.0��1.0����3D�� ��Ч


void setLabelBackgroundPaint(Paint paint) �����ǩ�ĵ�ɫ
void setLabelFont(Font font) �����ǩ������
void setLabelPaint(Paint paint) �����ǩ��������ɫ
void setLabelLinkMargin(double margin) �����ǩ��ͼ��l��� �
void setLabelLinkPaint(Paint paint) �����ǩ��ͼ��l������ɫ
void setLabelLinkStroke(Stroke stroke) �����ǩ��ͼ��l��� ʴ�

void setLabelOutlinePaint(Paint paint) �����ǩ� ���ɫ

void setLabelOutlineStroke(Paint paint) �����ǩ� �ʴ�


void setLabelShadowPaint(Paint paint) �����ǩ��Ӱ��ɫ
void setMaximumLabelWidth(double width) �����ǩ���� ȣ�0.0��1.0��
void setPieIndex(int index) ��ͼ������ϱ�ͼ���õ���
void setSectionOutlinePaint(int section,Paint paint) ָ�������ı ���ɫ

void setSectionOutlineStroke(int section,Stroke stroke) ָ�������ı �ʴ�

void setSectionPaint(int section,Paint paint) ָ����������ɫ


void setShadowPaint(Paint paint) �� ����Ӱ��ɫ
void setShadowXOffset(double offset) �� ����Ӱ��� �� ƽƫ��
void setShadowYOffset(double offset) �� ����Ӱ��� �Ĵ�ֱƫ��
void setLabelGenerator(PieSectionLabelGenerator generator)
�����ǩ�ĸ�ʽ�����ó�null������ǩ��(l��� �����ʾ
void setToolTipGenerator(PieToolTipGenerator generator) MAP��������ϵ���ʾ��ʽ
void setURLGenerator(PieURLGenerator generator) MAP����ȡt�Ӹ�ʽ

//ʹ���ĺ��ֱ�����

jfreechart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingH
ints.VALUE_TEXT_ANTIALIAS_OFF);

final Rotator rotator = new Rotator(plot);


rotator.start();

class Rotator extends Timer implements ActionListener {

/** The plot. */


private PiePlot3D plot;

/** The angle. */


private int angle = 270;

/**
* Constructor.
*
* @param plot the plot.
*/
Rotator(final PiePlot3D plot) {
super(100, null);
this.plot = plot;
addActionListener(this);
}

/**
* Modifies the starting angle.
*
* @param event the action event.
*/
public void actionPerformed(final ActionEvent event) {
this.plot.setStartAngle(this.angle);
this.angle = this.angle + 1;
if (this.angle == 360) {
this.angle = 0;
}
}

}
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.util.Rotation;

/**
* A rotating 3D pie chart.
*
*/
public class PieChart3DDemo2 extends ApplicationFrame {

/**
* Creates a new demo.
*
* @param title the frame title.
*/
public PieChart3DDemo2(final String title) {

super(title);

// create a dataset...
final DefaultPieDataset data = new DefaultPieDataset();
data.setValue("Java", new Double(43.2));
data.setValue("Visual Basic", new Double(10.0));
data.setValue("C/C++", new Double(17.5));
data.setValue("PHP", new Double(32.5));
data.setValue("Perl", new Double(12.5));

// create the chart...


final JFreeChart chart = ChartFactory.createPieChart3D(
"Pie Chart 3D Demo 2", // chart title
data, // data
true, // include legend
true,
false
);

chart.setBackgroundPaint(Color.yellow);
final PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setStartAngle(270);
plot.setDirection(Rotation.ANTICLOCKWISE);
plot.setForegroundAlpha(0.60f);
plot.setInteriorGap(0.33);
// add the chart to a panel...
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);

final Rotator rotator = new Rotator(plot);


rotator.start();

/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(final String[] args) {

final PieChart3DDemo2 demo = new PieChart3DDemo2("Pie Chart 3D Demo 2");


demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

// ****************************************************************************
// * JFREECHART DEVELOPER GUIDE *
// * The JFreeChart Developer Guide, written by David Gilbert, is available *
// * to purchase from Object Refinery Limited: *
// * *
// * http://www.object-refinery.com/jfreechart/guide.html *
// * *
// * Sales are used to provide funding for the JFreeChart project - please *
// * support us so that we can continue developing free software. *
// ****************************************************************************

/**
* The rotator.
*
*/
class Rotator extends Timer implements ActionListener {

/** The plot. */


private PiePlot3D plot;

/** The angle. */


private int angle = 270;

/**
* Constructor.
*
* @param plot the plot.
*/
Rotator(final PiePlot3D plot) {
super(100, null);
this.plot = plot;
addActionListener(this);
}
/**
* Modifies the starting angle.
*
* @param event the action event.
*/
public void actionPerformed(final ActionEvent event) {
this.plot.setStartAngle(this.angle);
this.angle = this.angle + 1;
if (this.angle == 360) {
this.angle = 0;
}
}

//renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
renderer.setLabelGenerator(new
StandardCategoryLabelGenerator("{2}",java.text.NumberFormat.getPercentInstance()))
;
renderer.setItemLabelsVisible(true);
renderer.setItemLabelFont(new java.awt.Font("����", Font.TRUETYPE_FONT, 20));

renderer.setSeriesLabelGenerator(0,new
StandardCategoryLabelGenerator("##%",java.text.NumberFormat.getPercentInstance()))
;
plot.setRenderer(renderer);

DecimalFormat df = new DecimalFormat("0.00%");


custombarrenderer3d.setBaseItemLabelGenerator(new
StandardCategoryItemLabelGenerator("{2}", df));

You might also like