Area series with two colours

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
rtech
Newbie
Newbie
Posts: 8
Joined: Tue Apr 27, 2021 12:00 am

Area series with two colours

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
Screen1AreaSeries.JPG (40.03 KiB) Viewed 6583 times

Yeray
Site Admin
Site Admin
Posts: 9509
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Area series with two colours

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

rtech
Newbie
Newbie
Posts: 8
Joined: Tue Apr 27, 2021 12:00 am

Re: Area series with two colours

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
Site Admin
Posts: 9509
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Area series with two colours

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply