Hi,
I'm using JFreeChart v0.9.6 and would like to set the labels vertically on a vertical bar chart.
The methods setVerticalValueLabels on the CategoryPlot don't seem to have any effect on the position of labels.
Is there another method which I can use to set the label orientation?
Thanks,
Christophe.
Label orientation on vertical bar chart
Re: Label orientation on vertical bar chart
Hi,
I had these lines commented in my code... One or another worked in a 0.9.4 installation. Just try the second if, as you said, the first one doesn't.
1. chart.getCategoryPlot().setVerticalLabels(true);
2. CategoryPlot plot = chart.getCategoryPlot();
HorizontalCategoryAxis hca = (HorizontalCategoryAxis) plot.getDomainAxis();
hca.setVerticalCategoryLabels(true);
Jordi G. March
I had these lines commented in my code... One or another worked in a 0.9.4 installation. Just try the second if, as you said, the first one doesn't.
1. chart.getCategoryPlot().setVerticalLabels(true);
2. CategoryPlot plot = chart.getCategoryPlot();
HorizontalCategoryAxis hca = (HorizontalCategoryAxis) plot.getDomainAxis();
hca.setVerticalCategoryLabels(true);
Jordi G. March
Re: Label orientation on vertical bar chart
Hi Jordi
It's not the axis labels but the value labels.
I have 3 values (3 series) per month and I want to draw for each vertical bar the value. I use the following code :
CategoryPlot plot = schart.getCategoryPlot();
plot.setValueLabelsVisible(true);
plot.setVerticalValueLabels(true);
But the orientation of the value labels is always horizontal and overlap the bar.
Christophe Clement
It's not the axis labels but the value labels.
I have 3 values (3 series) per month and I want to draw for each vertical bar the value. I use the following code :
CategoryPlot plot = schart.getCategoryPlot();
plot.setValueLabelsVisible(true);
plot.setVerticalValueLabels(true);
But the orientation of the value labels is always horizontal and overlap the bar.
Christophe Clement
Re: Label orientation on vertical bar chart
Hello Christopher, and thanks for the clarification. You solved me another question I just asked before.
Unfortunately, I've seen setVerticalValueLabels in 0.9.6 but not in 0.9.4, and no tricks whatsoever.
I'll stay tuned for any responses though, it's pretty interesting to me too.
Thanks again Christopher,
Jordi
Unfortunately, I've seen setVerticalValueLabels in 0.9.6 but not in 0.9.4, and no tricks whatsoever.
I'll stay tuned for any responses though, it's pretty interesting to me too.
Thanks again Christopher,
Jordi
Re: Label orientation on vertical bar chart
I'll try to explain the two separate things:
(1) On a horizontal axis, you can set the tick labels to a 'vertical' orientation, usually so that you can fit more labels into the available space. For example:
CategoryPlot plot = myChart.getCategoryPlot();
HorizontalCategoryAxis axis = (HorizontalCategoryAxis) plot.getDomainAxis();
axis.setVerticalTickLabels(true);
// or you can use the synonymous setVerticalCategoryLabels(true)
These are the labels along the category axis.
(2) There is an option (contributed by other developers) to display values as text near each data point (for example, above each bar in a bar chart). You can switch this on/off using the setValueLabelsVisible(...) method in the CategoryPlot class (I'm considering moving this and related methods to the renderer, but that is another issue). *Some* renderers respect this setting, others don't yet...it is an incomplete implementation.
If the value labels are visible, you can have them displayed with a 'vertical' orientation by using the setVerticalValueLabels(...) method in the CategoryPlot class. Again, *some* renderers will respect this setting, others will ignore it (an incomplete implementation).
I will work on finishing off the code in (2) before JFreeChart 1.0.0 is released, but it isn't a feature that I use in my daily work, so it isn't top of my priority list. If someone else wants to tidy up the code, contributions will be gratefully accepted.
Regards,
Dave Gilbert
(1) On a horizontal axis, you can set the tick labels to a 'vertical' orientation, usually so that you can fit more labels into the available space. For example:
CategoryPlot plot = myChart.getCategoryPlot();
HorizontalCategoryAxis axis = (HorizontalCategoryAxis) plot.getDomainAxis();
axis.setVerticalTickLabels(true);
// or you can use the synonymous setVerticalCategoryLabels(true)
These are the labels along the category axis.
(2) There is an option (contributed by other developers) to display values as text near each data point (for example, above each bar in a bar chart). You can switch this on/off using the setValueLabelsVisible(...) method in the CategoryPlot class (I'm considering moving this and related methods to the renderer, but that is another issue). *Some* renderers respect this setting, others don't yet...it is an incomplete implementation.
If the value labels are visible, you can have them displayed with a 'vertical' orientation by using the setVerticalValueLabels(...) method in the CategoryPlot class. Again, *some* renderers will respect this setting, others will ignore it (an incomplete implementation).
I will work on finishing off the code in (2) before JFreeChart 1.0.0 is released, but it isn't a feature that I use in my daily work, so it isn't top of my priority list. If someone else wants to tidy up the code, contributions will be gratefully accepted.
Regards,
Dave Gilbert