Size chart control in window of user monitor.

rckrch
rckrch used Ask the Experts™
on
I am trying to write code that will determine the resolution of the screen the user is using in order to properly size charts.  I am having trouble getting anything to work. Can someone please help? I am using ASP.Net chart control and vb.net.

Following is code that does not work.

Thanks for the help.

Dim CurScreenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
        Dim CurScreenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
        Dim DesignWidth As Integer = 1680        
Dim DesignHeight As Integer = 1050 
        Dim WidthRatio As Single
        Dim HeightRatio As Single

        WidthRatio = CurScreenWidth / DesignWidth
        HeightRatio = CurScreenHeight / DesignHeight

        Dim ChartWidth As Single = DesignWidth * WidthRatio * 0.96         
Dim ChartHeight As Single = DesignHeight * HeightRatio * 0.85

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi rckrch,

The problem seems to be lines 7 and 8, where you're dividing integers.  Convert to the integers to a float or real type and your code should work.


        WidthRatio = (single)CurScreenWidth / (single)DesignWidth
        HeightRatio = (single)CurScreenHeight / (single)DesignHeight


Good Luck!
Kent

Author

Commented:
Thanks Kent for the reply.  However, the WidthRatio and HeightRatio work fine.  I get the appropriate result for the variables.  The formula in the code returns the correct numbers, but the chart size is still not adjusted to the screen resolution.
Oh.  Ok.  :)

What's the context of this code?  It looks like the snippet is creating the variables ChartWidth and ChartHeight, and setting them.  The values need to be stored in the variables (properties) that are associated with the control.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
This code is in the page load.  The chart width property  is set in this procedure with Chart1.Width = ChartWidth.  Stepping through the procedure I get all of the variables to calculate correctly, but the chart dimensions are much smaller that the screen.  This works on my development server, but not on the production server.
I've never experienced this.  I've only read of similar behavior reported by others, and it has been reported quite often.

It seems that the cause is almost always a conflict with other installed software.  A registry setting, common DLL, or other item that should be benign is causing a different behavior in different environments.

One trick that seems relevant here is to Lock and then UnLock the control.  It seems that the control can inherit a Locked status and explicitly locking and unlocking can clear it.

Give that a try.

Author

Commented:
I don't know what locking and unlocking a control means.
"Locked" is just a property of the form / control.

Chart1.Locked = true;
Chart1.Locked = false;

Try this just before you set the size.

Author

Commented:
"Locked" is not among the list of properties on my asp.net chart control.
Apologies.  I misunderstood and thought this was a VB object.

Let me do a bit more research.  Or maybe one of our other experts can join in.

Author

Commented:
Thanks
Commented:
I used a function in javascript to identify the variable for width 'document.getElementById('<%=PanelWidth.ClientID%>').value'.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial