如何在JFreeChart ChartFactory.createLineChart中从o开始在X-Y轴上绘制线条 [英] how to start draw line from X - Y axis at o in JFreeChart ChartFactory.createLineChart

查看:304
本文介绍了如何在JFreeChart ChartFactory.createLineChart中从o开始在X-Y轴上绘制线条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JFreeChart 创建折线图。

i am creating line chart using JFreeChart.

折线图正确绘制但我想从点开始0.我该怎么做?

Line chart draw properly but i want to start at point 0. how can i do that?

public void lineChart()
{
         CategoryDataset ds=createDataset2();
         chart2=ChartFactory.createLineChart("Bar Chart", "OPD Number", "Weight", ds,PlotOrientation.VERTICAL,true,true,false);

         ChartPanel cp = new ChartPanel(chart2);
         jp.add(cp);                     //jp is JPanel 
    }
    public CategoryDataset createDataset2() 
    {
        final DefaultCategoryDataset dataset= new DefaultCategoryDataset();
        final String series1 = "Type1";
        OPDDetailBean ob=new OPDDetailBean();
        ArrayList<OPDDetailBean> aob=new ArrayList<OPDDetailBean>();
        aob=ob.searchOPDDetails("5");
        for(int i=0;i<aob.size();i++)
        {
            dataset.addValue(Integer.parseInt(aob.get(i).getWeight()), series1, ""+(i+1));    
        }
        return dataset;
    }

给出输出..

我希望输出像。

推荐答案

1,2,3,4和5是您示例中的类别。您没有类别0,因此不能有一行。如果希望0位于绘图的左边界,请添加类别0并调整轴边距。或者可能更好:使用来自ChartFactory的XYPlot和相应的方法,如 createXYLineChart()

"1", "2", "3", "4" and "5" are categories in your example. You don't have a category "0", so there cannot be a line to it. Either add a category "0" and adapt the axis-margin if you want 0 to be on the left border of the plot. Or probably better: use an XYPlot and corresponding methodes from ChartFactory like createXYLineChart().

hth,

- martin

hth,
- martin

这篇关于如何在JFreeChart ChartFactory.createLineChart中从o开始在X-Y轴上绘制线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