X-axis labeling errors

Get help and support using chartsEngine for LiveCode.

Moderators: heatherlaine, BvG

Post Reply
kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

X-axis labeling errors

Post by kwinkler » Sat Dec 04, 2010 5:16 am

I have a simple plot with data ranging from 0-360 on the X-axis. If the chart width is set to 400, then the labels appear at 0.0, 90.6, 181.2, 271.8 and 360.0. If the chart width is set to 800, then the labels appear at 0.0, 90.3, 180.5, 270.8 and 360.0. Better, but not good enough. Of course, the labels should appear at 0, 90, 180, 270, and 360.

Have I overlooked something obvious? I have only checked this with stacked line charts. Versions 1.08 and 1.1 of ChartEngine both show the same behavior.

kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

Re: X-axis labeling errors

Post by kwinkler » Sun Dec 05, 2010 3:59 am

further info-

The labeling problem described above occurs when I use the following command-

set the charts["gridXNumberFormat"] of grp "myChart" to "0.0",

or indeed, if I use no formatting command at all.

However, if I increase the number of digits to five or more after the decimal point, such as-

set the charts["gridXNumberFormat"] of grp "myChart" to "0.00000"

then the labels are correct. But then the labels appear as 90.00000, which is not what I need.

kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

Re: X-axis labeling errors

Post by kwinkler » Sun Dec 05, 2010 4:17 am

Here is an example of what I have been describing. Note the labels on the x-axis.
Screen shot 2010-12-04 at 10.13.59 PM.png
Screen shot 2010-12-04 at 10.13.59 PM.png (55.86 KiB) Viewed 4043 times

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: X-axis labeling errors

Post by malte » Sun Dec 05, 2010 10:04 am

Hi,

I will take a look on monday when I am back in the office.

In the meantime, could you please post the script that creates your chart, along with the dataset you are using?

Thanks a lot,

Malte

kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

Re: X-axis labeling errors

Post by kwinkler » Sun Dec 05, 2010 10:13 pm

Hi Malte,

Apparently I am not allowed to attach the .livecode file, so I have attached the text of the card script that creates the chart with an incorrectly labeled X-axis. Another example can be found on the third page of your documentation (chartenginedocs.pdf), where the X-axis is incorrectly labeled 2.51 instead of 2.5.

In another thread I commented on a problem autoscaling the Y-axis. In the attached code, Section A is my workaround to set the maximum of the Y-axis. Section B is the code I would rather use, but trying to set charts["maxY"] creates the strange autoscaling problem I described in the other thread. You should be able to reproduce this by commenting out Section A, and uncommenting Section B.

The complete project file SinePlotter.livecode can be downloaded from https://public.me.com/kwinkler.

Thanks for looking into this,

Ken



on runModel
global gFreq, gAmp
local theData, var1,var2, theDataB, tmax, tmaxY
put 0 into tmax
put 0 into theData

repeat with i = 0 to 360
put 10*abs(sin(i * pi /180 * gFreq)) into var1
put gAmp*abs(sin(i*pi/180*gFreq*6)) into var2

put i & "," & var1 & "," & var2 & CR after theData -- this data gets plotted

put i into theDataB["Time"] -- theDataB will go into the data grid
put var1 into theDataB["Var1"]
put var2 into theDataB["Var2"]

put max(tmax, var1 + var2) into tmax -- find max of stacked curves for autoscaling
end repeat

--section A
put round(tmax/4+.5)*4 into tmaxY -- plot will autoscale to tmaxY (setting maxY has bug)
put 361 & ",0," & tmaxY & CR after theData -- set var2 = desired maxY
--end section A

set the dgData of group "TimeAmpDataGrid" to theDataB -- for debugging, and maybe for printing

