Position text box based on data

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

Elderfield.A
Posts: 78
Joined: Thu Jul 11, 2019 10:47 pm

Position text box based on data

Postby Elderfield.A » Tue Apr 21, 2020 11:15 pm

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

EViews Jason
EViews Developer
Posts: 870
Joined: Tue Sep 16, 2008 3:50 pm

Re: Position text box based on data

Postby EViews Jason » Wed Apr 22, 2020 12:27 pm

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)

Elderfield.A
Posts: 78
Joined: Thu Jul 11, 2019 10:47 pm

Re: Position text box based on data

Postby Elderfield.A » Wed Apr 22, 2020 4:03 pm

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

EViews Jason
EViews Developer
Posts: 870
Joined: Tue Sep 16, 2008 3:50 pm

Re: Position text box based on data

Postby EViews Jason » Fri Apr 24, 2020 9:07 am

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13305
Joined: Tue Sep 16, 2008 5:38 pm

Re: Position text box based on data

Postby EViews Gareth » Fri Apr 24, 2020 9:13 am

This link will probably help:
https://bit.ly/2VTzFXw
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 29 guests