How to increase a Barchart's minimum width for large charts

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Rex Feral
Posts: 11
Joined: Tue Feb 23, 2016 8:48 am
antibot: No, of course not.

How to increase a Barchart's minimum width for large charts

Post by Rex Feral » Wed Apr 27, 2016 9:50 am

I'm trying to make something of a signal viewer using step charts(each representing a signal over time) and bar charts (representing moments where the signal value was not as expected)

It pretty much looks like this:

Image

The problem is the barchart shrinks down to a minimum width when on large charts with max time value of over 1000 like this:

Image

Now, I'm completely fine with this as it will size back to its original shape as you zoom in, however from a GUI perspective it's not as noticeable as I intended it to be when I designed it.

Thing is I don't need much to make it better. In fact if the minimum width could be set to something thicker it would be great. Something like this would be great:

Image

But I can't find how to do it, although I searched through methods in Series, Plot, Renderer and whatnot and tried all kinds of stuff increasing Stroke width everywhere it gives me such an option, for example: barChartRenderer.setSeriesStroke(0, new BasicStroke(5.0f));

So is there a method to increase a barchart's minimum width, programatically? I don't mind hacking in a solution, inheriting a class or even duplicating one.

P.S. Asked also on StackOverflow, at first, feel free to check there for answers as well: http://stackoverflow.com/questions/3688 ... rge-charts
Last edited by Rex Feral on Tue May 03, 2016 7:06 am, edited 1 time in total.

Naxter
Posts: 45
Joined: Thu Jun 26, 2014 8:24 am
antibot: No, of course not.
Location: Germany, Aachen

Re: How to increase a Barchart's minimum width for large cha

Post by Naxter » Wed Apr 27, 2016 10:27 am

Hi,

have you thought about changing the barWidth depending the zoom factor?

By the way: if you want to have thicker bars in larger zoom outs, your "area", where your Bar belongs to will get larger too. So actually you had the bar from 48-52 for example, and with changing the bar width your area would be like from 30-70, so you change the data.

Is there maybe an other solution to "strech" the chart? I would like to know that, aswell, for my development.

Greetings

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

Re: How to increase a Barchart's minimum width for large cha

Post by John Matthews » Wed Apr 27, 2016 11:22 am

Instead of a bar chart, wy not use a Marker or Annotation on the step chart?
Last edited by John Matthews on Thu May 05, 2016 9:25 am, edited 1 time in total.

Rex Feral
Posts: 11
Joined: Tue Feb 23, 2016 8:48 am
antibot: No, of course not.

Re: How to increase a Barchart's minimum width for large cha

Post by Rex Feral » Wed Apr 27, 2016 12:53 pm

I knew about Annotation, but it's the first time I hear about Marker. I had a quick look over what it is and looks interesting, as long as I can put it on a Numerical Axis and it doesn't shrink to becoming unobservable. Thanks, I'll have to try it.

And yes I did post on StackOverflow, before considering it would be better to ask around here. Should I mention this in this post as well?

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

Re: How to increase a Barchart's minimum width for large cha

Post by John Matthews » Fri Apr 29, 2016 3:48 am

Rex Feral wrote:I did post on StackOverflow…Should I mention this in this post as well?
I think it's helpful to future readers on both sites. For readability, maybe edit your original question to include a link; I'll remove the link from my response.

Rex Feral
Posts: 11
Joined: Tue Feb 23, 2016 8:48 am
antibot: No, of course not.

Re: How to increase a Barchart's minimum width for large cha

Post by Rex Feral » Tue May 03, 2016 7:18 am

Well Annotation and Markers with labels both seem not to work really that well.

The problem being that Markers are given on a certain interval and an accurate +10/-10 interval is still shrinked to the maximum and unnoticeable on a 1000000 units axis. Also further effort required into resizing the marker range on zoom if I want to make it noticeable.

Also Labels and Annotations are a no go, because I might have a lots of them on a rather short interval and they might overlap making them unreadable, which is why I go for tooltips (that work very well on barcharts).

That said, I still consider my best bet being increasing the Barchart's minimum width, which I don't think would be that difficult, I just don't know where it's done. Must be a setStroke() somewhere in a class the barChart uses. I have to add I do not construct my bar charts with the ChartFactory, so it would not be that difficult to construct my own BarChart class and Painter class and use them in tandem.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: How to increase a Barchart's minimum width for large cha

Post by david.gilbert » Tue May 03, 2016 9:43 am

I guess you are using XYBarRenderer to draw the bars? Inside the drawItem() method you will see a lookup for the startX and endX values...these determine the widths of the bars. You could alter this code so that the bar widths are derived from the width of the dataArea (which is also passed to this method).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Rex Feral
Posts: 11
Joined: Tue Feb 23, 2016 8:48 am
antibot: No, of course not.

Re: How to increase a Barchart's minimum width for large cha

Post by Rex Feral » Wed May 04, 2016 3:24 pm

Well, this was a great step forward.

I made a custom XYBarRenderer and and overrided the drawItem() method to make the bar width larger if and where there is space on the chart (if it doesn't overlap with other barcharts).

Thanks a lot!

Locked