Hi All,
I need to add 2 columns to the chat in x axis by grouping using database . I am new to Jfree chart . Please help to add two columns in x axis by grouping .
my query will display data like the below table ... i need to do group by in chart for business and status columns in x axis & count should display in y axis .
business status count
a test1 23
a test2 45
b test1 66
b test3 70
c test2 82
c test3 99
d test4 100
Pivot table
Row Labels Sum of count
a 68
test1 23
test2 45
b 136
test1 66
test3 70
c 181
test2 82
test3 99
d 100
test4 100
Grand Total 485
How to add two columns to the chart
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: How to add two columns to the chart
Something like this:
Code: Select all
public class SimpleBarChart {
public static void main(String[] args) {
DefaultCategoryDataset dcd = new DefaultCategoryDataset();
dcd.addValue(23, "A", "Test1");
dcd.addValue(10, "A", "Test2");
dcd.addValue(66, "B", "Test1");
dcd.addValue(70, "B", "Test3");
dcd.addValue(82, "C", "Test2");
dcd.addValue(99, "C", "Test3");
dcd.addValue(100, "D", "Test4");
BarRenderer br = new BarRenderer();
CategoryPlot plot = new CategoryPlot(dcd, new CategoryAxis("Category"), new NumberAxis("Values"), br);
JFreeChart chart = new JFreeChart(plot);
ChartPanel cp = new ChartPanel(chart);
JFrame f = new JFrame("Bar Chart");
f.getContentPane().add(cp);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
Re: How to add two columns to the chart
Thanks For your reply ...these values are coming from database .. i need to connect with database and prepare the chart ... Please help me on that ... I not need of DefaultCategoryDataset() instead i need to connect to database and display chart
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: How to add two columns to the chart
.msksanthu wrote: I do not need DefaultCategoryDataset; instead, I need to connect to database and display chart
You may want to look at JDBCCategoryDataset, which is "A CategoryDataset implementation over a database JDBC result set." Although off-topic, this related example may offer some insight in formulating your query.
Re: How to add two columns to the chart
Thanks for your information