0

In bar chart, the data is dynamic from DB at run time. My problem is that-

  1. If data set is large chart get shrink ed, it's not clearly visible .
  2. If data set having less number of data's(less no. of record sets) then the chart's bars width are big. How can I control it?

    chartPanel = new ChartPanel(test());
    jPanel1.add(chartPanel, BorderLayout.CENTER);
    
    
    public static JFreeChart test() {
        String query = "SELECT num1,num2 from test1 ;
        JFreeChart cha;
        try {
            JDBCCategoryDataset dataset = new JDBCCategoryDataset("jdbc:mysql://localhost:3306/db", "com.mysql.jdbc.Driver", "root", "");
            dataset.executeQuery(query);
            cha = ChartFactory.createBarChart3D("xxxx", "xxx", "xxx", dataset, PlotOrientation.VERTICAL, true, true, false);
    
        } catch (Exception e) {
            System.out.println(e);
        }
        return cha;
    }
    

Is there a way to adjust the width of the bars in a Barchart.

SOLVED Width of the bar in Jfreechart

Community
  • 1
  • 1
Mukthi
  • 561
  • 4
  • 13
  • 35
  • We now know that you are selecting two (presumably) numeric attributes from an unknown relation named `test` in an inaccessible MySQL database. What request in the first comment remains unclear? – trashgod Jan 17 '12 at 15:51
  • If this query returns large number of records then the chart is not clearly showing or it returns small number of records ,chart displayed with big sized bar's. – Mukthi Jan 18 '12 at 04:03

1 Answers1

0

If you can try fixing the Maximum number of bars your graph can show.

Because any how if you manage to fix the width of bars but if the number of bars will be large then the bars will overlap.

So fix the maximum number of bars your graph can show.

gprathour
  • 14,813
  • 5
  • 66
  • 90
  • Graph wont show more than 30 bar's.I controlled by the filter but if it has to show one or two bar then the width is too high. – Mukthi Jan 30 '12 at 07:07
  • @Mukthi You will have to use bar rendere 3D check out its doc http://www.jfree.org/jfreechart/api/javadoc/index.html and look for method drawItem if it helps you. – gprathour Jan 30 '12 at 07:19
  • Category plot and XY plot can only use the render.Its simple bar chart, how can i do it? – Mukthi Jan 30 '12 at 07:23