## Calculated Variables and Chart Positioning

**Moderators:** heatherlaine, BvG

### Calculated Variables and Chart Positioning

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

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

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"
```

All the best,

Malte

### Chart variables

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

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

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

### Variables & Charts

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 (Â£)

[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 (Â£)]

[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 (Â£)]

[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

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

### Re: Calculated Variables and Chart Positioning

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

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

### Re: Calculated Variables and Chart Positioning

What is the error you get?

What is in v_Total_Letting_Income and v_Rental_Growth?

All the best,

Malte

What is in v_Total_Letting_Income and v_Rental_Growth?

All the best,

Malte

### Re: Calculated Variables and Chart Positioning

*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?

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?