Page 1 of 1

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

Posted: Fri Mar 11, 2022 12:12 pm
by 16892633
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

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

Posted: Fri Mar 11, 2022 7:41 pm
by Marc
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

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

Posted: Fri Mar 18, 2022 12:06 am
by 16892633
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

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

Posted: Tue Mar 22, 2022 9:38 am
by Marc
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