Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Is it possible to determine a chart's visible size?

We are trying to automatically arrange charts (pivot tables) such that there is a small gap between objects when the number of selected members in the horizontal dimensions across the top of the Pivot Table changes. i.e. move the other objects left/right so there is small gap between the objects rather than let them overlap.

To do this I need to determine a chart's visible size. Whilst we are able to use a macro to read and write the position and size properties using getRect and setRect, we cannot determine the visible width of an object. The Width property always returns the "design" width, not the visible width.

We are planning to utilise this in a 2 x 3 display of pivot tables which arrange themselves nicely on the screen when years / periods (used as horizontal dimensions in the pivot tables) are selected from list boxes.

Having struggled with this for a while, I wondered if anyone in the community has a solution?

Thanks,

Chris.

1 Solution

Accepted Solutions
Not applicable
Author

Following up on this.

We are now on v10 SR2 and can do the following:

I have this function to find out where a chart is:

Function checklocation(chart)

    set obj=ActiveDocument.GetSheetObject(chart)

    set pos=obj.GetRect

    checklocation ="positionbox """ & chart & """ , " & pos.Left & " , " & pos.Top & " , " & pos.Width & " , " & pos.Height

End Function

This function will set a new location for a chart:

Function positionbox(objref,x,y,w,h)

    set obj=ActiveDocument.GetSheetObject(objref)

    if obj.IsMinimized then

        'Don't do anything!

    else

    '    set fr = obj.GetFrameDef

        set pos=obj.GetRect

        pos.Left = x

        pos.Top = y

        pos.Width= w

        pos.Height= h

        obj.SetRect pos

    end if

End Function

Beware that clients and browsers represent positions differently, so you need to work out how the user is accessing the document and position in the right place (use the checklocation function to find out what the right place is in client and browser - approximately multiply by 3 for the browser positions). Work out what they're using with the following code (I think this is only available from Qlikview 10). So far this seems to work the same on all browsers, but there might come a time when the positions need to be different for each browser (hope not!).

if ActiveDocument.Evaluate("left(ClientPlatform(),7)")="browser" Then...

View solution in original post

6 Replies
Not applicable
Author

We (I work with Chris) have managed to come up with some macros which reposition boxes to basic settings using the following code (we have buttons calling the stdlayout and doublewidelayout macros):

sub stdlayout
' obj ,x,y ,w,h
positionbox "CH191",1,137,550,413 'Project Groups
positionbox "CH195",555,137,520,413 'Dream Depts
positionbox "CH194",1079,137,520,413'Man Accts
positionbox "CH190",1,554,550,413 'Projects
positionbox "CH193",555,554,520,413 'Subjectives
positionbox "CH192",1079,554,520,413'Commodities
End Sub


sub doublewidelayout
' obj ,x,y ,w,h
positionbox "CH191",1,137,760,413 'Project Groups
positionbox "CH195",767,137,765,413 'Dream Depts
positionbox "CH194",1537,7,830,962 'Man Accts
positionbox "CH190",1,556,760,413 'Projects
positionbox "CH193",767,556,765,413 'Subjectives
positionbox "CH192",2372,7,914,962 'Commodities
End Sub



Function positionbox(objref,x,y,w,h)
set obj=ActiveDocument.GetSheetObject(objref)
set pos=obj.GetRect
pos.Left = x
pos.Top = y
pos.Width= w
pos.Height= h
obj.SetRect pos
End Function

This works pretty well - it's intuitive enough to use, and fast enough to enable a good experience. However, this only works in the client or plugin. In the AJAX versions the positioning is completely different - the objects end up in completely the wrong positions.

Is there a better way of doing it, or can I detect the client version in the code to set different locations / sizes for my objects for each client version?

Help appreciated,

Jon.

Not applicable
Author

Following up on this.

We are now on v10 SR2 and can do the following:

I have this function to find out where a chart is:

Function checklocation(chart)

    set obj=ActiveDocument.GetSheetObject(chart)

    set pos=obj.GetRect

    checklocation ="positionbox """ & chart & """ , " & pos.Left & " , " & pos.Top & " , " & pos.Width & " , " & pos.Height

End Function

This function will set a new location for a chart:

Function positionbox(objref,x,y,w,h)

    set obj=ActiveDocument.GetSheetObject(objref)

    if obj.IsMinimized then

        'Don't do anything!

    else

    '    set fr = obj.GetFrameDef

        set pos=obj.GetRect

        pos.Left = x

        pos.Top = y

        pos.Width= w

        pos.Height= h

        obj.SetRect pos

    end if

End Function

Beware that clients and browsers represent positions differently, so you need to work out how the user is accessing the document and position in the right place (use the checklocation function to find out what the right place is in client and browser - approximately multiply by 3 for the browser positions). Work out what they're using with the following code (I think this is only available from Qlikview 10). So far this seems to work the same on all browsers, but there might come a time when the positions need to be different for each browser (hope not!).

if ActiveDocument.Evaluate("left(ClientPlatform(),7)")="browser" Then...

Not applicable
Author

How did you manage to move and resize objects in Ajax? For me, it works with the IE plugin (IE 8), but doesn't work with Ajax (IE 8, Google Chrome 13.0, Firefox 3.6.20).

My macro is activated by the document OnOpen trigger / run external.

My QV Server is version 10.00.8811.6, 32 bit QlikView running on 64 bit OS (using Wow64).

God bless you! Best regards,

Marcel

Not applicable
Author

It all just worked as above (and continues to do so). We're now on SP3 running full server on 64bit. Clients are obviously all sorts using Ajax.

Have patience, stick at it, and good luck!

Jon.

Not applicable
Author

Jon, how and when is your macro triggered? Do you have any other important sub or function? Could you please post the version of your QV Server and QV WebServer?

God bless you! Regads,

Marcel

Not applicable
Author

Marcel,

The we trigger the macro via a button.

Chris.