How to modify the element legend name and value using an edit method

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
PCSdeZ
Newbie
Newbie
Posts: 4
Joined: Thu Dec 16, 2021 12:00 am

How to modify the element legend name and value using an edit method

Post by PCSdeZ » Fri Mar 11, 2022 12:12 pm

Hi, I would like to have some help to do the following: edit the legend name and/or their value of the data elements of a Pie chart at runtime with C++Builder. I can't found a way to do this kind of editing.

My application start showing data elements with default values and legend names, for example:
Pie1,1
Pie2,1
Pie3,1
Pie4,1

Then, the user will need to change those data elements legend name and/or values, doing click on each element, for example:
Francisco,5
Andrés,2
Michel,1
Jorge,3

I founded a way to do similar thing deleting one of the original data element and then adding the new one, and so for, but this method results on an unwanted change of the data elements order of chart.
So I do not want to delete and add, but modify the data element legend name and their value using an edit method.
How can I do that?

Best regards,
Patricio Cerda

Marc
Site Admin
Site Admin
Posts: 1089
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: How to modify the element legend name and value using an edit method

Post by Marc » Fri Mar 11, 2022 7:41 pm

Hello,

The following code modifies a particular value/label in a Pie Chart. You can offer up the old values in edit boxes or by the means of your choice, to be modified.

Code: Select all

procedure TForm1.Button4Click(Sender: TObject);
begin
  Series1.YValues[3] := 70;   //0 index ... use point index of your choice
  Series1.Labels[3] := 'My label';
  Chart1.Invalidate;
end;
Regards,
Marc Meumann
Steema Support

PCSdeZ
Newbie
Newbie
Posts: 4
Joined: Thu Dec 16, 2021 12:00 am

Re: How to modify the element legend name and value using an edit method

Post by PCSdeZ » Fri Mar 18, 2022 12:06 am

I'm sorry Mr. Neumann,

I don't use Delphi but C++Builder, and I can't found documentation of your product, and can't also make work the piece of Delphi code that you sent me.

I tried this, but it does not compile:

void __fastcall TForm1::Chart1ClickSeries(TCustomChart *Sender, TChartSeries *Series,
int ValueIndex, TMouseButton Button, TShiftState Shift, int X,
int Y)
{
TChartSeries *MiSerie = Chart1->Series[TipoGraf];
MiSerie->YValues->Items[ValueIndex] = 1;
MiSerie->Labels->Labels[ValueIndex] = "Michel"; // in this line the compiler shows "expected expression"
}

Could you please send me a C++ Builder way to do what I need?

Regards,
Patricio Cerda

Marc
Site Admin
Site Admin
Posts: 1089
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: How to modify the element legend name and value using an edit method

Post by Marc » Tue Mar 22, 2022 9:38 am

Hello Patricio,

It would look like this, using the Series' click event:

Code: Select all

void __fastcall TForm1::Series1Click(TChartSeries *Sender, int ValueIndex, TMouseButton Button,
		  TShiftState Shift, int X, int Y)
{
  Sender->YValues->Items[ValueIndex] = 1;
  Sender->Labels->Labels[ValueIndex] = "Michel";
}
Regards,
Marc
Steema Support

Post Reply