user1622242
user1622242

Reputation: 11

Bar JFree Charts y-axis

I want to display Bar chart using jfree charts. I am able to display string data on y-axis like A 0,B 100 on y-axis but the bars are displaying long.the bars are not displaying in proper format. how to encode y-values as integers in my dataset while still i have to display string data displayed above in that format?

Upvotes: 1

Views: 2623

Answers (1)

GrahamA
GrahamA

Reputation: 5923

The SymbolAxis needs a for each of the numberic values so you will need to provide 101 values (0 - 100) rather then the 11 in your code

Try replacing

SymbolAxis rangeAxis=new SymbolAxis("", new String[] {"Poor    0", "10","20", "30", "40", "Avg.     50","60","70","80","90","Best   100"});
plot.setRangeAxis(rangeAxis);

with

//Provide a new Symbol Axis
String[] grade =  new String[101];
for (int i = 0 ; i < grade.length ; i ++){
    grade[i] = Integer.toString(i);
}
grade[0] = "Poor    0";
grade[100] = "Best   100";
grade[50] = "Avg.   50";
SymbolAxis rangeAxis = new SymbolAxis("", grade);
rangeAxis.setTickUnit(new NumberTickUnit(10));
rangeAxis.setAutoRange(false);
rangeAxis.setRange(0, 100);
plot.setRangeAxis(rangeAxis);

Use SymbolAxis#setTickUnit() to control the interval between tick marks and you shold get a chart line this

enter image description here

Upvotes: 3

Related Questions