Calculated Variables and Chart Positioning

Get help and support using chartsEngine for LiveCode.

Moderators: heatherlaine, BvG

Post Reply
andrew99
Posts: 11
Joined: Mon Mar 23, 2009 12:49 pm

Calculated Variables and Chart Positioning

Post by andrew99 » Mon Mar 23, 2009 1:17 pm

Hello,

I'm new to revolution and working with ChartsEngine (which looks great!). I'm trying to display a chart (stacked line) based on a bunch of calculated variables and i'm a bit confused. Hopeing someone might be able to help.

Is there a worked example that might be able to be published to show how I get a half dozen or so calculated variables into 'tdata' and specify an onscreen location for the chart (ideally I'd like it to appear within a tabbed button - note the tabed button only fills the lower half of my window). Should the selected tab change I need the chart to hide, and / or the calculated variables change (using the Compute function) I need the chart to refresh.

Sorry if that sounds rather confusing but I'm lost and would appreciate any help.

Many thanks

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

Post by malte » Mon Mar 23, 2009 2:35 pm

Hi Andrew,

what you want should be pretty straightforward. :)

If you create the chart from scratch, you are able to specify a rectangle in which it should be rendered in.

chartsCreateChart "testchart",20,40,320,440

the first Parameter is the name of the chart being created, the following parameters are left location, measured from the left of the card, top location, measured from top of card, right location, measured from left of the card and bottom location, measured from top of the card.

If you want to refresh an existing chart, but want to change the dimensions, you can set the width and height of the group control that contains the chart. An example could look like this:

Code: Select all

local tOldTopLeft
-- remember the original topLeft of the chart
put the topLeft of grp "myChart" into tOldTopLeft
set the width of grp "myChart" to 500
set the height of grp "myChart" to 370
set the topLeft of grp "myChart" to tOldTopLeft
send chartsRefresh to grp "myChart"
For the variables, could you please give an example of which variables you use, and the data that is contained in these variables?

All the best,

Malte

andrew99
Posts: 11
Joined: Mon Mar 23, 2009 12:49 pm

Chart variables

Post by andrew99 » Wed Mar 25, 2009 1:14 pm

Malte,

Thankyou for your reply its very helpful.

The calculated variables for the stacked line chart I mentioned would be as follows.

