TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
rtech
- Newbie
- Posts: 8
- Joined: Tue Apr 27, 2021 12:00 am
Post
by rtech » Wed Apr 28, 2021 7:22 am
Hello,
I need area series with two colours. One for negative and one for positive areas. (See attached screenshot for details)
I've done that by using OnAfterAdd:
Code: Select all
void __fastcall MyFlowRateRectangleSeries::OnAfterAddPoint(TChartSeries *Sender, int ValueIndex)
{
if(Sender->YValues->Value[ValueIndex] > 0)
Sender->ValueColor[ValueIndex] = DefaultPosColor;
else
Sender->ValueColor[ValueIndex] = DefaultNegColor;
}
but it doesn't work automatically, only if I call OnAfterAdd in code:
Code: Select all
NewSeries->AddXY(XValue, YValue);
NewSeries->OnAfterAdd(NewSeries, Index); //OnAfterAddPoint doesn't work without that line
also I want to apply new colours by pressing button, I need to redraw chart in OnClick handler for that?
-
Attachments
-
- Screen1AreaSeries.JPG (40.03 KiB) Viewed 8895 times
-
Yeray
- Site Admin
- Posts: 9613
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Mon May 03, 2021 10:43 am
Hello,
it doesn't work automatically, only if I call OnAfterAdd in code:
Have you assigned your
OnAfterAddPoint
method to the series
OnAfterAdd
event? Ie:
Code: Select all
NewSeries->OnAfterAdd=OnAfterAddPoint;
also I want to apply new colours by pressing button, I need to redraw chart in OnClick handler for that?
Yes, you need to repaint the chart after changing the colors.
-
rtech
- Newbie
- Posts: 8
- Joined: Tue Apr 27, 2021 12:00 am
Post
by rtech » Thu May 06, 2021 7:08 am
Have you assigned your OnAfterAddPoint method to the series OnAfterAdd event?
Yes, i've done it in my create series code:
Code: Select all
TChartSeries *MyFlowRateRectangleSeries::CreateNewSeries()
{
auto NewSeries = MyAreaSeries::CreateNewSeries();
NewSeries->OnAfterAdd = OnAfterAddPoint;
return NewSeries;
}
But without that line
Code: Select all
NewSeries->OnAfterAdd(NewSeries, Index);
it doesn't work
-
Yeray
- Site Admin
- Posts: 9613
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Fri May 07, 2021 10:34 am
Hello,
This is working for me with a new simple example:
Code: Select all
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TAreaSeries *Series1=new TAreaSeries(this);
Chart1->AddSeries(Series1);
Series1->FillSampleValues();
Series1->OnAfterAdd=OnAfterAddPoint;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TChartSeries *s=Chart1->Series[0];
s->Add(s->YValues->MinValue+Random(s->YValues->Range()));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnAfterAddPoint(TChartSeries *Sender, int ValueIndex)
{
ShowMessage("New point added");
}
If you still find problems with it, please arrange a simple example project we can run as-is to reproduce the problem here.