Series point values
Q: How can I copy values from one Series to another ?
Series2.DataSource := Series1 ; CBUILDER CODE : Series2->DataSource=Series1; Another solution is to call the AssignValues method: Series2.AssignValues( Series1 ); Series2->AssignValues(Series1); Q: How can I display the sum of all the values in a Chart Series? Example: There is a Pie chart series with three pie slices, the values are 10, 20, 30. Now I want to see the sum (=60) somewhere in the chart. You can use the Series.YValues Total and TotalABS properties ShowMessage( FloatToStr( Series1.YValues.Total ) ); ShowMessage(FloatToStr(Series1->YValues->Total)); Q: How can I group and plot values by month or by week ?
Q: How to add NULL values to a chart ?
Series1.AddNull( '' );Series1.AddNullXY(2,3,''); Series1->AddNull(""); Series1->AddNullXY(2,3,""); Q: How to remove gaps after deleting points in a Series ?
Series1.Delete( 3 ); Series1.XValues.FillSequence; Series1->Delete(3); Series1->XValues->FillSequence(); Q: Is there a way to specify a range of points to be shown on chart? For example, if we add 50 points to a Series, have the chart show points 34 to 41 only.The Series OnBeforeAdd event can be used to limit which points do we actually add (see the code bellow): var tmpCount:integer; procedure TForm1.FormCreate(Sender: TObject); begin Series1.Clear; //force clear, just in case Series1.FillSampleValues(50); end; function TForm1.Series1BeforeAdd(Sender: TChartSeries): Boolean; begin Inc(tmpCount); result:= (tmpCount>34) and (tmpCount<41); //add only desired values end; procedure TForm1.Series1ClearValues(Sender: TChartSeries); begin tmpCount:=0; //reset counter end; TForm1 *Form1; int tmpCount; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Series1->Clear(); //force clear, just in case Series1->FillSampleValues(50); } //--------------------------------------------------------------------------- void __fastcall TForm1::Series1ClearValues(TChartSeries *Sender) { tmpCount=0; // reset counter } //--------------------------------------------------------------------------- bool __fastcall TForm1::Series1BeforeAdd(TChartSeries *Sender) { tmpCount++; bool result= (tmpCount>34) && (tmpCount<41); //add only desired values return result; } //--------------------------------------------------------------------------- Q: I'd like to connect points in "chornological" order i.e. the way I add them. But TeeChart seems to connect points by ascending XValues.Well, the Series.XValues.Order:=loAscending; is the default setting for connecting points by line. If you require something else, you can easily change the "line drawing" order by: Series.XValues.Order:=loNone; Series1->XValues->Order=loNone; Q: If I use a Series, then the Null values are always displayed as 0. How can I avoid this?The AddNull (or the AddNullXY in TeeChart4) method is actually only the standard Add (or AddXY in TeeChart4) method with the Color=clNone; I took this out of the source code: Function TChartSeries.AddNull(Const ALabel:String):Longint; begin result:=Add( 0, ALabel, clNone ); end; Function TChartSeries.AddNullXY(Const X,Y:Double; Const ALabel:String):Longint; begin result:=AddXY(X,Y,ALabel,clNone ); end; The solution: procedure TForm1.Series1AfterAdd(Sender: TChartSeries; ValueIndex: Integer); var i:integer; begin for i:=Sender.FirstValueIndex to Sender.LastValueIndex do if Sender.IsNull(ValueIndex) then if Sender.YValue[ValueIndex]=Sender.YValues.MinValue then Sender.YValue[ValueIndex]:=Sender.YValues.MaxValue else if Sender.YValue[ValueIndex]=Sender.YValues.MaxValue then Sender.YValue[ValueIndex]:=Sender.YValues.MinValue end; void __fastcall TForm1::Series1AfterAdd(TChartSeries *Sender, int ValueIndex) { for (int i=Sender->FirstValueIndex;i<=Sender->LastValueIndex;i++) { if (Sender->IsNull(ValueIndex)) if (Sender->YValues->Value[ValueIndex]==Sender->YValues->MinValue) Sender->YValues->Value[ValueIndex]=Sender->YValues->MaxValue; else if (Sender->YValues->Value[ValueIndex]==Sender->YValues->MaxValue) Sender->YValues->Value[ValueIndex]=Sender->YValues->MinValue; } } |