MS chart - Dynamically setting the height on the basis of the number of records returned.

Hello there,

I have an MS chart control, a range bar chart which displays a set of names on the X axis and Dates on the Y axis. The chart displays the data properly to a certain number of records but when the data retrieved is too large It is not at all possible to read the data because it is too tiny.

Is there a way I can increase the height of the control on the basis of the records retrieved and also, is it possible to fix the height of the series manually.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here is a reference to properties on the MS Chart Control:

You can set the Maximum property if you desire to the MAX(value) of the range of values being placed in the chart. However, assigning a value to Maximum changes the ValueScale property Auto to False. See the web page at the link above (Maximum and ValueScale links) for more details.

Here is a link to an example working with the AxisScale object: 

Let me know if you need more detail.

Thanks, Eric
virtualmenonAuthor Commented:
hello eric,

Could you give me a simple example where I can fix the series height to be a certain percentage of the chart height..

virtualmenonAuthor Commented:
Can i set the height of the chart area dynamically..??
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Here's some VB as to how I manage the size of my Charts in an app... (This is a Bar Graph)

Dim Chart1 As New Chart
Chart1.IsMapEnabled = "False"
Chart1.ImageStorageMode = ImageStorageMode.UseImageLocation
Chart1.ImageLocation = "~/temp/ChartPic_#SEQ(300,10)" 

'Calculate the height, based on the number Chart Points (+ Legend)
'cZ is the count of the number of items on the chart
Dim cHeight As Int32 = ((cZ + 1) * 22) + 80
Chart1.Height = Unit.Pixel(cHeight)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Espavo, thanks for adding a great example.
VirtualMenon, if by dynamically you mean in the code behind, the answer demonstrated above is yes. Espavo provided a good example, let us know if you need anything else to finish the solution.
virtualmenonAuthor Commented:
Awesome example Espavo. Thanks a lot mate...Worked like a gem.


virtualmenonAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.