Page 1 of 1

Chart display question

Posted: Tue Jan 23, 2007 8:05 pm
by 8440889
Hello,

I've taken over a project from another developer and I'm looking for a answer to a problem that we have had reported.

We have a simple distribution chart. Typical values on the left axis range from 0 to infinity. When the chart is displayed, using the scroll wheel on the mouse scrolls the chart upwards and downwards. The problem arises from scrolling the chart up. When this happens, the chart shows negative values and I cannot figure out how to make the chart not scroll pass 0.

I am using a standard TChart, programming in delphi 7. I've tried setting the LeftAxis.AutomaticMinimum to False and setting a minimum of zero. But that doesn't work. I suspect I can catch this behavior in the OnScroll event, but I have no idea what to test for.

Anyone? I would greatly appreciate the help. Thanks![/img]

Posted: Wed Jan 24, 2007 8:43 am
by narcis
Hi lkuderick,

You could tried doing something like this:

Code: Select all

procedure TForm1.Chart1Scroll(Sender: TObject);
begin
  With Chart1.Axes.Left do
    if Minimum < 0 then
    begin
      AutomaticMinimum:=false;
      Minimum:=0;
    end
    else
      Automatic:=true;
end;

Posted: Wed Jan 24, 2007 4:13 pm
by 8440889
Narcis,

Thank you for the reply. That almost works. However, when the chart attempts to move below 0 using the scroll wheel, the ticks on the left axis adjust the scale of the graph.

The ticks on the left axis presently scaled every 50 units. Once you start to scroll the chart negatively, the scales start to change and zoom the chart. I'm not 100% positive that some other code is effecting this however, I have disabled everything I have found relating to this chart.

At this point, I'm making an assumption that this is designed behavior that the chart rescales. If there is a property I haven't quite been able to locate it yet.

I only got this project a couple of weeks ago and have only started to read the documentation about this component, so please bear with me.

Is there a method to quickly reset to the original scale?

Posted: Thu Jan 25, 2007 9:17 am
by narcis
Hi lkuderick,

Yes, an easy way to unzoom a chart is letting the axes to automatically scale to best fit the series on their drawing area:

Code: Select all

  Chart1.Axes.Left.Automatic:=true;

Posted: Fri Jan 26, 2007 7:28 pm
by 8440889
Narcis,

Thank you for all your help. I really appreciate it. I have another question and problem that I have been unable to resolve.

Using the Zoom feature of the chart I can use the mouse to grab a region of the chart and focus in on that portion. This works well as long as the region that is selected is above 0 on the Y axis.

However, when a user grabs a region around the 0 axis the zoomed region shows a area below the 0 axis that shouldn't exist. Is there any way to limit these 'grabs' to not display information below the 0 axis?

Again, thank you for your help?

Posted: Mon Jan 29, 2007 8:03 am
by narcis
Hi lkuderick,

Yes, as I suggested in my first post, you should try setting axes minimum and/or maximum values in the OnScroll event.