FIND POINT ON MSCHART
-
2012년 3월 5일 월요일 오전 8:10
I have a spline curve graph having 10 points on MS CHART using vb.net:
(1,30), (2,35),(3,42),(4,47),(5,53),(6,49),(7,45),(8,43),(9,41),(10,37)
how can i find the X value where y = 51 ?
- 편집됨 asb17470 2012년 3월 5일 월요일 오전 9:29
모든 응답
-
2012년 3월 5일 월요일 오후 10:29
I don't think it is posible to get values of any of the MS Chart functions, unless anyone else knows different. Spline fits are normally used for getting equally spaced points rather than specific values, so fitting a single polynomial function might be more useful.
The only way I know of getting the approximate value from a spline is to use a maths library function rather than the ms chart option. The Math.Net library has a CubicSplineInterpolation function that does the job. Apologies for using c# but you can get the following,
With the following code that ignores the fact that y=51 gives 2 x values.
using MathNet.Numerics.Interpolation.Algorithms; public Form1() { InitializeComponent(); double[] xData = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; double[] yData = new double[] { 30, 35, 42, 47, 53, 49, 45, 43, 41, 37 }; //store the spline List<double> splineX = new List<double>(); List<double> splineY = new List<double>(); //generate the spline CubicSplineInterpolation myInterp = new CubicSplineInterpolation(xData, yData); double a = 1; while (a < 10) { splineX.Add(a); splineY.Add(myInterp.Interpolate(a)); a = a + 0.05; } //get the Y value closest to required var closest = splineY.Select(n => new { n, distance = Math.Abs(n - 51) }) .OrderBy(p => p.distance) .First().n; //get the X value double myVal = splineX[splineY.IndexOf(closest)]; //Plot the chart chart1.Series.Clear(); chart1.Legends.Clear(); Series actual = new Series("Actual"); actual.Points.DataBindXY(xData, yData); actual.ChartType = SeriesChartType.Point; actual.ChartArea = "ChartArea1"; chart1.Series.Add(actual); // Series smooth = new Series("Smooth"); smooth.Points.DataBindXY(splineX, splineY); smooth.ChartType = SeriesChartType.Line; smooth.ChartArea = "ChartArea1"; chart1.Series.Add(smooth); // CalloutAnnotation myAnno = new CalloutAnnotation(); myAnno.AllowMoving=true; myAnno.Text = string.Format("X= {0:f2} : Y= {1:f4}",myVal, closest); myAnno.AnchorDataPoint = smooth.Points[splineY.IndexOf(closest)]; chart1.Annotations.Add(myAnno); }Does that help?
Regards
George
- 편집됨 SharpStatistics 2012년 3월 5일 월요일 오후 10:30

