Overlapping Labels on X-Axis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Kiran Ponnam

Overlapping Labels on X-Axis

Post by Kiran Ponnam » Wed Nov 15, 2000 10:09 pm

Hi,
I am working on vertical BarCharts.I am trying to draw BarCharts for Countries(x-axis) and
products(y-axis).This data is comming from data_base. For four to six countries my code is
working well.Whenever I am trying to display chart for more than six countries,
it is overlapping on one another.How can I extend the x-axis to overcome this problem?
If you have any example please send me.Iam sending the code I've used:


DefaultCategoryDataSource myDataSource = new DefaultCategoryDataSource(arrSelectedProductsList,arrSelectedCountryList,data);
JFreeChart myChart = JFreeChart.createVerticalBarChart(myDataSource);
JFreeChartPanel myChartPanel = new JFreeChartPanel(myChart);
myChart.setTitle("Installs Report");

VerticalBarPlot myPlot =(VerticalBarPlot)myChart.getPlot();
Axis myHorizontalAxis = myPlot.getAxis(Plot.HORIZONTAL_AXIS);
myHorizontalAxis.setLabel("Country");

Axis myVerticalAxis = myPlot.getAxis(Plot.VERTICAL_AXIS);
myVerticalAxis.setLabel("Installs Count");

myDataSource.setSeriesNames(arrSelectedProductsList);

myDataSource.setCategories(arrSelectedCountryList);
add(myChartPanel);


Thanks in Advance,

Kiran

David Gilbert

RE: Overlapping Labels on X-Axis

Post by David Gilbert » Thu Nov 16, 2000 12:16 am

Kiran,

All I can suggest is using vertical labels on your category axis, and maybe changing to a smaller font...that will buy you a few extra categories.

The code you need to add to HorizontalCategoryAxis (this method should have been there already, but isn't):

public void setVerticalCategoryLabels(boolean flag) {
this.verticalCategoryLabels = flag;
this.notifyListeners(new com.jrefinery.chart.event.AxisChangeEvent(this));
}

Then where you have:

myHorizontalAxis.setLabel("Country");

...add...

myHorizontalAxis.setVerticalCategoryLabels(true);

Regards,

DG.

Locked