Labels truncated in a chart

Hello.

I use JasperReport to create a report with a timeSeriesChart. I used a JRChartCustomizer to customize that chart because I needed to display the different values into the chart himself and managed to do that by overriding the customize method in that way:

public void customize(JFreeChart chart, JRChart jasperChart)
{        
        XYPlot xyplot = chart.getXYPlot();            
        XYItemRenderer renderer = (XYItemRenderer) xyplot.getRenderer();            
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());    
}

The problem is that higher labels are truncated when I generate the report like shown in the image below. It is also the case for the last label of the domain axis.



Does anyone have an idea to solve that problem?

Thank you.

kromer's picture
166
Joined: Jan 27 2011 - 2:23am
Last seen: 12 years 4 months ago

15 Answers:

A possibility would be to increase the range axis upper margin with a certain amount.

Hope this helps,

sanda

 

Code:
public void customize(JFreeChart chart, JRChart jasperChart)
{        
    XYPlot xyplot = chart.getXYPlot();            
    XYItemRenderer renderer = (XYItemRenderer) xyplot.getRenderer();            
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); 
 
    xyplot.getRangeAxis().setUpperMargin(xyplot.getRangeAxis().getUpperMargin() + 0.05);    
}</td></tr></tbody></table>
shertage's picture
19776
Joined: Sep 26 2006 - 8:06pm
Last seen: 11 months 2 weeks ago

Thank your for the idea, it works !

I had also tried with this workaround:
"rangeAxis.setUpperBound(rangeAxis.getUpperBound() * 1.05);"
but I think it is a crappy solution, yours is really better.

I also used it for the domain axis and finally, the solution to the problem is the 2 lines above.

Have a nice day.

Code:
xyplot.getRangeAxis().setUpperMargin(xyplot.getRangeAxis().getUpperMargin() + 0.05);
xyplot.getDomainAxis().setUpperMargin(xyplot.getDomainAxis().getUpperMargin() + 0.05);</td></tr></tbody></table>
kromer's picture
166
Joined: Jan 27 2011 - 2:23am
Last seen: 12 years 4 months ago

Hi buddy,

this is a line chart or a XYline,  if its a XY Line, how did you do to plot date format on x.

 

My chart apear only long value , about 14 digits. and i cant mask it.

 

I apreciate any help.

danielnb's picture
244
Joined: Jan 14 2011 - 10:35am
Last seen: 7 years 11 months ago

Hi

It is a "timeSeriesChart" in the JRXML and I think that it is a XYLine JFreeChart. I customize the x labels in the JRChartCustomizer with the following code

Code:
XYPlot xyplot = chart.getXYPlot();		
DateAxis axis = (DateAxis)xyplot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));</td></tr></tbody></table>
kromer's picture
166
Joined: Jan 27 2011 - 2:23am
Last seen: 12 years 4 months ago

Another possibility is to edit the jrxml file: in the <categoryAxisFormat /> set the tickLabelMask attribute in the <axisFormat/> subelement with an appropriate date format pattern.

Hope this helps,

sanda

 

Code:
<categoryAxisFormat>
 <axisFormat tickLabelMask="MM/dd/yyyy">
 ...
 </axisFormat>
</categoryAxisFormat>


Post Edited by shertage at 01/31/2011 12:17
shertage's picture
19776
Joined: Sep 26 2006 - 8:06pm
Last seen: 11 months 2 weeks ago
Thx for the help.

Ill try both ideas, and later i tell you if it works. =)
danielnb's picture
244
Joined: Jan 14 2011 - 10:35am
Last seen: 7 years 11 months ago

Hi, thank you, timeseries really solved my main problem.

but i got another less important problem. One information of my chart, it´s a vertical line, because, its only happened one time, but has many values.
i.e: Values, 3,5,7 at 3:00 o clock.

On my XYLine chart i could see the vertical line, and with Times Series Chart, i just have a point, and the value is the latest number read. So i got a point at X:7 and Y: 3:00 o clock. Anyone have been through this ? THXX



Post Edited by danielnb at 01/31/2011 15:38
danielnb's picture
244
Joined: Jan 14 2011 - 10:35am
Last seen: 7 years 11 months ago

danielnb
Wrote:

Hi, thank you timeseries really solved my main problem.

but i got another less important problem. One information of my chart, it´s a vertical line, because, its only happened one time, but has many values.
i.e: Values, 3,5,7 at 3:00 o clock.

On my XYLine chart i could see the vertical line, and with Times Series Chart, i just have a point, and the value is the latest number read. So i got a point at X:7 and Y: 3:00 o clock. Anyone have been through this ? THXX

 

I'm not sure that I undrestand what you want but I think you should use multiple "timeSeries" in your "timeSeriesDataSet", 3 in this case: one for the 3, one for the 5 and one for the 7.

kromer's picture
166
Joined: Jan 27 2011 - 2:23am
Last seen: 12 years 4 months ago

Hi.

you been very helpfull.

I think i didnt explain very well.

 

so i atached this image.

First chart is my original chart(Times Series), you can see at top left, 2 points (not related).

On my test chart (XY Line), i used same Y variables.

 

What i want is that 2 points of first chart has the same line, that second chart have.  All the data and expressions are the same, except the kind of chart.  And these numbers are not fixed come from Java Beans.

So i dont know how many values i got and even if i knew. I think if i make multiple series, i should get multiples points one under another, and not a plain line.

I know its confused, my bad english must contribute for that.

 

Well, if anyone have some idea, i apreciate a lot. Thanks =)

 

danielnb's picture
244
Joined: Jan 14 2011 - 10:35am
Last seen: 7 years 11 months ago

Hi,

This is a limitation in the JFreeChart library: a TimeSeries does not allow multiple observations for the same x-axis value. So, if you need multiple observations (ie multiple points on the same vertical line), you have to define multiple <timeSeries/> elements in your dataset, identified by different <seriesExpression/> values.

Unfortunately, an xy plot cannot be used as time series plot.

Hope this helps,

sanda

shertage's picture
19776
Joined: Sep 26 2006 - 8:06pm
Last seen: 11 months 2 weeks ago
I hope this can be a future feature of next versions.

And Yes , all of you really helped me. Thx


danielnb's picture
244
Joined: Jan 14 2011 - 10:35am
Last seen: 7 years 11 months ago

Hi again.

 

I kinda solved this problem, i created a multi axis with 2 time series chart, the first, i put all series that i have no problem.

The second, i put the vertical data, duplicating the last bean and setting one more minute to his time.

 

I created two because they have different time period.

 

Well but i got another problem,  my left scale is duplicated and in different proportion.

 

There is anyway i take it off ?

 

I attached an image, so you know better what im talking.

 

Thx 

 

 

danielnb's picture
244
Joined: Jan 14 2011 - 10:35am
Last seen: 7 years 11 months ago

Customize the chart in a JRChartCustomizer.

HTH,

sanda

Code:
public void customize(JFreeChart chart, JRChart jrChart)
{        
    Plot mainPlot = chart.getPlot(); 
    if (mainPlot instanceof CategoryPlot)
	{
	    ((CategoryPlot)mainPlot).getRangeAxis(1).setVisible(false);
	}
	else if (mainPlot instanceof XYPlot)
	{
	    ((XYPlot)mainPlot).getRangeAxis(1).setVisible(false);
	}
}</td></tr></tbody></table>
shertage's picture
19776
Joined: Sep 26 2006 - 8:06pm
Last seen: 11 months 2 weeks ago
Perfect, I think i love you =))).


For those who might have the same situation, i only changed the value 1 to 0.
danielnb's picture
244
Joined: Jan 14 2011 - 10:35am
Last seen: 7 years 11 months ago

Wrong discussion, but can't remove post ...



Post Edited by kromer at 02/07/2012 12:22
kromer's picture
166
Joined: Jan 27 2011 - 2:23am
Last seen: 12 years 4 months ago
Feedback