how to start draw line from X - Y axis at o in JFreeChart ChartFactory.createLineChart

给你一囗甜甜゛ 提交于 2020-01-01 17:09:07

问题


i am creating line chart using JFreeChart.

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;
    }

which give output..

And i want output like.


回答1:


"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



来源:https://stackoverflow.com/questions/20604462/how-to-start-draw-line-from-x-y-axis-at-o-in-jfreechart-chartfactory-createlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!