x-axis overlap

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mehdi.yazdan
Posts: 2
Joined: Sun May 13, 2012 7:52 am
antibot: No, of course not.

x-axis overlap

Post by mehdi.yazdan » Sun May 13, 2012 9:02 am

In my program I have hashmap with this format <string , integer>, then the chart that will be produced with this format : it's x-axis type is string and it's y-axis is integer. These labels overlaps when data grows if i rotate label (vertically), it isn't useful. How can I reduce labels in x-axis with string type. there are solutions for integer and date type , but I couldn't find anything for string type.
Below you can see the pseudo code
Pseudo-code

Code: Select all

DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for all data( ){
dataset.setValue(yIntegrValue,category , xValue); 
}
JFreeChart  chart = ChartFactory.createLineChart(
        "profile", 
        "date",
        "values",
        dataset,
        PlotOrientation.VERTICAL, 
        true, true, false);
        
        CategoryPlot plot =  chart.getCategoryPlot();
        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
      ChartUtilities.saveChartAsJPEG(new File("F:\\chart.jpg"), chart, 1500, 800);

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: x-axis overlap

Post by John Matthews » Mon May 14, 2012 6:12 am

Cross-posted here.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: x-axis overlap

Post by paradoxoff » Mon May 14, 2012 7:20 am

Have you checked the FAQ?

mehdi.yazdan
Posts: 2
Joined: Sun May 13, 2012 7:52 am
antibot: No, of course not.

Re: x-axis overlap

Post by mehdi.yazdan » Tue May 15, 2012 1:47 pm

tanks John Matthews and paradoxoff
Another way that i used to solve this problem as follow:
I create <integer, integer>XYcahrt instead of <string,Integer> XYchart, then with SymbolAxis i changed x-axis view from integer to it's string. Now due to type of x-axis is integer with using NumberTickUnit(), overlap on x-axis can be prevented

Locked