|
bargap and x axis positioning on bar graphs |
Posted by duncan berriman on Jan-21-2004 08:21 |
|
Hi,
I have a bar graph which depicts data at 15 minute intervals over 24 hours.
I tried a bargap of zero and every 4th bar I ended with some white space between the bars. Any reason for this and is there anything I can do about it as it looks odd.
Secondly the bar is always drawn with the middle of the bar over the x axis point.
So for instance data for between 00:00 and 00:15 ends up centered over 00:00. To accomdate this extra space is added before 00:00. This happens for every bar so when it gets to the data between 23:45 and 23:59 it ends up with white space at the end. I know most of the extra space can be got rid of using setIdent(false);
My question is, is it possible to force it to draw the bar to the right of the x axis point so that it actually depicts the correct information, eg. data covering 00:00 thru 00:15 is shown over this point on the scale. I've looked at the manual and on here but can find no reference.
Ideally something like layer->Align(Right);
Thanks
Duncan
Thanks
Duncan Berriman |
Re: bargap and x axis positioning on bar graphs |
Posted by duncan berriman on Jan-21-2004 08:35 |
|
PS. I just noticed the white gap between bars is every 6 then every 7 bars not as reported 4.
Also having looked at the manuals again I can see why your examples in the manual based over 24 hour periods all appear 'correct'. Its because you have 25 values not 24.
Cheers again
Duncan |
Re: bargap and x axis positioning on bar graphs |
Posted by Peter Kwan on Jan-22-2004 05:42 |
|
Hi duncan,
If you want the ticks and labels to be in between the bars, you may use the code below to configrue the x-axis
Call c.xAxis().setIndent(0)
Call c.xAxis().setLinearScale(-0.5, Ubound(labelsArray) - 0.5, labelsArray)
Note that in your labelling method, the number of labels must be 1 more than the number of data points.
Regards
Peter Kwan |
Re: bargap and x axis positioning on bar graphs |
Posted by duncan berriman on Jan-22-2004 23:09 |
|
Peter,
Thanks once again for your excellent support. That has resolved the problem with the x axis however I still have a problem with white space. I have attached an example.
Any ideas.
Thanks
Duncan Berriman
|
Re: bargap and x axis positioning on bar graphs |
Posted by Peter Kwan on Jan-22-2004 23:51 |
|
Hi duncan,
I think you are referring to the problem that sometimes there is a gap of 1 pixel between two bars, while sometimes there is no gap. The reason is because it is impossible for ChartDirector to keep every bar of the same width, and also make sure there is no space between any two bars. It occurs when the width is not divisible by the number of bars. By default, ChartDirector will make sure every bar is of the same width, thus sometimes there may be a extra 1 pixel spacing required.
Another method is to make sure there is no spacing, but then the width of the bars are not constant. Some bars will be wider by 1 pixel. This is usually not noticible. To choose this method, use the special constant TouchBar as the bar gap. For example (the following is in PHP syntax):
$barLayer->setBarGap(TouchBar);
Regards
Peter Kwan |
Re: bargap and x axis positioning on bar graphs |
Posted by duncan berriman on Feb-04-2004 06:14 |
|
Thanks Peter,
That makes sense.
I will give that a try or programatically make sure the width of the graph is divisible by the number of bars.
Thanks again
Duncan |
Re: bargap and x axis positioning on bar graphs |
Posted by Duncan Berriman on Feb-03-2011 20:54 |
|
Hi Peter,
V5 upgrade part2. Sorry to trouble you again, hopefully this is actually an issue with ChartDirector and not a compiler issue.
The problem above has come back, no code changes to our system and as can be seen from the debug info in the chart the width of the colums is the same so there should be no white space.
480 (width) /96 (values) = 5 (bar width).
I can't find any reason for this in our code nor in the release notes for 4.1/5.0/5.1 unless its something to do with tick increment?
bargap is set to zero.
Thanks
Duncan
|
Re: bargap and x axis positioning on bar graphs |
Posted by Peter Kwan on Feb-04-2011 00:15 |
|
Hi Duncan,
I have checked your chart carefully. For your case, all the bars are in fact equally wide and exactly 5 pixels wide.
However, the center of the bars are not equally spaced. That is why the bars may not exactly touch each others.
To plot the bars, ChartDirector first computes the center of the bars. Then it plot the bars according to the bar width. I think in your case, the center of the bars are at coordinates like 77.5, 82.5, 87.5, 92.5, .... As it is at exactly the center of two integers, it is sometimes round up, and sometimes down, so the center becomes 78, 83, 87, 93, ..., which is not evenly spaced. The distance between two bars can be from 4 to 6 pixels. This causes the problem you see.
To solve the above problem, ChartDirector has a special constant Chart::TouchBar, which can be used to ensure there is no gap between bars. If Chart::TouchBar is used, an alternative method would be used to draw the bars, so that there is no gap, and the adjacent bars will share the same border. (In your current case, adjacent bars will be separated by 2 borders, each belonging to one bar.) The code is like:
layer->setBarGap(Chart::TouchBar);
Hope this can help.
Regards
Peter Kwan |
Re: bargap and x axis positioning on bar graphs |
Posted by Duncan Berriman on Feb-04-2011 00:25 |
|
Hi Peter,
This only fails on latest version.
All works fine on previous version with touchbar set to zero.
As per the original problem years ago we changed the size to make sure the bars fits and the graph works fine.
Its only the upgraded version that exhibits this behaviour.
old version works fine.
Any other ideas?
|
Re: bargap and x axis positioning on bar graphs |
Posted by Duncan Berriman on Feb-04-2011 00:55 |
|
Just to confirm
bargap=0;
layer->setBarGap(bargap);
Changing to TouchBar means no gaps but it looks a mess visually.
layer->setBarGap(TouchBar);
The bargap=0 method and making sure the width and number of columns resulted in a round figure fixed this before. |
Re: bargap and x axis positioning on bar graphs |
Posted by Peter Kwan on Feb-04-2011 23:26 |
|
Hi Duncan,
You are absolutely correct that using setBarGap is like:
layer->setBarGap(Chart::TouchBar);
In the past, we had suggested people to set bar gap to 0 and to use a plot area width that was exactly divisible by the number of bars. However, we found that it did not always work. Whereas the bar width is an exact integer, the bar position is not necessarily an exact integer. (It is only an exactly integer if the bar width is an even number, but a half-integer if the bar width is an odd number.)
It so happens that in your case, in a 32-bit machine, the rounding always result in the numbers rounded up, while in a 64-bit machine, it is sometimes rounded up and sometimes rounded down.
I think TouchBar should be a solution as it is invented for this purpose. If the chart looks like a mess, would you mind to include the chart image created using TouchBar? I will see if it is normal or abnormal. If it is abnormal, I would try to guess the cause of the problem. You may also refer to the sample charts that are created using TouchBar (eg. the Dual Horizontal Bar Chart sample code) to see if your chart looks like one of them.
Another alternative I can think of is to introduce a small bias in the coordinates so that the numebrs are always rounded up. You may try something like:
layer->setXData(0.00001, 95.00001);
Please let me know if the above can solve the problem.
Regards
Peter Kwan |
Re: bargap and x axis positioning on bar graphs |
Posted by Duncan Berriman on Feb-04-2011 23:43 |
|
Hi Peter,
Thanks for the help. This is a touchbar graph produced with ChartDirector V4.1 64 bit. Just thought I'd see if it was version specific, its not, so it looks like it is a 64 bit issue.
Its not as pretty as what we had.
|
Re: bargap and x axis positioning on bar graphs |
Posted by Duncan Berriman on Feb-04-2011 23:45 |
|
32 bit for comparison (no touchbar).
|
Re: bargap and x axis positioning on bar graphs |
Posted by Duncan Berriman on Feb-04-2011 23:57 |
|
I tried layer->setXData(0.00001, 95.00001); but that makes the problem worse.
I also tried setting the width so that the bar width was even (4 or 6) and that fixes the issue, the only problem then is that the graph is too large or too small for my needs.
So it does indeed seem to be an issue with odd bar widths.
I still don't quite understand why it causes an issue in the 64 bit version.
Sounds like we could do with a fix to tell it what rounding to use, decimal places or something. |
Re: bargap and x axis positioning on bar graphs |
Posted by Peter Kwan on Feb-06-2011 00:22 |
|
Hi Duncan,
The chart created by using TouchBar seems normal. I do see some color distortion (eg. the blue bars seem alternatively brighter and darker), but it is likely to be due to normal JPEG color distortion. I am not sure if you are actually using JPEG, or if it is just a screen shot that happens to be saved in JPEG. If your actual chart is displayed on screen as DIB/BMP, or are using PNG, then such distortion should not exist.
(The JPEG distortion is more serious in the TouchBar chart because that chart is sharper - the black border between 2 bars is a one pixel wide - whereas in the original chart it is two pixels wide.)
The cause of the problem is because of the following two factors:
(a) Although the bar width is an exact integer, the bar position is not. You can see this if you consider the "ticks". I am not sure how you put the ticks in between the bars (by default the ticks should be center aligned to the bar), but one way of doing so is to shift the ticks by 0.5 unit (eg. using setTickOffset). For your case, 0.5 unit is 2.5 pixels. If the ticks are now at integer coordinates, the center of the bars must be at non-integer coordinates (as they are 2.5 pixels apart).
(b) Due to how the Intel CPU works, rounding a floating point computation result that is near 0.5 is effectively random. It can be affected by compiler brand, version, operating system, or other programs happen to be running on the computer, and by 32-bit/64-bit. It is hard to predict the exact rounding as it is not completely deterministic.
It so happens the number is rounded one way in the 32-bit edition, and another way in the 64-bit edition. It is hard to say which one is more correct. It is also hard to know if the problem is due to 32-bit/64-bit. or due to the different compiler versions used to compile the 32-bit and 64-bit editions, or due to the OS or other factors.
My opinion is that the TouchBar method should work good enough (if you are not using JPEG so there is no JPEG distortion). However, if you prefer the original style, we would need to find a way to modify the shifting, so that it is not 2.5 pixels, but something like 2.6 pixels, so that the numbers are always rounded up.
Regards
Peter Kwan |
Re: bargap and x axis positioning on bar graphs |
Posted by Duncan Berriman on Feb-10-2011 00:37 |
|
Hi Peter,
Think I may have solved it with your ideas in last post.
We offer the graphs in png, gif or jpg (customer choice) so eventual format is outside our control.
However I looked at your idea of offsets.
Currently we use.
c->xAxis()->setLinearScale(-0.5,args-0.5, StringArray(labels2, args+1));
after a bit of playing I settled on
c->xAxis()->setLinearScale(-0.4,args-0.4, StringArray(labels2, args+1));
which seems to solve the issue as can be seen below.
Duncan
|
Re: bargap and x axis positioning on bar graphs |
Posted by Duncan Berriman on Feb-10-2011 00:39 |
|
Sorry wrong graph - correct one below.
|
Re: bargap and x axis positioning on bar graphs |
Posted by Peter Kwan on Feb-10-2011 03:37 |
|
Hi Duncan,
Thanks for the information on how to solve the problem.
Sorry for suggesting the incorrect solutions in my previous message. realized from the start that the x-axis ticks and labels are not in their usual positions, but I had mistaken on how it was achieved. I thought the x-axis is configured using Axis.setLabels with Axis.setLabelOffset and Axis.setTickOffset. Now I read this thread again starting from the first post in 2004, and realize that the setLinearScale code was suggested by me. (The setLabelOffset and setTickOffset was not invented at that time.)
Again, thanks again for the information on how to solve the problem.
Regards
Peter Kwan |
Re: bargap and x axis positioning on bar graphs |
Posted by Duncan Berriman on Feb-10-2011 05:13 |
|
Hi Peter,
No issues at all, As you say the whole system of graphs we use was developed with your fantastic support and input and your help over the last few days has led us to the solution.
I only wish everyone we dealt with was as responsive and helpful.
Many thanks again for fantatic service.
I'll email you re upgrade licences soon.
Duncan |
|