使用Java进行XY绘图

red*_*ike 14 java charts plot

我试图找到一些关于用Java绘图的信息 - 特别是xy绘图.我遇到过多个java库,但我不确定哪些易于学习使用/将其集成到现有应用程序中的难度.

我遇到过的是:JFreeChart和JOpenChart

我也查看了这个列表中的一些(并非所有都具有XY绘图功能):10个适用于开发人员的优秀免费开源Java图表库

有任何经验的人知道哪个是最容易/最快学习如何使用?

Neo*_*Neo 18

我已经使用jfreechart 100次用于不同的解决方案.它很容易学习,因为它有一个开发人员指南和更多关于Java2s.com的简单教程.只是google它,你会发现更多这里是XY系列的演示

 package org.jfree.chart.demo;

 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 XYSeriesDemo extends ApplicationFrame {

/**
 * A demonstration application showing an XY series containing a null value.
 *
 * @param title  the frame title.
 */
public XYSeriesDemo(final String title) {

    super(title);
    final XYSeries series = new XYSeries("Random Data");
    series.add(1.0, 500.2);
    series.add(5.0, 694.1);
    series.add(4.0, 100.0);
    series.add(12.5, 734.4);
    series.add(17.3, 453.2);
    series.add(21.2, 500.2);
    series.add(21.9, null);
    series.add(25.6, 734.4);
    series.add(30.0, 453.2);
    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart(
        "XY Series Demo",
        "X", 
        "Y", 
        data,
        PlotOrientation.VERTICAL,
        true,
        true,
        false
    );

    final 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.             *
// ****************************************************************************

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

    final XYSeriesDemo demo = new XYSeriesDemo("XY Series Demo");
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);

}

}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 哇!A +回答!非常感谢 - 这正是我所寻求的那种反馈. (2认同)
  • 如果您需要将绘图保存到文件:ChartUtilities.saveChartAsPNG(新文件("your_filename"),chart1,width,height); 在try catch块中. (2认同)