This article describes the line chart effect implemented by the JFreeChart plug-in. Share it for your reference, as follows:
package com.lei.jfreechart;import javax.swing.JPanel;import org.jfree.chart.ChartFactory;import org.jfree.chart.ChartPanel;import org.jfree.chart.ChartPanel;import org.jfree.chart.axis.NumberAxis;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.PlotOrientation;import org.jfree.data.category.DefaultCategoryDataset;import org.jfree.ui.ApplicationFrame;import org.jfree.ui.RefineryUtilities;public class LineCharts extends ApplicationFrame {/****/private static final long serialVersionUID = 1L;public LineCharts(String s) { super(s); setContentPane(createDemoLine());}public static void main(String[] args) { LineCharts fjc = new LineCharts("line chart"); fjc.pack(); RefineryUtilities.centerFrameOnScreen(fjc); fjc.setVisible(true);}// Generate a panel that displays the chart public static JPanel createDemoLine() { JFreeChart jfreechart = createChart(createDataset()); return new ChartPanel(jfreechart);}// Generate the main object of the chart JFreeChart createChart(DefaultCategoryDataset linedataset) { // Define the chart object JFreeChart chart = ChartFactory.createLineChart("First quarter sales curve", // Line chart name "Time", // Horizontal name "Sales (Millions)", // Ordinate name linedataset, // Data PlotOrientation.VERTICAL, // Horizontal display image true, // include legend true, // tooltips false // urls ); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinesVisible(true); // Whether to display grid lines plot.setBackgroundAlpha(0.3f); //Set background transparency NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); rangeAxis.setUpperMargin(0.20); rangeAxis.setLabelAngle(Math.PI / 2.0); return chart;}// Generate data public static DefaultCategoryDataset createDataset() { DefaultCategoryDataset linedataset = new DefaultCategoryDataset(); // Name of each curve String series1 = "Refrigerator"; String series2 = "color TV"; String series3 = "washing machine"; // horizontal axis name (column name) String type1 = "January"; String type2 = "February"; String type3 = "March"; linedataset.addValue(0.0, series1, type1); linedataset.addValue(4.2, series1, type2); linedataset.addValue(3.9, series1, type3); linedataset.addValue(1.0, series2, type1); linedataset.addValue(5.2, series2, type2); linedataset.addValue(7.9, series2, type3); linedataset.addValue(2.0, series3, type1); linedataset.addValue(9.2, series3, type2); linedataset.addValue(8.9, series3, type3); return linedataset;}}The operation effect is as follows:
For more Java-related content, readers who are interested in this site can view the topics: "Java Data Structure and Algorithm Tutorial", "Summary of Java Operation DOM Node Tips", "Summary of Java File and Directory Operation Tips" and "Summary of Java Cache Operation Tips"
I hope this article will be helpful to everyone's Java programming.