Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7800011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:29:40+00:00 2026-06-02T00:29:40+00:00

Yes i know about ( This post ) , if you search you will

  • 0

Yes i know about ( This post ) , if you search you will notice the event AxisValueChanged seems to only exist in this one thread.

My goal is simply to automaticly zoom the Y axis when user make a selection on the X axis, but i have been unable to figure out how.

I also tried to to use the SelectionRangeChanged event, but this event seems kind of broken as im unable to figure out whats actual range selected? ( IE so i can find the maximum / minimum ranges ).

Im using MS chart ( Microsoft chart )

The end goal is when i zoom X axis ( This is a FastLine Chart) it should see the new “max” visible value on Y axis and resize/zoom it accordingly

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:29:41+00:00Added an answer on June 2, 2026 at 12:29 am

    If I understand you correctly, given a zoomed range on X axis you want to zoom also the same range on Y axis. If so, you can do in this way:

    void chart1_SelectionRangeChanged(object sender, CursorEventArgs e)
    {
        // Given the visible (zoomed) range on X, 
        // it zooms the same relative range on Y:
        // i.e. if on the X axis, the range 5% - 30% is zoomed, 
        // it zooms the same range on Y.
        var axisY = this.chart1.ChartAreas[0].AxisY;
    
        var totalXRange = e.Axis.Maximum - e.Axis.Minimum;
        var totalYRange = axisY.Maximum - axisY.Minimum;
    
        var ySelectionStart = (e.Axis.ScaleView.ViewMinimum - e.Axis.Minimum) *
                              totalYRange / totalXRange;
        var ySelectionEnd = (e.Axis.ScaleView.ViewMaximum - e.Axis.Minimum) * 
                             totalYRange / totalXRange;
    
        axisY.ScaleView.Zoom(ySelectionStart,ySelectionEnd);
    }
    

    As you said, the event AxisValueChanged doesn’t exist; the post you linked probably meant the (existing) event AxisViewChanged.

    Obviously, you can also use AxisViewChanged for your purpose, and adapting my code to exploit that event shouldn’t be so hard.

    Feel free to ask if you need help though 😉

    EDIT :

    I modified my code to account for your goal. The following code computes the Y range corresponding to the maximum and minimum values of the points inside the zoomed X range:

    void chart1_SelectionRangeChanged(object sender, CursorEventArgs e)
    {
        var axisY = this.chart1.ChartAreas[0].AxisY;
    
        var xRangeStart = e.Axis.ScaleView.ViewMinimum;
        var xRangeEnd = e.Axis.ScaleView.ViewMaximum;
    
        // compute the Y values for the points crossing the range edges
        double? yRangeStart = null;
        var pointBeforeRangeStart = this.chart1.Series[0].Points.FirstOrDefault(x => x.XValue <= xRangeStart);
        var pointAfterRangeStart = this.chart1.Series[0].Points.FirstOrDefault(x => x.XValue > xRangeStart);
        if (pointBeforeRangeStart != null && pointAfterRangeStart != null)
            yRangeStart = Interpolate2Points(pointBeforeRangeStart, pointAfterRangeStart, xRangeStart);
    
        double? yRangeEnd = null;
        var pointBeforeRangeEnd = this.chart1.Series[0].Points.FirstOrDefault(x => x.XValue <= xRangeEnd);
        var pointAfterRangeEnd = this.chart1.Series[0].Points.FirstOrDefault(x => x.XValue > xRangeEnd);
        if (pointBeforeRangeEnd != null && pointAfterRangeEnd != null)
            yRangeEnd = Interpolate2Points(pointBeforeRangeEnd, pointAfterRangeEnd, xRangeEnd);
    
        var edgeValues = new[] { yRangeStart, yRangeEnd }.Where(x => x.HasValue).Select(x => x.Value);
    
        // find the points inside the range
        var valuesInRange = this.chart1.Series[0].Points
        .Where(p => p.XValue >= xRangeStart && p.XValue <= xRangeEnd)
        .Select(x => x.YValues[0]);
    
        // find the minimum and maximum Y values
        var values = valuesInRange.Concat(edgeValues);
        double yMin;
        double yMax;
        if (values.Any())
        {
            yMin = values.Min();
            yMax = values.Max();
        }
        else
        {
            yMin = this.chart1.Series[0].Points.Min(x => x.YValues[0]);
            yMax = this.chart1.Series[0].Points.Max(x => x.YValues[0]);
        }
    
        // zoom Y-axis to [yMin - yMax]
        axisY.ScaleView.Zoom(yMin, yMax);
    }
    
    // see: http://en.wikipedia.org/wiki/Linear_interpolation#Linear_interpolation_between_two_known_points
    public static double Interpolate2Points(DataPoint p1, DataPoint p2, double x)
    {
        var x0 = p1.XValue;
        var y0 = p1.YValues[0];
        var x1 = p2.XValue;
        var y1 = p2.YValues[0];
        return y0 + ((x - x0) * y1 - (x - x0) * y0) / (x1 - x0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, yes I know about this question , but I'm looking for a bit
I use an email registration and confirmation in my project (yes, I know about
Yes I know, this title isn't really helpfull but this is the exact problem.
Here's Eric Lippert's comment from this post : Now that you know the answer,
I know there are alot of different questions about this but none of them
Yes, I KNOW about Google Analytics. We use it for our overall site metrics,
I just came across this post .It just nicely explains about configuring unicorn server
Yes I know that it shouldn't be abused and that C# is primariy used
(Yes I know I can call Java code from Scala; but that is pointless;
Ok so I start coding websites (yes I know I am almost 15 years

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.