Bad Summ of 2 series (different sizes)

28 Views Asked by At

I have 2 series - both diffenent size. Screen below show bad summ. I'm use below code to summ 2 series.

SDIAppForm->Chart4->Series[4]->SetFunction(new TAddTeeFunction(SDIAppForm->Chart4));

SDIAppForm->Chart4->Series[4]->DataSources->Add( SDIAppForm->Chart4->Series[3]); SDIAppForm->Chart4->Series[4]->DataSources->Add( SDIAppForm->Chart4->Series1);

SDIAppForm->Chart4->Series[4]->CheckDataSource();

Series1 and Series3 are red colour, Black is wrong summ (partially overlap series 3

Do you have any simple idea how I can solve problem? I'm not an expert with TeeChart so I will be appriciate for simple example how to solve this problem.

1

There are 1 best solutions below

0
On

Problem solved with interpolate function

    float InterpolateLineSeries_Power(  double XValue, int APMChart4SeriesCounter_)
 // FirstIndex, LastIndex: Integer; XValue: Double): Double;
{
  int Index=0;
  double dx,dy;
               for ( Index = SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->FirstDisplayedIndex(); Index < SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->LastValueIndex ; Index++) {
                 if ((SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->XValues->Value[Index])>XValue)  break;

               }


  //safeguard
  if (Index<1)  Index=1;
  else if (Index>=SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->Count())  Index=SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->Count()-1;

  // y=(y2-y1)/(x2-x1)*(x-x1)+y1
  dx=SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->XValues->Value[Index] - SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->XValues->Value[Index-1];
  dy=SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->YValues->Value[Index] - SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->YValues->Value[Index-1];

  if (dx!=0)
    return dy/dx*(XValue - SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->XValues->Value[Index-1]) + SDIAppForm->Chart4->Series[APMChart4SeriesCounter+3]->YValues->Value[Index-1] ;
  else  return 0;
}