Модератор: Модераторы
//Чистим MedChart от предыдущих серий
Medchart.Series.Clear;
//Создаем серии
for i:=1 to n do
begin
series[i]:= TSerie.Create(MedChart);
series[i].ShowLines := true;
series[i].ShowPoints := true;
series[i].PointStyle := taseries.psCircle;
series[i].ShowInLegend:=true;
end;
//Присваиваем серии компоненту TAChart
if checkbox1.checked then
MedChart.AddSerie(series[1]);
........
........
//Легенда серий
series[1].title := 'Рост';
series[2].title := 'Вес';
.......
//Цвета линий серий
series[1].SeriesColor := clRed;
series[2].SeriesColor := clGreen;
//Запрос сведений для диаграммы с SQL сервера
Dataset.sql.clear;
Dataset.sql.add('select * from Medicine where TestDate>='''+FormatDateTime('yyyy-mm-dd',begindate)+''' and TestDate<='''+FormatDateTime('yyyy-mm-dd',enddate)+''' and ClientID='+ClientID+' order by TestDate');
Dataset.Open;
count:=0;
while not Dataset.EOF do begin
count:=count+1;
Series[1].addxy(count,Dataset.FieldByName('ClientHeight').AsFloat,floattostr(Dataset.FieldByName('ClientHeight').AsFloat),clTAColor);
Series[2].addxy(count,Dataset.FieldByName('ClientWeight').AsFloat,floattostr(Dataset.FieldByName('ClientWeight').AsFloat),clTAColor);
.....
Dataset.Next;
end;
Dataset.Close;
procedure TChart.DrawLegend(ACanvas : TCanvas; ARect : TRect);
var
w,h,x1,y1,x2,y2,i,TH:Integer;
MySerie:TChartSeries;
j: Integer; //Edit
begin
TmpBrush.Assign(ACanvas.Brush);
TmpPen.Assign(ACanvas.Pen);
TmpFont.Assign(ACanvas.Font);
w:=GetLegendWidth(ACanvas);
TH:=ACanvas.TextHeight('I');
if only_pie then begin//if only one pie show diferent legend
MySerie := get_pie;
h:=5+MySerie.Count*(TH+5);
end else begin
h:=5+SeriesInLegendCount*(TH+5);
end;
x1 := ARect.Right-w-5;
y1 := YImageMax;
x2 := x1+w;
y2 := y1+h;
// Border
ACanvas.Brush.Assign(FGraphBrush);
ACanvas.Pen.Assign( FLegend.Frame );
ACanvas.Font.Assign( FLegend.Font );
ACanvas.Rectangle(x1,y1,x2,y2);
// Lines and Series titles
if only_pie then begin//if only one pie show diferent legend
MySerie := get_pie;
for i := 0 to MySerie.Count - 1 do begin //clean this coord shoould not be published
ACanvas.Pen.Color := FLegend.Frame.Color;
ACanvas.Brush.Color := FGraphBrush.Color;
ACanvas.TextOut(x1+25,y1+5+i*(TH+5), format('%1.2g',[PChartCoord(MySerie.Coord.items[i])^.y])+' '+PChartCoord(MySerie.Coord.items[i])^.Text);
ACanvas.Pen.Color := clBlack;
ACanvas.Brush.Color := PChartCoord(MySerie.Coord.items[i])^.Color;
ACanvas.Rectangle(x1+5,y1+i*(TH+5)+TH div 2, x1+22,y1+10+i*(TH+5)+TH div 2);
end;
end else begin
j:=0; //Edit
for i:=0 to SeriesCount-1 do begin
MySerie:=Series[i];
if MySerie.ShowInLegend then begin //Edit i->j везде
ACanvas.Brush.Assign(FGraphBrush);
ACanvas.TextOut(x1+25,y1+5+j*(TH+5),MySerie.Title);
ACanvas.Pen.Color := MySerie.SeriesColor;
if MySerie is TBarSeries then begin
ACanvas.Pen.Color := clBlack;
ACanvas.Brush.Assign( (MySerie as TBarSeries).BarBrush);
ACanvas.Rectangle(x1+5,y1+j*(TH+5)+TH div 2, x1+22,y1+10+j*(TH+5)+TH div 2);
end else if MySerie is TAreaSeries then begin
ACanvas.Pen.Color := clBlack;
ACanvas.Brush.Color := MySerie.SeriesColor;;
ACanvas.Rectangle(x1+5,y1+j*(TH+5)+TH div 2, x1+22,y1+10+j*(TH+5)+TH div 2);
end else if (MySerie is TLine) or (MySerie is TSerie) then begin
ACanvas.MoveTo(x1+5,y1+5+j*(TH+5)+TH div 2);
ACanvas.LineTo(x1+22,y1+5+j*(TH+5)+TH div 2);
end else if MySerie is TPieSeries then begin end; //down't draw
j+=1; //Edit
end;
end;
end;
ACanvas.Brush.Assign(TmpBrush);
ACanvas.Pen.Assign(TmpPen);
ACanvas.Font.Assign(TmpFont);
end;
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 56