Solved

Find the x for y in chart

Posted on 2006-07-05
5
230 Views
Last Modified: 2011-09-20
Hi.

If i know the y value how can i find the x value and vice versa?

Example for (Chart1.SeriesList.Series[0].MaxYValue) how can i find the x ?
0
Comment
Question by:CodedK
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17044411

The MaxYValue property returns the largest Y value in the chart series, it does not return you the index of the data point (which would be needed in order to get the corresponding X value). You could walk the series YValues[index] until you found the yvalue that = MaxYValue, which would then give you the index, but if there are 2 data points where the YValue = MaxYValue, then you would not be able to determine what data point you needed to get. Eg, given the 6 sample data points in the format of index = (x, y)

0 = (1, 5)
1 = (2, 7)
2 = (10, 20)
3 = (11, 14)
4 = (15, 12)
5 = (8, 20)

The series MaxYValue would return 20. But because there are 2 data points with Y=20, you would be unable to determine if the corresponding X value was supposed to be 10 or 8. So, only if EVERY y value and EVERY x value is unique, will you be able to do what you are asking.

Russell

0
 
LVL 16

Author Comment

by:CodedK
ID: 17044463
Thank you Russell.

But how can find the x. Given that y is unique.
Can you tell me the commands?
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 125 total points
ID: 17044604
Assuming that the x values and y values are unique, the following functions could be used against a given chart series.

Russell

---

function FindXForY(YValue: Double; Series: TChartSeries): Double;
var  dwIndex:       Integer;
begin

  // Set default result
  result:=0;

  // Find the index of the y value
  for dwIndex:=0 to Pred(Series.YValues.Count) do
  begin
     if (Series.YValue[dwIndex] = YValue) then
     begin
        // Return the x value
        result:=Series.XValue[dwIndex];
        // Done
        break;
     end;
  end;

end;

function FindYForX(XValue: Double; Series: TChartSeries): Double;
var  dwIndex:       Integer;
begin

  // Set default result
  result:=0;

  // Find the index of the y value
  for dwIndex:=0 to Pred(Series.XValues.Count) do
  begin
     if (Series.XValue[dwIndex] = XValue) then
     begin
        // Return the y value
        result:=Series.YValue[dwIndex];
        // Done
        break;
     end;
  end;

end;

0
 
LVL 16

Author Comment

by:CodedK
ID: 17044749
Thank you very much Russell :)
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17045244
No problem,
Russell
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 117
Performance of SQL statement 37 137
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 75
Get weeknumber and year from date 4 25
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question