研究了JFreeChart一个月了, 按照官方提供的demo一些简单的图表到是可以实现了. 但有一个问题一直困扰着我, 在做一个时序图, X轴是日期轴, 从1号到30/31号, Y轴表示每一天的出货量. 数据从数据库中获得大体sql应该是
select date, count(*) c from where date like '...' t group by date. 结果集就包含日期与数量两列. 然后使用JFreeChart进行绘制, 发现如果检索出来的数据不是连续的(中间有几天没记录), 或者只有半个月的(或更少), 这个时候X轴上的日期显示就乱套了, 不知道是为什么, 请高手指教.... 

解决方案 »

  1.   

    源码实例,请参考,若有帮助麻烦给下分,谢谢!package JFreeChartDemo;import org.jfree.chart.ChartFrame;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.ChartFactory;
    import org.jfree.data.category.CategoryDataset;
    import org.jfree.data.category.DefaultCategoryDataset;
    import org.jfree.chart.axis.CategoryAxis;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.plot.CategoryPlot;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.title.TextTitle;import java.awt.Font;public class JFreeCharTest1 { /**
     * @param args
     */
    public static CategoryDataset CreateCategory(){
    DefaultCategoryDataset cds=new DefaultCategoryDataset();
    cds.setValue(10,"开发人员","beyondsoft");
    cds.setValue(18,"初级开发人员","beyondsoft");
    cds.setValue(22,"高级开发人员","beyondsoft");
    cds.setValue(26,"测试人员","hisoft");
    cds.setValue(33,"黑盒测试人员","hisoft");
    cds.setValue(44,"白盒测试人员","hisoft");
    return  cds;
    }

    public static JFreeChart getfreechart(){
    JFreeChart chart=ChartFactory.createBarChart("IT市场形式分析","公司名","人数",CreateCategory(), PlotOrientation.VERTICAL, true, true, true);
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();  
    // 设置图表的纵轴和横轴org.jfree.chart.axis.CategoryAxis
            NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();    
            CategoryAxis domainAxis = categoryplot.getDomainAxis();    
            TextTitle textTitle = chart.getTitle();
            textTitle.setFont(new Font("黑体", Font.PLAIN, 20));
            domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
            domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
            numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
            numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
            chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
    return chart;
    }

    public static void main(String[] args) {

    ChartFrame frame=new ChartFrame("IT市场形式分析",getfreechart());
    frame.pack();
    frame.setVisible(true);
    }
    }
      

  2.   

    例子2:package JFreeChartDemo;import org.jfree.chart.ChartFrame;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.plot.PiePlot;
    import org.jfree.data.general.DefaultPieDataset;import java.awt.Font;
    import java.util.Locale;public class JFreeChartTest { public static void main(String[] args) {
    DefaultPieDataset dpd = new DefaultPieDataset();
    dpd.setValue("开发人员", 10.00);
    dpd.setValue("测试人员", 23.00);
    dpd.setValue("PM", 3);
    dpd.setValue("finance", 30);
    dpd.setValue("HR", 48); Locale locale = Locale.CHINA;
    JFreeChart chart = ChartFactory.createPieChart3D("数据", dpd, true, true,
    locale);
    chart.getTitle().setFont(new Font("黑体", Font.BOLD, 20));// 设置标题字体
    PiePlot piePlot = (PiePlot) chart.getPlot();// 获取图表区域对象
    piePlot.setLabelFont(new Font("黑体", Font.BOLD, 10));
    chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 10));
    ChartFrame chartframe = new ChartFrame("数据", chart);
    chartframe.pack();
    chartframe.setVisible(true);
    }
    }