在網上查了多少回,有的說是實時曲線,但是沒有乙個是真正的實時曲線,今天我決定寫乙個真的實時曲線 ,你可以稍加修改就可利用。
1、新增乙個自定義控制項,新增兩個picturebox控制項,picshow .visible設定成true,另乙個設定成不可見。首先在picshow中進行繪圖,繪圖超過x軸範圍時,轉成pichide中再繪圖並等到繪圖完畢,再顯示出來。這樣看起來就是連續的。
寫 下**
public class ucrealcurs
dim maxplotno as long '最長的x軸範圍
dim sdataponit() as pointf '顯示影象
dim hdataponit(20) as pointf
dim did as long '序號
dim ymin as single = 99999.9, ymax as single = -99999.9
dim scalefactorx, scalefactory as single
dim pscalex, pscaley as single
dim wid as integer '影象的寬度
dim hgt as integer '影象的高度
dim bm as image
dim gr as graphics
'在**窗體上作畫,畫好以後再顯示在顯示
private function plotdata(byval pointarray() as pointf) as boolean
dim redpen as new pen(color.red), mpen as new pen(color.blue), lpointarray(), lbasearray(1) as pointf
dim bm2 as new bitmap(wid, hgt) '建立背景繪圖區
dim gr2 as graphics = graphics.fromimage(bm2) '建立繪圖的畫布
dim pen as pen = new pen(color.green)
pen.dashstyle = drawing2d.dashstyle.dot
for i as integer = 0 to hgt step 20
gr2.drawline(pen, 0, i, wid, i)
next
for i as integer = 0 to wid step 20
gr2.drawline(pen, i, 0, i, hgt)
next
redim lpointarray(pointarray.getupperbound(0)) '重訂區域陣列變數範圍
'最小x值
'lblstartx.text = did - maxplotno + pointarray(pointarray.getlowerbound(0)).x.tostring("0.00")
''最大x值
'lblendx.text = did - maxplotno + pointarray(pointarray.getupperbound(0)).x.tostring("0.00")
'取得陣列的極限值
for i as integer = pointarray.getlowerbound(0) to pointarray.getupperbound(0)
if pointarray(i).y > ymax then ymax = pointarray(i).y
if pointarray(i).y < ymin then ymin = pointarray(i).y
next
'lblstarty.text = ymin.tostring("0") '最小y值
'lblendy.text = ymax.tostring("0") '最大y值
'填入陣列元素
for i as integer = pointarray.getlowerbound(0) to pointarray.getupperbound(0)
lpointarray(i).x = pointarray(i).x * pscalex
'和上方y零點的距離
lpointarray(i).y = pointarray(i).y * pscaley
next
gr2.drawlines(redpen, lpointarray) '繪圖
pichide.image = bm2 '將背景繪圖資料放到框中
pichide.refresh() '重新顯示
gr2.dispose() '清除畫布
redpen.dispose() '清除資源
end function
sub plot(byval startx as single)
scalefactorx = maxplotno
scalefactory = 300 ' ymax - ymin
pscalex = picshow.width / scalefactorx 'x軸的比例係數
pscaley = (picshow.height * 0.97) / scalefactory 'y軸的比例係數
redim preserve sdataponit(did)
sdataponit(did).x = did * pscalex
sdataponit(did).y = startx * pscaley
if did < maxplotno then
if did > 1 then
gr.drawline(pens.red, sdataponit(did - 1), sdataponit(did))
end if
picshow.bringtofront()
picshow.image = bm
picshow.refresh()
else
picshow.visible = false
pichide.visible = true
for i as integer = 0 to maxplotno
hdataponit(i).x = i ' + did - 20
hdataponit(i).y = sdataponit(i + did - 20).y
next
plotdata(hdataponit)
end if
did = did + 1
' gr.dispose()
end sub
private sub ucrealcurs_load(byval sender as object, byval e as system.eventargs) handles me.load
wid = picshow.clientsize.width
hgt = picshow.clientsize.height
bm = new bitmap(wid, hgt) '建立背景繪圖區
gr = graphics.fromimage(bm) '建立繪圖的畫布
maxplotno = 20
dim pen as pen = new pen(color.green)
pen.dashstyle = drawing2d.dashstyle.dot
for i as integer = 0 to hgt step 20
gr.drawline(pen, 0, i, wid, i)
next
for i as integer = 0 to wid step 20
gr.drawline(pen, i, 0, i, hgt)
next
end sub
end class
這裡只是設定乙個20個資料的寬度,但是這個寬度是可以調整的,不過如果想在子執行緒來執行,就需要對其它的幾個控制項進行委託來呼叫顯示,這將再以後幾節中為說明。
C 繪製實時曲線
1.要做乙個除錯工具,採集感測器資料並顯示。繪製曲線注意座標反轉,線條的張力即可。專案中的曲線是從右往左顯示的,線條的座標都放在list裡了,效果如下圖 2.上 public class drawingcurve 繪製畫布 public bitmap drawcanvas int width,int...
ZedGraph實時曲線例項
2010 10 17 11 23 58 分類 asp.net 舉報 字型大小 訂閱 public partial class frmmain form private void frmmain load object sender,eventargs e private void timedraw ...
ZedGraph實時曲線例項
2010 10 17 11 23 58 分類 asp.net 舉報 字型大小 訂閱 public partial class frmmain form private void frmmain load object sender,eventargs e private void timedraw ...