本文整理汇总了Java中org.jfree.chart.JFreeChart类的典型用法代码示例。如果您正苦于以下问题:Java JFreeChart类的具体用法?Java JFreeChart怎么用?Java JFreeChart使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JFreeChart类属于org.jfree.chart包,在下文中一共展示了JFreeChart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDrawWithNullInfo
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Draws the chart with a single range. At one point, this caused a null
* pointer exception (fixed now).
*/
public void testDrawWithNullInfo() {
boolean success = false;
MeterPlot plot = new MeterPlot(new DefaultValueDataset(60.0));
plot.addInterval(new MeterInterval("Normal", new Range(0.0, 80.0)));
JFreeChart chart = new JFreeChart(plot);
try {
BufferedImage image = new BufferedImage(200, 100,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
g2.dispose();
success = true;
}
catch (Exception e) {
success = false;
}
assertTrue(success);
}
示例2: MultiLineChart
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
public MultiLineChart(final String title, List<Users> tpaverficationUserList) {
super(title);
this.tpaverficationUserList = tpaverficationUserList;
XYDataset dataset = null;
try {
dataset = createDataset();
} catch (Exception e) {
System.out.println("MultiLineChart -- Constructor" + e);
}
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(700, 470));
setContentPane(chartPanel);
this.pack();
RefineryUtilities.centerFrameOnScreen(this);
this.setVisible(true);
}
开发者ID:cyberheartmi9,项目名称:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud,代码行数:19,代码来源:MultiLineChart.java
示例3: testXYAutoRange1
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Checks that the auto-range for the domain axis on an XYPlot is
* working as expected.
*/
public void testXYAutoRange1() {
XYSeries series = new XYSeries("Series 1");
series.add(1.0, 1.0);
series.add(2.0, 2.0);
series.add(3.0, 3.0);
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
JFreeChart chart = ChartFactory.createScatterPlot(
"Test",
"X",
"Y",
dataset,
PlotOrientation.VERTICAL,
false,
false,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
NumberAxis axis = (NumberAxis) plot.getDomainAxis();
axis.setAutoRangeIncludesZero(false);
assertEquals(0.9, axis.getLowerBound(), EPSILON);
assertEquals(3.1, axis.getUpperBound(), EPSILON);
}
示例4: createChart
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
@Override
public JFreeChart createChart(Element element, ChartSource source) {
Attribute key = source.getAttributeProperty(PIE_ATTRIBUTE_KEY);
Attribute value = source.getAttributeProperty(PIE_ATTRIBUTE_VALUE);
if ((key == null) || (value == null))
throw new ChartNotSetupedException();
DefaultPieDataset dataset = new DefaultPieDataset();
for (Element element2 : source.getElements()) {
Object v1 = engine.getAttribute(element2, key);
Object v2 = engine.getAttribute(element2, value);
if ((v1 != null) && (v2 != null))
dataset.setValue(toString(v1), toDouble(v2));
}
return ChartFactory.createPieChart(element.getName(), dataset, true,
true, false);
}
示例5: testDrawWithNullInfo
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Draws the chart with a <code>null</code> info object to make sure that
* no exceptions are thrown (particularly by code in the renderer).
*/
public void testDrawWithNullInfo() {
boolean success = false;
try {
DefaultStatisticalCategoryDataset dataset
= new DefaultStatisticalCategoryDataset();
dataset.add(1.0, 2.0, "S1", "C1");
dataset.add(3.0, 4.0, "S1", "C2");
CategoryPlot plot = new CategoryPlot(dataset,
new CategoryAxis("Category"), new NumberAxis("Value"),
new StatisticalLineAndShapeRenderer());
JFreeChart chart = new JFreeChart(plot);
/* BufferedImage image = */ chart.createBufferedImage(300, 200,
null);
success = true;
}
catch (NullPointerException e) {
e.printStackTrace();
success = false;
}
assertTrue(success);
}
示例6: linePlot
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
public JFreeChart linePlot(String xLabel, String yLabel){
int numDatasets = dataset.size();
JFreeChart result = ChartFactory.createXYLineChart(
chartTitle, // chart title
xLabel, // x axis label
yLabel, // y axis label
dataset.get(0), // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);
XYPlot plot = result.getXYPlot();
plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));
for(int i=1;i<numDatasets;i++){
plot.setDataset(i,dataset.get(i));
//XYItemRenderer renderer = plot.getRenderer(i-0);
//plot.setRenderer(i, new XYLineAndShapeRenderer(false, true));
plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
}
return result;
}
开发者ID:PacktPublishing,项目名称:Neural-Network-Programming-with-Java-SecondEdition,代码行数:26,代码来源:Chart.java
示例7: createChart
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return A sample chart.
*/
private JFreeChart createChart(IntervalXYDataset dataset,String s) {
final JFreeChart chart = ChartFactory.createXYBarChart(
"Histogram Plot: "+s,
"Keyword index",
false,
"frequency",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
final IntervalMarker target = new IntervalMarker(400.0, 700.0);
//target.setLabel("Target Range");
target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
target.setLabelAnchor(RectangleAnchor.LEFT);
target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
target.setPaint(new Color(222, 222, 255, 128));
plot.addRangeMarker(target, Layer.BACKGROUND);
return chart;
}
示例8: main
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {
final JFreeChart chart = createChart(createDataset());
final Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(600, 300);
shell.setLayout(new FillLayout());
shell.setText("Time series demo for jfreechart running with SWT");
ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart, true);
frame.setDisplayToolTips(true);
frame.setHorizontalAxisTrace(false);
frame.setVerticalAxisTrace(false);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
示例9: ChartTab
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Constructor
* @param chart The chart to be displayed
*/
public ChartTab(JFreeChart chart, ChartEditorJPanel parent) {
this.parent = parent;
// --- Create and configure the chart panel ---
this.chartPanel = new ChartPanel(chart);
this.chartPanel.setBackground(Color.WHITE); // Component background
this.chartPanel.getChart().getPlot().setBackgroundPaint(Color.WHITE); // Chart background
this.chartPanel.getChart().getXYPlot().setDomainGridlinePaint(Color.BLACK);
this.chartPanel.getChart().getXYPlot().setRangeGridlinePaint(Color.BLACK);
// --- Create the tool bar --------------------
this.rebuildVisibilityToolBar();
// --- Add components to the panel ------------
this.setLayout(new BorderLayout());
this.add(this.chartPanel, BorderLayout.CENTER);
this.add(this.getJToolBarSeriesVisibility(), BorderLayout.SOUTH);
// parent.getDataModel().getChartSettingModel().addObserver(this);
}
示例10: testDrawWithNullInfo
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Draws the chart with a <code>null</code> info object to make sure that
* no exceptions are thrown (particularly by code in the renderer).
*/
public void testDrawWithNullInfo() {
boolean success = false;
try {
double[][] starts = new double[][] {{0.1, 0.2, 0.3},
{0.3, 0.4, 0.5}};
double[][] ends = new double[][] {{0.5, 0.6, 0.7}, {0.7, 0.8, 0.9}};
DefaultIntervalCategoryDataset dataset
= new DefaultIntervalCategoryDataset(starts, ends);
IntervalBarRenderer renderer = new IntervalBarRenderer();
CategoryPlot plot = new CategoryPlot(dataset,
new CategoryAxis("Category"), new NumberAxis("Value"),
renderer);
JFreeChart chart = new JFreeChart(plot);
/* BufferedImage image = */ chart.createBufferedImage(300, 200,
null);
success = true;
}
catch (NullPointerException e) {
e.printStackTrace();
success = false;
}
assertTrue(success);
}
示例11: testDrawWithEmptyDataset
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Test chart drawing with an empty dataset to ensure that this special
* case doesn't cause any exceptions.
*/
public void testDrawWithEmptyDataset() {
boolean success = false;
JFreeChart chart = ChartFactory.createStackedXYAreaChart("title", "x",
"y", new DefaultTableXYDataset(), PlotOrientation.VERTICAL,
true, false, false);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setRenderer(new StackedXYAreaRenderer2());
try {
BufferedImage image = new BufferedImage(200 , 100,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
g2.dispose();
success = true;
}
catch (Exception e) {
success = false;
}
assertTrue(success);
}
示例12: createLineChart
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Create a line chart with sample data in the range -3 to +3.
*
* @return The chart.
*/
private static JFreeChart createLineChart() {
// create a dataset...
Number[][] data = new Integer[][]
{{new Integer(-3), new Integer(-2)},
{new Integer(-1), new Integer(1)},
{new Integer(2), new Integer(3)}};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S",
"C", data);
// create the chart...
return ChartFactory.createLineChart(
"Line Chart",
"Domain", "Range",
dataset,
PlotOrientation.HORIZONTAL,
true, // include legend
true,
true
);
}
示例13: testDrawWithNullInfo
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Draws the chart with a <code>null</code> info object to make sure that
* no exceptions are thrown (particularly by code in the renderer).
*/
public void testDrawWithNullInfo() {
boolean success = false;
try {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, "S1", "C1");
dataset.addValue(2.0, "S1", "C2");
dataset.addValue(3.0, "S2", "C1");
dataset.addValue(4.0, "S2", "C2");
GroupedStackedBarRenderer renderer
= new GroupedStackedBarRenderer();
CategoryPlot plot = new CategoryPlot(dataset,
new CategoryAxis("Category"), new NumberAxis("Value"),
renderer);
JFreeChart chart = new JFreeChart(plot);
/* BufferedImage image = */ chart.createBufferedImage(300, 200,
null);
success = true;
}
catch (NullPointerException e) {
e.printStackTrace();
success = false;
}
assertTrue(success);
}
示例14: test1654215
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* A test for bug 1654215 (where a renderer is added to the plot without
* a corresponding dataset and it throws an exception at drawing time).
*/
public void test1654215() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
dataset, PlotOrientation.VERTICAL, true, false, false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setRenderer(1, new LineAndShapeRenderer());
boolean success = false;
try {
BufferedImage image = new BufferedImage(200 , 100,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
g2.dispose();
success = true;
}
catch (Exception e) {
e.printStackTrace();
success = false;
}
assertTrue(success);
}
示例15: createChart
import org.jfree.chart.JFreeChart; //导入依赖的package包/类
/**
* Create a stacked bar chart with sample data in the range -3 to +3.
*
* @return The chart.
*/
private static JFreeChart createChart() {
// create a dataset...
Number[][] data = new Integer[][]
{{new Integer(-3), new Integer(-2)},
{new Integer(-1), new Integer(1)},
{new Integer(2), new Integer(3)}};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S",
"C", data);
// create the chart...
return ChartFactory.createStackedAreaChart(
"Stacked Area Chart", // chart title
"Domain", "Range",
dataset, // data
PlotOrientation.HORIZONTAL,
true, // include legend
true,
true
);
}