Highlow / bar chart customization

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
GraemeK
Posts: 7
Joined: Wed Jan 04, 2017 5:16 am
antibot: No, of course not.

Highlow / bar chart customization

Post by GraemeK » Wed Jan 04, 2017 5:22 am

Hi.

Hope this is the correct place for a new question regarding the JFreechart API. And apologies if there is already an answer in the forum.

I am creating a report (using jasper reports server) that requires bars on an x axis. Each bar has a high value and a low value on the y axis. So the bars would float in the chart (similar to a high low chart). Each bar will represent a day in the month (along the x axis).

It is similar to a high low chart but simpler (no open/close, etc) and I also require a bars not lines. Eventually I would like to add a line or circle on the bar where another data point resides (so there are three values: high, low, middle).

I intend to build a jasper reports server customizer to help me do this. I was going to use a bar chart as the basis and then add a new renderer through the customizer. I would like to know if this is the correct chart to use and correct approach. I will probably start by trying to get this to work as a plain Java code first before migrating into jasper reports server.

I'm not sure if anything like this already exists, so any advice welcome.

Thanks.

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

Re: Highlow / bar chart customization

Post by John Matthews » Wed Jan 04, 2017 9:37 am

You might look at MinMaxCategoryRenderer, seen among the Statistical Charts in the demo.

GraemeK
Posts: 7
Joined: Wed Jan 04, 2017 5:16 am
antibot: No, of course not.

Re: Highlow / bar chart customization

Post by GraemeK » Wed Jan 04, 2017 5:36 pm

Thanks John,

That certainly helped. I purchased the developer's guide which also helped hugely. I would prefer a 'bar' rather than a line with bobbles at each end. I'll see if I can increase the width of the line and remove the bobbles and I think change the way the min/max/middle are rendered.

G.

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

Re: Highlow / bar chart customization

Post by John Matthews » Thu Jan 05, 2017 1:26 pm

Excellent. There's a minimal setObjectIcon() example here. I haven't tried it, but setGroupStroke() looks promising for the line thickness.

GraemeK
Posts: 7
Joined: Wed Jan 04, 2017 5:16 am
antibot: No, of course not.

Re: Highlow / bar chart customization

Post by GraemeK » Thu Jan 05, 2017 10:04 pm

Hi John,

It's really good and has expanded my knowledge of how to use this amazing API! I purchased the development guide which is worth its weight in gold. However, I would like to change the order of the rendering so that the icons are rendered on top of the line / bar (setting the stroke widens the bar width hiding the icons). Aside from re-writing the drawItem method in the MinMaxCategoryRenderer, do you know of a way to do this?

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

Re: Highlow / bar chart customization

Post by John Matthews » Fri Jan 06, 2017 12:52 am

Given a choice, I'd implement a custom Icon, rather than rewriting the drawItem() method. You may have to try both to see which looks better.

GraemeK
Posts: 7
Joined: Wed Jan 04, 2017 5:16 am
antibot: No, of course not.

Re: Highlow / bar chart customization

Post by GraemeK » Fri Jan 06, 2017 2:27 am

Thanks John. It's all a bit new to me. Will a custom icon allow me to render on top of the line? Or rather something such as a little pointy arrow to the left for example?

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

Re: Highlow / bar chart customization

Post by John Matthews » Fri Jan 06, 2017 11:58 am

I'm pretty sure the order is fixed by drawItem(). Your Icon idea sounds right, but also look a the available org.jfree.chart.annotations.

GraemeK
Posts: 7
Joined: Wed Jan 04, 2017 5:16 am
antibot: No, of course not.

Re: Highlow / bar chart customization

Post by GraemeK » Fri Jan 06, 2017 4:42 pm

Thanks for all your help and suggestions, John.

I've ended up writing my own render class because we need other additional behaviour. It's a great exercise in understanding the API and libraries and really enjoyable! I'll look at annotations!

Locked