Monirul Islam
Monirul Islam

Reputation: 935

Need to set column label dynamically in JFreeChart

Please see attached screeshot. i want to set label dynamically for X axis. Currently is says Test1,Test2,Test3,Test4..if i want to set a category array dynamically how can i do that? i mean i want to set category like House Expense,Office Rent, Food...etc. Here is screenshot and code.

http://www.screencast.com/t/lak24QQvfM3

Here is the bar chart code. see line between 86-90.

http://pastebin.com/MXq4zTbw

Can anyone help me with that? If anything is not clear please ask.

Thanks in advance.

Upvotes: 1

Views: 171

Answers (1)

GrahamA
GrahamA

Reputation: 5923

Replace your createDataset() with something like this:

private static CategoryDataset createDataset() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(40.0,"Expediture","House");
    dataset.addValue(30.0,"Expediture","Office Rent");
    dataset.addValue(-20.5,"Expediture","Food");
    dataset.addValue(30.0,"Expediture","Other");
    dataset.addValue(6.0,"Expediture","Etc");
    return dataset;
}

enter image description here

Upvotes: 1

Related Questions