可否指定Tchart圖表區間的顏色 |
答題得分者是:Fishman
|
cswang1210
一般會員 發表:46 回覆:42 積分:17 註冊:2005-01-06 發送簡訊給我 |
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi cswang1210, 在該 TChart 的 OnBeforeDrawAxes 事件加入以下程式碼試試:
procedure TForm1.Chart1BeforeDrawAxes(Sender: TObject); var p1,p2,T : Double; tmpRect:TRect; begin p1 := StrToFloat(Edit1.Text); // 下限 p2 := StrToFloat(Edit2.Text); // 上限 if p1 > p2 then begin t := p2; p2 := p1; p1 := t; end; tmpRect := Chart1.ChartRect; Chart1.Canvas.Brush.Style := bsSolid; Chart1.Canvas.Pen.Style := psClear; { adjust the rectangle dimension } if ((P1 < Chart1.LeftAxis.Minimum) and (p2 > Chart1.LeftAxis.Minimum)) then P1 := Chart1.LeftAxis.Minimum; if ((p1 < Chart1.LeftAxis.Maximum) and (p2 > Chart1.LeftAxis.Maximum)) then P2 := Chart1.LeftAxis.Maximum; tmpRect.Bottom := Chart1.LeftAxis.CalcYPosValue(P1); tmpRect.Top := Chart1.LeftAxis.CalcYPosValue(P2); { set the brush color } Chart1.Canvas.Brush.Color := clCream; // 顏色 { paint !!! } if ((p1 > Chart1.LeftAxis.Minimum) and (p1 < Chart1.LeftAxis.Maximum)) or ((p2 > Chart1.LeftAxis.Minimum) and (p2 < Chart1.LeftAxis.Maximum)) or ((p1 <= Chart1.LeftAxis.Minimum) and (p2 >= Chart1.LeftAxis.Maximum))then Chart1.Canvas.Rectangle(tmpRect.Left Chart1.Width3D, tmpRect.Top - Chart1.Height3D, tmpRect.Right Chart1.Width3D, tmpRect.Bottom - Chart1.Height3D); end;發表人 -
------
Fishman |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |