Jump to content
Changes to the Jaspersoft community edition download ×

Spider Chart - How to display values for the axis scale?


jimy

Recommended Posts

Hi,

I am using a spider chart in my reports.  The data set has 3 series.  Lets assume, for simplicity sake, that the values of each series are static.

I would like to display a value for the axis scale so that the viewer of the report can see what the values are for each series plot. 

 

NOTE: I did figure out how to implement a customizer class successfully, but going through jfreecharts API I could not see a way to turn on a value display for the axis.

I found one example of doing this by implementing a renderer, but that was using a BarChart with a Category Plot.  When I try to retrieve the category plot in my customizer class, I receive an error that SpiderWebChart plot cannot be cast to Category plot.

So, the basic question is:  How do I display a value for the axis scale for a Spider Chart.

 

Thank you!

 

Edit:

 

Error filling print... org.jfree.chart.plot.SpiderWebPlot cannot be cast to org.jfree.chart.plot.CategoryPlot
java.lang.ClassCastException: org.jfree.chart.plot.SpiderWebPlot cannot be cast to org.jfree.chart.plot.CategoryPlot
    at org.jfree.chart.JFreeChart.getCategoryPlot(JFreeChart.java:830)



Post Edited by jimy at 07/25/2011 04:31
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

Which JR version are you using?

Starting with JR 3.1.0 a spider chart component is shipped together with the JR library, and there is no more need of chart customizers here. You could take a look at the spiderchartcomponent sample in the /samples directory, to see how this component could be used.

Hope this helps,

sanda

Link to comment
Share on other sites

Hi, thanks for repsonse.

I think I am using JasperReports version 3.5.3.  I am using iReports 4.0.0 for sure, and I think 3.5.3 is the JasperReports version that shipped with it.

There certainly is a Spider Chart Component in iReports on the palette, however, the component itself does not seem to have a way to display tickmarks or values for the axis scale.

The solution seems to be to implement a custom renderer, but according to JFreeCharts API, SpiderWebPlot does not contain a getRenderer for it's Plot. 

So I probably need to refactor my customizer class a bit to extend the proper class that will allow me access to a renderer.  Sorry this last part is still a bit foggy to me as I am still trying to fully understand JFreeCharts implementation of a SpiderWebPlot.  If there was a way to cast a CategoryPlot to a SpiderWebPlot I would be able to access a renderer that way, but I don't think that cast is supported.

 

Note: My customizer class currently extends AbstractChartCustomizer.

Any tips on a different class I could extend that would give me access to a renderer.  Overriding the draw() method seems to be another possible solution.  Any tips on how to proceed are greatly appreciated.



Post Edited by jimy at 07/26/2011 18:55
Link to comment
Share on other sites

Hi Jimy,

Things are a little bit different in JR for the spider chart element, because it was implemented as a JR component. The related customize() method should now accept a ChartComponent instead of a JRChart object.
This is why the customizer class should implement the new net.sf.jasperreports.components.charts.ChartCustomizer interface which exposes the

public void customize(JFreeChart chart, ChartComponent chartComponent);

method. More, your chart customizer class may extend the net.sf.jasperreports.components.charts.AbstractChartCustomizer class.
Now, in the customize() method you can acces the SpiderWebPlot element in the generated spider chart like below.
And be aware that the SpiderWebPlot is not a CategoryPlot.

Hope this helps,
sanda

Code:


Post Edited by shertage at 07/27/2011 13:49
Link to comment
Share on other sites

Hi Sanda,  thanks again for your reply.

Yes, I have code very similar to your reply, that was not a problem - but again thanks for posting it.  The problem is that I cannot figure out how to display the scale for the chart axis.  It just doesn't seem to exist, or I have overlooked it somewhere.  Here's an attachment of my current chart to help explain what is missing.

If you open the image I've attached, you can see that the chart has an axis, but no scale.  I need a scale to show users what they are looking at in terms of values on the axis.

Any tips on how to achieve this?



Post Edited by jimy at 07/27/2011 16:17
Link to comment
Share on other sites

Hi Jimy,

Now I see :). It was my misunderstanding, sorry. In my previous post I tried to ensure that the correct ChartCustomizer interface was implemented, because this discussion started with the BarChart customizer example, which indeed uses a CategoryPlot with its related renderer, but extends "the other" ChartCustomizer.

I took a look at the SpiderWebPlot capabilities, and in my opinion for the moment there is no easy way to get a scale on axis. It is not impossible, but requires some amount of work. Because of the following steps:

  • extend the SpiderWebPlot class (let's name it CustomSpiderWebPlot for instance) and override the draw()/drawLabel() methods;
  • then, because there is no setPlot() method in the JFreeChart class, you cannot use a chart customizer to simply set the CustomSpiderWebPlot object in your generated JFreeChart. A lot of additional work will be necessary. Practically you should make your own spiderchart component based on the JR existing APIs, and extend the net.sf.jasperreports.components.spiderchart.SpiderChartRendererEvaluator (--> CustomSpiderChartRendererEvaluator) in order to instantiate the JFreeChart with a CustomSpiderWebPlot object. Then you have to ensure that the CustomSpiderChartRendererEvaluator is properly called by the other APIs, and so on...


Anyway, doing this way, a chart customizer is no more necessary.

I have no other ideas regarding this problem.

Sincerely hope this helps,
sanda

Link to comment
Share on other sites

Hi sanda,

thanks again for your reply.  I had in fact already extended SpiderWebPlot in my customizer class.  Interestingly enough, the draw() and drawRadarPoly() methods which I had overridden in my custom class never get called. 

Is this because they are instance methods and the instance making the call to draw() is the superclass?  I thought that when JasperReports instantiated a custom chart class it would set the chart reference to the custom class.

I realize this discussion may be getting old :)   but if you could explain why my overridden methods of SpiderWebPlot are never called within my custom class I would really appreciate it.  Maybe it is simply for the reason I stated above, not sure.

 

Thanks so Much!



Post Edited by jimy at 07/29/2011 01:29
Link to comment
Share on other sites

Hi jimy,

It's hard to say why aren't called the overriden methods without seeing the code. In this particular case, a customized SpiderWebPlot is not enough to solve this kind of problem, this plot has to be integrated in a customized spider chart component, replacing the old SpiderWebPlot. So, if a single step in the integration process gets missed, the customized SpiderWebPlot may be bypassed.
If you could post a sample with the customized component here, perhaps we will be able to find out more about the issue.
 
For an elegant and reusable solution, I think that a plot setter method in the JFreeChart class is definitely necessary, in order to make the plot customization a really powerful tool. With an available setPlot() method, we only need a chart customizer to replace the default SpiderWebPlot object in the generated JFreeChart with the customized one, and there is no more necessary to override the entire component.

Maybe a good and useful idea would be to post a feature request for the plot setter here.

Best regards,
sanda

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...