Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save this: 1

Status
Not open for further replies.

MrDoch

Programmer
Aug 6, 2004
6
DE
Hi All,

Can someone tell me how to save the YValues from a chart?
I have tried with something like:

Chart1.SeriesList.Series[0].YValues.SaveToFile(SaveDialog1.FileName);

But then it writes: undeclared identifier 'SaveToFile'.
What is the problem?
 
Chart1.SeriesList.Series[0].YValues.SaveToFile(SaveDialog1.FileName);
Look up properties (in help) for whatever component type 'YValues' is.
Does it have a method 'SaveToFile'?

Roo
Delphi Rules!
RooBoy.jpg
 
I have found the following, but it does not help me going on:

Proberty YValue[Index:Longint]:Double

I can save a StringList without problems by writing:
StringList.SaveToFile(SaveDialog1.FileName);

I am pretty sure I cannot use SaveToFile in this case, but what else?

Regards

 
Here is a quick example which will work:
Code:
var
  i: Integer;
  values: TStringList;
begin
  values := TStringList.Create;
  try
    for i := 0 to Chart1.Series[0].YValues.Count - 1 do
      values.Add(FloatToStr(Chart1.SeriesList.Series[0].YValues.Value[i]));
    values.SaveToFile('C:\ChartYValues.txt') 
  finally
    values.Free;
  end;
end;
It loops through all the items in the YValues list and adds them to a TStringList, before saving to file.

Hope this helps!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Hi,

That helped a lot!

Now there is only one problem:
When I have saved the StringList, and try to open it again (LoadFromFile), then I get an "Access Violation".
I can solve this by chanching Values.free to Values.Clear,
but I do really want to free the memory after saving the List.. Thanks in advance.
 
You get an access violation because you are trying to access memory that has already been freed. If you want to load it in a different place in the program then use something like this:
Code:
var
  values: TStringList;
begin
  values := TStringList.Create;
  try
    values.LoadFromFile('C:\ChartYValues.txt') 
    { do some processing on the stringlist }
  finally
    values.Free;
  end;
end;
or alternatively declare the TStringList as a variable of the form/class/unit and create it in the appropriate constructor and destroy it in the appropriate destructor. That way it is persistent for longer than a single method.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Perfect, thank you very much!

Do I have to close this question, or how does it work here?
 
There is no official closure for threads - simply accepting the answer with a comment such as "thank you very much!" or "that worked" is sufficient in showing your question was answered satisfactorily.

Although I'm not trying to hint at awarding me a star, there is a star award scheme for helpful posts. You'll notice there is a "Thank [handle] for this valuable post!" link under each post. By clicking this you can award a star for each helpful post. You can only award one to each respondent.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top