Line chart widget and global variables

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Paul_Malloy
Posts: 16
Joined: Thu Mar 20, 2008 9:45 pm

Line chart widget and global variables

Post by Paul_Malloy » Thu Sep 08, 2016 8:46 pm

I am trying to incorporate the Linechart widget into a project that scores and graphs neuropsychological test results. I reviewed the online tutorial on Linechart, which as helpful and included a script for specifying the values to be graphed (these can be entered in the Linechart properties or sent to Linechart with a script). My question is whether static integer values in the example can be replaced with dynamic variables that are generated by the scoring procedure:

Sample script:

My attempt to modify the script (which doesn't work):
local tData
put "Jan,6,22" & return &
"Feb,6,22" & return &
"Mar,8,20" & return &
"Apr,11,17" & return &
"May,14,15" & return &
"Jun,17,12" & return &
"Jul,11,18" & return &
"Aug,18,13" & return &
"Sep,16,15" & return &
"Oct,12,16" & return &
"Nov,9,18" & return &
"Dec,7,20" into tData
set the graphData of widget "Line Graph" to tData

on mouseUp
global gDRSTotT, gTrailsAT, gTrailsBT, gBDST, gCowaT, gBNTT, gBVMIT, gHVLTTotT, gHVLTretainT, gBVMTTotT, gBVMTretainT
local tGraphValues
put "DRS total," & gDRSTotT & return &
"Trails A," & gTrailsAT & return &
"Trails B," & gTrailsBT & return &
"BDS," & gBDST & return &
"COWA," & gCowaT & return &
"BNT," & gBNTT & return &
"Beery VMI," gBVMIT & & return &
"HVLT learning," & gHVLTTotT & return &
"HVLT retain," & gHVLTretainT & return &
"BVMT learning" & gBVMTTotT & return &
"BVMT retain" & gBVMTretainT into tData
set the graphData of widget "Line Graph" to tGraphValues
end mouseUp

Can anyone tell me if this is possible? Perhaps an array would be the way to go? Thanks.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Line chart widget and global variables

Post by Klaus » Thu Sep 08, 2016 9:09 pm

Hi Paul,

not sure I understand your problem, but you are filling the variable "tData"
in your mouseup handler but set the graphdata to ANOTHER local variable "tGraphValues "
which is obviously empty!
...
local tGraphValues
put "DRS total," & gDRSTotT & return &
...
"BVMT retain" & gBVMTretainT into tData
set the graphData of widget "Line Graph" to tGraphValues
...

Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Line chart widget and global variables

Post by bn » Thu Sep 08, 2016 11:10 pm

Hi Paul,

this works

Code: Select all

on mouseUp
   global gDRSTotT, gTrailsAT, gTrailsBT, gBDST, gCowaT, gBNTT, gBVMIT, gHVLTTotT, gHVLTretainT, gBVMTTotT, gBVMTretainT
   
   -- this just fills in some data into the global variables, you would use the values of the globals
   put 2 into gDRSTotT; put 5 into gTrailsAT; put 3 into gTrailsBT; put 7 into gBDST; put 6 into gCowaT
   put 1 into gBNTT; put 9 into gBVMIT; put 7 into gHVLTTotT; put 3 into gHVLTretainT; put 4 into gBVMTTotT; put 8 into gBVMTretainT
   -- end fill in
   
   local tData
   put "DRS total," & gDRSTotT & return &  \
         "Trails A," & gTrailsAT & return &  \
         "Trails B," & gTrailsBT & return &  \
         "BDS," & gBDST & return &  \
         "COWA," & gCowaT & return &  \
         "BNT," & gBNTT & return &  \
         "Beery VMI," & gBVMIT  & return &  \
         "HVLT learning," & gHVLTTotT & return &  \
         "HVLT retain," & gHVLTretainT & return &  \
         "BVMT learning," & gBVMTTotT & return &  \
         "BVMT retain," & gBVMTretainT into tData
   set the graphData of widget "Line Graph" to tData
end mouseUp
note that you have to use \ at the end of a line instead of just a return when doing this in a script. In the script editior on a Mac you do alt-return instead of just return. Using Windows or Linux should be something similar.

Kind regards
Bernd

Paul_Malloy
Posts: 16
Joined: Thu Mar 20, 2008 9:45 pm

Re: Line chart widget and global variables

Post by Paul_Malloy » Fri Sep 09, 2016 2:32 pm

Thank you very much B. I will give this a try later today.

Paul_Malloy
Posts: 16
Joined: Thu Mar 20, 2008 9:45 pm

Re: Line chart widget and global variables

Post by Paul_Malloy » Fri Sep 09, 2016 2:34 pm

Klaus wrote:Hi Paul,

not sure I understand your problem, but you are filling the variable "tData"
in your mouseup handler but set the graphdata to ANOTHER local variable "tGraphValues "
which is obviously empty!
...
local tGraphValues
put "DRS total," & gDRSTotT & return &
...
"BVMT retain" & gBVMTretainT into tData
set the graphData of widget "Line Graph" to tGraphValues
...

Best

Klaus
Thanks, Klaus for catching that error. I forgot to change that instance of tData.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Line chart widget and global variables

Post by jacque » Fri Sep 09, 2016 5:20 pm

bn wrote: In the script editior on a Mac you do alt-return instead of just return.
Actually it's better to use a backslash on all platforms. If you use the special Mac continuation character, you'll get errors when the stack runs on a different OS.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Paul_Malloy
Posts: 16
Joined: Thu Mar 20, 2008 9:45 pm

Re: Line chart widget and global variables

Post by Paul_Malloy » Sat Sep 10, 2016 2:48 pm

Thanks to all for the solutions. They worked.

Now I have another problem. :roll:

The scores I am trying to plot range from +20 to -20. The LineChart widget seems to randomly display the vertical axis values incorrectly, with a different increment in the positive direction and negative direction (e.g. one point in the positive direction and two in the negative direction). In addition, some intervals are repeated (e.g. "2" will appear twice at two different horizontal line positions). Is this a known bug? Is there a way to set the vertical axis range and increments?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Line chart widget and global variables

Post by bn » Mon Sep 12, 2016 9:32 pm

Hi Paul,

could you please post your data. Please copy the data from the Properties Inspecort for the Line Graph widget.

Also it would be helpful if you could post your intended data.

Kind regards

Bernd

Paul_Malloy
Posts: 16
Joined: Thu Mar 20, 2008 9:45 pm

Re: Line chart widget and global variables

Post by Paul_Malloy » Thu Sep 15, 2016 8:48 pm

Thanks, Bernd. This seems to be working properly now. Not sure what I was doing wrong. It would be nice to be able to set the range and increments on the axes. Perhaps that will come in future iterations of the line Graph widget.

Post Reply

Return to “Talking LiveCode”