chartsCreateChart "myChart", 20, 150, 400, 380 -- only created if not pre-existing
set the charts["dataIncludesX"] of grp "myChart" to true
set the charts["chartStyle"] of grp "myChart" to "linesStacked"
set the charts["gridXNumberFormat"] of grp "myChart" to 0.000
set the charts["gridXDescriptionOrientation"] of grp "myChart" to "normal"
set the charts["chartBackgroundColor"] of grp "myChart" to 1000,1000,1000
set the charts["maxX"] of grp "myChart" to 360 -- so we don't see the last point that was added to scale Y-axis
set the charts["chartColors"] of grp "myChart" to "180,0,0" & cr & "120,120,120"

--section B
--set the charts["maxY"] of grp "myChart" to round(tmax + 1) -- this command is buggy
--end section B

set the charts["data"] of grp "myChart" to theData
chartsRefresh the long ID of grp "myChart"
end runModel

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: X-axis labeling errors

Post by malte » Mon Dec 06, 2010 12:01 pm

Hey Ken,

I´ve been looking into this now and it is rather tricky I am afraid.

As the grids attempt to draw equally spaced gridlines values for the label need to be calculated. As the spacing for the gridlines should be equal, the output CE produces is depended on the width of the graph. So the choie is to either draw the lines for the grid out of equal distances (and have the labeling off due to rounding), which makes sense for small datasets, or draw the grid oddly and have the labeling correct (which we did not choose to do in CE), or have the labels detached from the actual value and choose to use an incorrect label for the gridline, which might be off with huge datasets. Tricky.

Would it be helpful if I instead introduced a property for the chart that holds one label per line to override the calculated ones? The quick solution for now is to fiddle with the width of the chart in chartscreatechart. I guess this is sub optimal though. :-/

If you change your chartsCreateChart line to

chartsCreateChart "myChart", 20, 150, 442, 380

It will display the correct labels however this is not very satisfying I guess.

All the best,

malte

kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

Re: X-axis labeling errors

Post by kwinkler » Mon Dec 06, 2010 3:19 pm

Hi Malte,

Thanks for the quick response.

I don't understand how the grid can be drawn oddly. I have never noticed that effect in other graphing software, where the labels are always correct. But for my purposes, accurate labels are more important than having them precisely located in position. So your suggestion of a new property to override the calculated labels would be helpful. Or maybe the new property could simply calculate the correct labels, which is all I will be putting into them.

Since each axis label is a button, if should also be possible for my code to change the label on each button to the correct value. Do you agree?

Thanks for your help,

Ken

P.S. Did you have any luck with the maxY autoscaling problem?

kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

Re: X-axis labeling errors

Post by kwinkler » Mon Dec 06, 2010 4:18 pm

Malte,

I'm starting to understand the problem that you pointed out. In the attached plot, I increased the X dimension to 1000. Now it can be seen that the grid lines are actually labelled correctly, but they are not correctly positioned on the X-axis. The red curve is the absolute value of a sine wave. The minimum occurs at 180 degrees (as it should) but the grid line is located at 180.40. So I guess the problem is not with the labeling, but with the grid locations.

Would it be easier to fix the grid locations than to adjust the labeling as we discussed?

Regards,

Ken
Screen shot 2010-12-06 at 10.07.20 AM.png
Screen shot 2010-12-06 at 10.07.20 AM.png (22.84 KiB) Viewed 4004 times

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: X-axis labeling errors

Post by malte » Mon Dec 06, 2010 7:50 pm

Hi Ken,

I think what would need to be done is both. :-)
It appears we did not make the wisest design decision when we implemented the grid behaviour. There is some big news regarding chartsEngine anyway and it would be good to have that, before I officially announce it.

Allthe best,

Malte

kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

Re: X-axis labeling errors

Post by kwinkler » Mon Dec 06, 2010 8:29 pm

Hi Malte,

That sounds very encouraging. Can you give a hint regarding the time frame of the "big news"?

Ken

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: X-axis labeling errors

Post by BvG » Tue Feb 08, 2011 7:00 pm

Hi

I think I have fixed this in release 1.1.1.
Use an alternative Dictionary viewer:
http://bjoernke.com/bvgdocu/

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Post Reply

Return to “chartsEngine”