Page 1 of 1

Position text box based on data

Posted: Tue Apr 21, 2020 11:15 pm
by Elderfield.A
Hi,

I am trying to think of a neat way to position text boxes in charts based on the respective data in the chart, my first attempt of this (below) works, but still requires me to move the text boxes around to somewhere more visually appealing:

Code: Select all

   for !h =1 to data.@count 'data is a group object with the data that is being plotted
      %label = @wordq(%chart_labels, !h)    ' the labels I would like to put in the text box
      %label = @stripquotes(%label)
      %colour = @wordq(%colour_list, !h)  ' This is custom colour list defined elsewhere
      !shift = -0.3+!h    ' My attempt to position the textbox somewhere different each time the loop runs
      chart.addtext(0, !shift , keep ,textcolor({%colour}), fillcolor(@rgb(255,255,255)), framecolor(@rgb(0,0,0)),  font(Arial,12,b,-i,-u,-s)) {%label}
   next


I'd really like to get to a point where they are positioned some where near the data they refer to, but not on the data, in the first instance. And if I have to move them after for a final touch then I can.

Any suggestions?

Thanks

Adam

Re: Position text box based on data

Posted: Wed Apr 22, 2020 12:27 pm
by EViews Jason
Try using the (EViews 11 only) @axispos data member. This will return in virtual inches the location of a data point on the graph.

Here is an example on how to use it:

Code: Select all

create m 90 20

series x=@trend

freeze(g) x.line

!x = g.@axispos(1995,"b")   ' get the x coordinate from the bottom axis
!y = g.@axispos(200,"l") ' get the y coordinate from the left axis

show g

g.addtext(!x, !y, keep ,textcolor(red), fillcolor(@rgb(255,255,255)), framecolor(@rgb(0,0,0)),  font(Arial,12,b,-i,-u,-s)) "Text where top left corner\n is located at (1995,200)

Re: Position text box based on data

Posted: Wed Apr 22, 2020 4:03 pm
by Elderfield.A
Hi Jason,

Thanks for you reply and example. Unfortunately, my organisation is using Eviews 10+ (sorry I should have mentioned that from the outset). Is there a workaround here?

Thanks

Adam

Re: Position text box based on data

Posted: Fri Apr 24, 2020 9:07 am
by EViews Jason
Unfortunately for EViews 10 and earlier, there isn't a way to do what you want programatically without predetermining the location via the user interface.

Re: Position text box based on data

Posted: Fri Apr 24, 2020 9:13 am
by EViews Gareth
This link will probably help:
https://bit.ly/2VTzFXw