(X axis) years 1 to 10 (#)

(Y axis) calculated values (£)

Line 1 - Year 0 Annual Income - [Gross Income (£)]
Line 1 - Year 1 Annual Income - [Gross Income (£)] * [Income Growth (%)]
Line 1 - Year 2 Annual Income - [Year 1 Annual Income (£)] * [Income Growth (%)]
Line 1 - Year n Annual Income - [Year n-1 Annual Income (£)] * [Income Growth (%)]

Line 2 - Year 0 Annual Expenses - [Gross Expenses (£)]
Line 2 - Year 1 Annual Expenses - [Gross Expenses (£)] * [Inflation (%)]
Line 2 - Year 2 Annual Expenses - [Year 1 Annual Expenses (£)] * [Inflation (%)]
Line 2 - Year n Annual Expenses - [Year n-1 Annual Expenses (£)] * [Inflation (%)]

Line 3 - Year 0 Annual Net Income - [Gross Income (£)] - [Expenses (£)]
Line 3 - Year 1 Annual Net Income - ([Gross Income (£)] * [Income Growth (%)]) - ([Expenses (£)] * [Inflation (%)])
Line 3 - Year 2 Annual Net Income - ([Year 1 Annual Income (£)] * [Income Growth (%)]) - ([Year 1 Annual Expenses (£)] * [Inflation (%)])
Line 3 - Year n Annual Net Income - ([Year n-1 Annual Income (£)] * [Income Growth (%)]) - ([Year n-1 Annual Expenses (£)] * [Inflation (%)])

Hope this isn't too complicated.

Also thanks again for your help! Really appreciate it.

Andrew

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

Post by malte » Wed Mar 25, 2009 9:33 pm

Hi Andrew,

you're welcome. :) I want the lib to be used, so I better try my best to explain how it works, best in real life applications. Glad if it helps.

I am not sure I get the contents of the var completely. Is this an array? A cr delimited list? If so, what is the itemDelimiter? Is it a comma?

I think it would be helpful to see the code, that fills your variables. I am travelling this week, so I may not have full time access to the intertubes. Please excuse if the next reply takes a moment longer.

Cheers,

Malte

andrew99
Posts: 11
Joined: Mon Mar 23, 2009 12:49 pm

Variables & Charts

Post by andrew99 » Thu Mar 26, 2009 3:37 pm

Malte,

Sorry - it probably looked more complicated than it really is. I'll try to clarify. Note the () indicate the number format - ie. (£) indicates a £XXX,XXX value format and (%) indicates a X.X% value format. The [] indicates the variables known or calculated.

On the X axis we have time represented as Years 0 to 10 (#)

On the Y axis we have our calculated values (£)

LINE 1 - Annual Income - Years 0 -10
[Year 0 Annual Income (£)] = [Gross Income (£)]
ie: £100 = £100
[Year 1 Annual Income (£)] = ([Gross Income (£)] * [Income Growth (%)]) + [Gross Income (£)]
ie: £110 = (£100 * 10%) + £100
[Year 2 Annual Income (£)] = [Year 1 Annual Income (£)] * [Income Growth (%)] + [Year 1 Annual Income (£)]
ie: £121 = (£110 * 10%) + £110

[Year n Annual Income (£)] = ([Year n-1 Annual Income (£)] * [Income Growth (%)]) + [Year n-1 Annual Income (£)]

LINE 2 - Annual Expenses - Years 0 -10
[Year 0 Annual Expenses (£)] = [Gross Expenses (£)]
[Year 1 Annual Expenses (£)] = ([Gross Expenses (£)] * [Inflation (%)]) + [Gross Expenses (£)]
[Year 2 Annual Expenses (£)] = ([Year 1 Annual Expenses (£)] * [Inflation (%)]) + [Year 1 Annual Expenses (£)]

[Year n Annual Expenses (£)] = ([Year n-1 Annual Expenses (£)] * [Inflation (%)]) + [Year n-1 Annual Expenses (£)]

LINE 3 - Annual Net Income - Years 0 -10
[Year 0 Annual Net Income (£)] = [Gross Income (£)] - [Expenses (£)]
[Year 1 Annual Net Income (£)] = (([Gross Income (£)] * [Income Growth (%)]) + [Gross Income (£)]) - (([Expenses (£)] * [Inflation (%)]) + Expenses (£)])
[Year 2 Annual Net Income (£)] = (([Year 1 Annual Income (£)] * [Income Growth (%)]) + [Year 1 Annual Income (£)]) - (([Year 1 Annual Expenses (£)] * [Inflation (%)]) + [Year 1 Annual Expenses (£)])

[Year n Annual Net Income (£)] = (([Year n-1 Annual Income (£)] * [Income Growth (%)]) + [Year n-1 Annual Income (£)]) - (([Year n-1 Annual Expenses (£)] * [Inflation (%)]) + [Year n-1 Annual Expenses (£)])

If you'd rather have this as code I can do that, just let me know.

Andrew

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

Post by malte » Mon Mar 30, 2009 2:15 pm

Hi Andrew,

please excuse the late reply. I was travelling. It would be most helpful to see the part of your code that fills your variables, as I still can not see how they are organized (itemdelimiter, lines, etc.)

All the best,

Malte

andrew99
Posts: 11
Joined: Mon Mar 23, 2009 12:49 pm

Re: Calculated Variables and Chart Positioning

Post by andrew99 » Fri Jan 08, 2010 6:10 pm

Malte,

Wondering if you might be able to help, I'm getting errors with my graphing of a number of calculated variables - hopefully a useful sample of my code is as follows

--Income Charts Variable Calculations

--Gross Income
put (v_Total_Letting_Income * v_Rental_Growth) into v_Gross_Income_Y1
put (v_Gross_Income_Y1 * v_Rental_Growth) into v_Gross_Income_Y2
put (v_Gross_Income_Y2 * v_Rental_Growth) into v_Gross_Income_Y3
put (v_Gross_Income_Y3 * v_Rental_Growth) into v_Gross_Income_Y4
put (v_Gross_Income_Y4 * v_Rental_Growth) into v_Gross_Income_Y5
put (v_Gross_Income_Y5 * v_Rental_Growth) into v_Gross_Income_Y6
put (v_Gross_Income_Y6 * v_Rental_Growth) into v_Gross_Income_Y7
put (v_Gross_Income_Y7 * v_Rental_Growth) into v_Gross_Income_Y8
put (v_Gross_Income_Y8 * v_Rental_Growth) into v_Gross_Income_Y9
put (v_Gross_Income_Y9 * v_Rental_Growth) into v_Gross_Income_Y10

--Net Income
put (v_Total_Letting_Income - v_Total_Letting_Expenses) into v_Net_Income_Y1
put v_Net_Income_Y1 into v_Net_Income_Y2
put v_Net_Income_Y1 into v_Net_Income_Y3
put v_Net_Income_Y1 into v_Net_Income_Y4
put v_Net_Income_Y1 into v_Net_Income_Y5
put v_Net_Income_Y1 into v_Net_Income_Y6
put v_Net_Income_Y1 into v_Net_Income_Y7
put v_Net_Income_Y1 into v_Net_Income_Y8
put v_Net_Income_Y1 into v_Net_Income_Y9
put v_Net_Income_Y1 into v_Net_Income_Y10

local tchart
chartsCreateChart "Annual_Income_Analysis"
put the result into tchart
set the charts["chartStyle"] of group "Annual_Income_Analysis" to "linesStacked"
set the charts["data"] of tchart to "v_Gross_Income_Y1,v_Net_Income_Y1" & cr & "v_Gross_Income_Y2,v_Net_Income_Y2"
set the charts["showLegend"] of grp "Annual_Income_Analysis" to true
set the charts["legendNames"] of grp "Annual_Income_Analysis" to "Gross Income"&cr&"Net Income"
chartsRefresh tChart

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

Re: Calculated Variables and Chart Positioning

Post by malte » Fri Jan 08, 2010 6:53 pm

What is the error you get?

What is in v_Total_Letting_Income and v_Rental_Growth?

All the best,

Malte

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

Re: Calculated Variables and Chart Positioning

Post by malte » Fri Jan 08, 2010 6:55 pm

*scrrrrrreeeeeeeeeeeeeeeeeaaaaaaaaaatch* (sound of emergency break)

Hit reply too early.

You pass strings as data for the chart:

set the charts["data"] of tchart to "v_Gross_Income_Y1,v_Net_Income_Y1" & cr & "v_Gross_Income_Y2,v_Net_Income_Y2"
should be without quotes:

set the charts["data"] of tchart to v_Gross_Income_Y1,v_Net_Income_Y1 & cr & v_Gross_Income_Y2,v_Net_Income_Y2

Hope that helps,

Malte

PS: You seem to be passing only 2 datapoints for each line here. Is that really what you want?

Post Reply

Return to “chartsEngine”