我是JFreeChart的新手。我用JFreeChart創建了折線圖。現在,我想添加有關圖表外側的附加細節(即在圖表的左側和底部)。另外,我想用生成的圖表保存所有的信息。任何機構都可以幫助我。如何在圖表外添加有關圖表的其他詳細信息
package hh;
import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.renderer.xy.XYSplineRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class XYLineChartExample extends JFrame {
// double x=1.08,y=0.370;
JFreeChart chart;
public XYLineChartExample() {
super("XY Line Chart Example with JFreechart");
JPanel chartPanel = createChartPanel();
add(chartPanel, BorderLayout.CENTER);
setSize(1240, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
private JPanel createChartPanel() {
String chartTitle = "Objects Movement Chart";
String xAxisLabel = "X";
String yAxisLabel = "Y";
XYDataset dataset = createDataset();
JFreeChart chart = ChartFactory.createXYLineChart(chartTitle,
xAxisLabel, yAxisLabel, dataset);
XYPlot plot = chart.getXYPlot();
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
plot.setRenderer(renderer);
renderer.setSeriesPaint(2, Color.RED);
renderer.setSeriesPaint(3, Color.BLACK);
renderer.setSeriesPaint(4, Color.BLACK);
renderer.setSeriesPaint(5, Color.BLUE);
renderer.setSeriesPaint(6, Color.RED);
File imageFile = new File(
"C:/Users/varinder/Desktop/Graphs/Branch1_Grap.jpg");
int width = 1240;
int height = 500;
try {
ChartUtilities.saveChartAsJPEG(imageFile, chart, width, height);
} catch (IOException ex) {
System.err.println(ex);
}
return new ChartPanel(chart);
}
private XYDataset createDataset() {
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries series = new XYSeries("Object 1");
XYSeries series2 = new XYSeries("Object 2");
XYSeries series3 = new XYSeries("Object 3");
XYSeries series4 = new XYSeries("Object 4");
XYSeries series5 = new XYSeries("Object 5");
XYSeries series6 = new XYSeries("Object 6");
XYSeries series7 = new XYSeries("Object 7");
// fixed X axis
series.add(.10, .000);
series.add(.20, .000);
series.add(.30, .000);
series.add(.40, .000);
series.add(.50, .000);
series.add(.60, .000);
series.add(.70, .000);
series.add(.80, .000);
series.add(.90, .000);
series.add(1.00, .000);
series.add(1.10, .000);
series.add(1.20, .000);
series.add(1.30, .000);
series.add(1.40, .000);
series.add(1.50, .000);
series.add(1.60, .000);
series.add(1.70, .000);
series.add(1.80, .000);
series.add(1.90, .000);
series.add(2.00, .000);
series.add(2.10, .000);
series.add(2.20, .000);
series.add(2.30, .000);
series.add(2.30, .000);
series.add(2.40, .000);
series.add(2.50, .000);
series.add(2.60, .000);
series.add(2.70, .000);
series.add(2.80, .000);
series.add(2.90, .000);
series.add(3.00, .000);
series.add(3.10, .000);
series.add(3.20, .000);
series.add(3.30, .000);
series.add(3.40, .000);
series.add(3.50, .000);
series.add(3.60, .000);
// series.add(3.70, .000);
// fixed Y axis
series2.add(.00, .100);
series2.add(.00, .200);
series2.add(.00, .300);
series2.add(.00, .400);
series2.add(.00, .500);
series2.add(.00, .600);
series2.add(.00, .700);
series2.add(.00, .800);
series2.add(.00, .900);
series2.add(.00, 1.000);
series2.add(.00, 1.100);
series2.add(.00, 1.200);
// Bed level with red color
// series2.add(0, 193.500);
// series3.add(1.92, 100.370);
series3.add(0.88, 0.900);
series3.add(2.12, 0.900);
series3.add(0.75, 0.900);
series3.add(2.25, 0.900);
series3.add(0.59, 0.300);
series3.add(2.41, 0.300);
series3.add(0.00, 0.300);
series3.add(3.1, .300);
series4.add(0.88, 0.304);
series4.add(2.12, 0.304);
series4.add(0.879, 0.876);// one decrease
series4.add(2.12, 0.876);
series5.add(0.88, 0.876);
series5.add(1.109, 0.876);
series5.add(1.109, 0.376);
series6.add(2.12, 0.876);
series6.add(1.891, 0.876);
series6.add(1.890, 0.376);
series6.add(1.109, 0.376);
series7.add(1.109, 0.876);// sement area by adding 0.1.
series7.add(1.119, 0.876);
series7.add(1.119, 0.386);
series7.add(1.881, 0.386);
series7.add(1.881, 0.876);
series7.add(1.891, 0.876);
// series7.add(1.11, 0.);
dataset.addSeries(series);
dataset.addSeries(series2);
dataset.addSeries(series3);
dataset.addSeries(series4);
dataset.addSeries(series5);
dataset.addSeries(series6);
dataset.addSeries(series7);
return dataset;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new XYLineChartExample().setVisible(true);
}
});
}
}
這不是一個簡單的例子。你嘗試了什麼? –
什麼_附加details_,爲[示例](http://stackoverflow.com/a/13309587/230513)? – trashgod