ErikT 1 Posted April 12 I am using TeeChart in a GUI that continuously displays some readouts from a device. Generally, it works fine, but there is one annoyance. I use the automatic axis scaling, but would like to be able to set some constraints to that. A sort of "maximum zoom". The thing is that when a readout has been quite stable for a while, the automatic scaling feature zooms in so much that the numeric resolution becomes annoyingly visible. Example: If the example above is allowed to run for a while, the chart may be complete filled with one big blue rectangle due to this. It would be nice to be able to set a minimum distance between minimum and maximum, so the left axis in the example above would go from 42 to 52, for instance, with the blue graph being nicely centered in the chart. However, I haven't found such a setting. But since I don't exactly understand every explanation of the properties and methods in the help document, I wonder if I just haven't found it. So... does anyone have a cool solution, or do I need to go the complicated way of setting the axis minimum and maximum manually in my code, based on the series values? Share this post Link to post
Roger Cigol 107 Posted April 12 (edited) One way is to add two dummy series, one with Y values that are at the smallest maximum value you want to allow and one with Y values at the largest minimum value you want to allow. Then set the colour of the two dummy lines equal to the background colour (so they aren't visible to the user). Not the most elegant solution but a devious workable one..... Edited April 12 by Roger Cigol improved explanation Share this post Link to post
ErikT 1 Posted April 12 6 minutes ago, Roger Cigol said: One way is to add two dummy series, one with Y values that are at the smallest maximum value you want to allow and one with Y values at the largest minimum value you want to allow. Then set the colour of the two dummy lines equal to the background colour (so they aren't visible to the user). Not the most elegant solution but a devious workable one..... Okaaaay... Definitely one to consider. Thanks! Share this post Link to post
ErikT 1 Posted April 12 When I began poking around, it turned out to be not-so-complicated after all. I've made this piece of code, which seems to work nicely: procedure AdjustAxis(WhichChart : TChart; MinInterval : Double); var ChartMaxY : Double; ChartMinY : Double; ChartCenter : Double; begin ChartMaxY := WhichChart.MaxYValue(WhichChart.LeftAxis); ChartMinY := WhichChart.MinYValue(WhichChart.LeftAxis); if ((ChartMaxY - ChartMinY) < MinInterval) then begin ChartCenter := (ChartMaxY + ChartMinY) / 2; WhichChart.LeftAxis.SetMinMax(ChartCenter - (MinInterval / 2), ChartCenter + (MinInterval / 2)); WhichChart.LeftAxis.AutomaticMaximum := false; WhichChart.LeftAxis.AutomaticMinimum := false; end else begin WhichChart.LeftAxis.AutomaticMaximum := true; WhichChart.LeftAxis.AutomaticMinimum := true; end; end; The parameters are WhichChart, which is the name of the chart, and MinInterval, which is the smallest acceptable numerical difference between minimum and maximum on the left axis. Must be positive, by the way. The chart graph is centered between maximum and minimum in the chart window. Of course it can be made smarter. For instance, this only works on the left axis. Feel free to use and modify. 1 Share this post Link to post