codice:
import java.awt.Font;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.category.CategoryDataset;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.CategoryPlot;
public class LineGraph2 extends JFrame
{
private static final long serialVersionUID = 1L;
private CategoryDataset dataset;
private JFreeChart jfc;
public LineGraph2()
{
dataset = createDataset();
}
private CategoryDataset createDataset() {
// row keys...
final String series1 = "First";
final String series2 = "Second";
final String series3 = "Third";
// column keys...
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";
// create the dataset2...
final DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.addValue(1.0, series1, type1);
dataset2.addValue(4.0, series1, type2);
dataset2.addValue(3.0, series1, type3);
dataset2.addValue(5.0, series1, type4);
dataset2.addValue(5.0, series1, type5);
dataset2.addValue(7.0, series1, type6);
dataset2.addValue(7.0, series1, type7);
dataset2.addValue(8.0, series1, type8);
dataset2.addValue(5.0, series2, type1);
dataset2.addValue(7.0, series2, type2);
dataset2.addValue(6.0, series2, type3);
dataset2.addValue(8.0, series2, type4);
dataset2.addValue(4.0, series2, type5);
dataset2.addValue(4.0, series2, type6);
dataset2.addValue(2.0, series2, type7);
dataset2.addValue(1.0, series2, type8);
dataset2.addValue(4.0, series3, type1);
dataset2.addValue(3.0, series3, type2);
dataset2.addValue(2.0, series3, type3);
dataset2.addValue(3.0, series3, type4);
dataset2.addValue(6.0, series3, type5);
dataset2.addValue(3.0, series3, type6);
dataset2.addValue(4.0, series3, type7);
dataset2.addValue(3.0, series3, type8);
return dataset2;
}
public void setChar(String title)
{
jfc = 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
);
//jfc.setBackgroundPaint(Color.yellow); // Set the background colour of the chart
jfc.getTitle().setPaint(Color.blue); // Adjust the colour of the title
CategoryPlot p = jfc.getCategoryPlot(); // Get the Plot object for a bar graph
p.setBackgroundPaint(new Color(206, 252, 255)); // Modify the plot background
p.setRangeGridlinePaint(Color.black); // Modify the colour of the plot gridlines Modify Chart
}
private JPanel createPanel()
{
return new ChartPanel(jfc);
}
public void Show()
{
setContentPane(createPanel());
setVisible(true);
}
public static void main(String[] args)
{
LineGraph2 j = new LineGraph2();
j.setTitle("Example Chart...");
j.setSize(640, 430);
j.setChar("Example Chart...");
j.Show();
}
}