¿Cómo mostrar datos en tiempo real con un gráfico en VB?
VB puede mostrar la curva de los datos recopilados en tiempo real utilizando el método Line o el método PSet para dibujar líneas y colores en el evento Timer del control Timer.
El método Línea dibuja líneas y rectángulos en objetos.
El método PSet se utiliza para establecer puntos en el objeto en un color específico.
El siguiente es un fragmento de código de programa de control industrial que utiliza el método Línea:
Opción?Explicit
Dim?quitflag?As?Boolean
Dim?cmdXianshiFlag?As?Boolean
Dim?cmdTestFlag?As Boolean
Dim?p?As Integer
Dim?h?As Integer
¿Dim?miao1?Como un número entero
Dim?fen1?Como un número entero
Dim?j?As?Integer
Dim? ii?Como?Entero
Privado?br_br?Como?Doble
Privado?ab_bm?Doble
Privado?wwy_wy?Como?Doble
¿Privado?shijian(360)?¿Como?Cadena?*?10
¿Privado?shijian_zh(360)?¿Como?Cadena?*?10
Privado?record_zh(5, ?360)?Como?Único
¿Privado?record(5,?360)?Como?Único
Privado?c(360) como variable
Const ?a=?3.141592654?*?2
Función pública xp (colvb como variable, xx como variable, yy como variable, txt como variable)
Imagen1. ForeColor?=?colvb ?'QBColor(14)
Imagen1.CurrentX?=?xx
Imagen1.ForeColor?
Imagen1.CurrentX?=?xx
Imagen1.CurrentY?=?yy
Imagen1.Imprimir?txt?
Fin?Función
Privado?Sub?CmdTest_Click( )
¿Si?cmdTestFlag?Entonces
¿Para?j?=?0?
record(0,?j =?0
?registro( 1,?j)? =?0
registro(2,?j)? =?0
registro(3,?j)?
registro(4,?j)? =?0
registro(5,?j)?0
¿Siguiente?Prueba"
De lo contrario
¿Para?j?=?0?A?359
c(j)?=?j?*?a?/?60
registro( 0,?j)?=?Sin(c(j))?*?-450
registro(1,?j)? =?Sin(c(j))? *?-300
registro(2,?j)? ?a?/?3)?*?-450
registro(3,?j)? ?a?/? 3)?*?-450
registro(4,?j)? =?Sin(c(j)? ?2?*?a?/?3)?*? -300
record(5,?j)? =?Sin(c(j)? ?2?*?a?/?3)?*El resultado de esto es que la intersección de los dos puntos de intersección
El número de puntos es igual.
-150
Siguiente?j
cmdTest.Caption?=?"Registro"
Fin?Si
cmdTestFlag?=?No ?cmdTestFlag
Fin?Sub
Privado?Sub?Timer1_Timer()
If?lblTime.Caption?lt;?CStr(Time$)? Entonces
lblTime.Caption?=?Time$
Frmjly.Caption?=?" Logger"?Logger"? amp;?Space(90)? amp;?Date$? &?Espacio(6)? &?Tiempo$
miao1?=?Mid(lblTiempo,?7,?2)
fen1?=?Mid(Tiempo$, ?4 ,?2)
Si?fen1?=?0?Y?miao1?=?0?Entonces
shijian(0)? =?lblTime
¿Fin?Si
Etiqueta1?=?lblTime
Si?miao1?=?0?Entonces
Para?k?=?0?A? /p>
record_zh(0,?k? ?1)? =?record(0,?k)
record_zh(1,?k? ?1)? ?k)
record_zh(2,?k? ?1)? =?record(2,?k)
record_zh(3,?k? ?1)? =?record(3,?k)
record_zh(4,?k? ?1)? =?record(4,?k)
record_zh(5,? k? ?1)? =?registro(5,?k)
Siguiente?k
Para?j?=?1?A?9
registro( 0,?j)? =?record_zh(0,?j)
registro(1,?j)? =?record_zh(1,?j)
registro( 2, ?j)? =?record_zh(2,?j)
registro(3,?j)? =?record_zh(3,?
registro(4,?j)? =?record_zh(4,?j)
record(5,?j)? =?record_zh(5,?j)
Siguiente?j
¿Fin?Si
Si?fen1?=?0?Y?miao1?=?1?Entonces
¿Para?ii?=?0?A?
shijian_zh(ii? ?1)? =?shijian(ii)
Siguiente?ii
Para?h?=?1?A?6
Shijian(h)? =?shijian_zh(h)
Siguiente?h
Etiqueta1.Visible?=?False
Etiqueta2.Visible?=? /p>
¿Fin?Si
¿Fin?Si
Fin?Sub
Privado?p>Privado?Sub?Timer2_Timer()
BitBlt?Me.Picture1.hDC,?0,?0,?Me.Picture1.ScaleWidth,?Me.Picture1.ScaleHeight,?0,?0,?0,?vbBlack ?'ness
Texto1 ?=?Tiempo$
miao?=?Derecho$(Tiempo$,?2)
Texto2?=?fen1
registro(0,?0 )? =?record_jm(3)?*?-30
registro(1,?0)? =?record_jm(4)?*?-30
registro(2, ?0)? =?record_jm(5)?*?-30
registro(3,?0)? =?record_jm(0)?*?-30
registro( 4,?0)? =?record_jm(1)?*?-30
record(5,?0)? =?record_jm(10)?*?-30?'Secado al vacío p> p>
mmm?=?Val(fen1?*?60)? ?Val(miao)
j?=?mmm
p?=?(j ?/ ?360)?-?Int(j?/?360)
j?=?p?*?360
Texto2?=?Fecha$
Etiqueta8?=?Fecha$
Etiqueta2?=?shijian(1)
Etiqueta2.Left?=?fen1?*?30?Left?=?fen1?*? 30? ?1800?*?1? ?140
Etiqueta3?=?shijian(2)
Etiqueta3.Left?=?fen1?*?30? 1?140
Etiqueta4?=?shijian(3)
Etiqueta4.Left?=?fen1?*Left?=?fen1?*?30? 2?140
Label5?=?shijian(4)
Label5.Label6.Left?Label6.Left?=?fen1?*?30? ? 140
Label7?=?shijian(6)
Label7.p>colvb?=?vbWhite
xx?=?100
yy?=?150
txt?=?"℃"
wp?=?xp(colvb,?xx,?yy,?txt)
yy?=?350
txt?=?"100"
wp?=?xp(colvb,?xx,?yy,?txt)
xx?=?200
yy?=?1850
txt?=?"50"
wp?=?xp(colvb,? xx, ?yy,?txt)
yy?=?3350
xx?=?300
txt?=?"0"
wp?=?xp(colvb,?xx,?yy,?txt)
xx?=?100
yy?=?4850
txt ?=?"-50"
wp?=?xp(colvb,?xx,?yy,?txt)
xx?=?0
yy?=?6350
t
xt?=?"-100"
wp?=?xp(colvb,?xx,?yy,?txt)
'Coordenadas de vacío
colvb ?=?vbRed
xx?=?11500
yy?=?150
txt?=?"Pa"
wp ?=?xp(colvb,?xx,?yy,?txt)
yy?=?350
txt?=?"10000"
wp ?=?xp(colvb,?xx,?yy,?txt)
xx?=?11500
yy?=?1850
txt?= ?"1000"
wp?=?xp(colvb,?xx,?yy,?txt)
yy?=?3350
xx?= ?11500
txt?=?"100"
wp?=?xp(colvb,?xx,?yy,?txt)
xx?= ?11500
yy?=?4850
txt?=?"10"
wp?=?xp(colvb,?xx,?yy,? txt)
xx?=?11500
yy?=?6350
txt?=?"1"
wp?= ?xp(colvb,?xx,?yy,?txt)
xx?=?500
yy?=?150
txt?=?" Pa"
wp?=?xp(colvb,?xx,?yy,?txt)
yy?=?350
txt?=?" 10000"
wp?=?xp(colvb,?xx,?yy,?txt)
xx?=?500
yy?=?1850
txt?=?"1000"
wp?=?xp(colvb,?xx,?yy,?txt)
yy?=?3350
xx?=?500
txt?=?"100"
wp?=?xp(colvb,?xx,?yy,?txt)
xx?=?500
yy?=?4850
txt?=?"10"
wp?=?xp (colvb,?xx,?yy,?txt)
xx?=?500
yy?=?6350
txt?=?"1"
wp?=?xp(colvb,?xx,?yyy,?txt)
'Marco de dibujo
Imagen1.ForeColor?=?vbWhite p> p>
Imagen1.Línea?Línea?(450,?400)-(11300,?400)
Imagen1.Línea?(450,?700)-(500,?700)
Imagen1.Línea?(450,?1000)-(500,?1000)
Imagen1.Línea?(450,?1300)-(500,?1300)
Imagen1.Línea ?( 450,?1600)-(500,?1600)
Imagen1.ForeColor?=?vbRed
Imagen1.Line?(500,?566.7)-(550,? 566.7)
P
imagen1.Línea?(500,?733.3)-(550,?733.3)
Imagen1.Línea?(500,?900)-(550,?900)
Imagen1. ¿Línea?(500,?1066.7)-(550,?1066.7)
Imagen 1. ¿Línea?(500,?1233.3)-(550,?1233.3)
Imagen1.Línea?(500,?1400)-(550,?1400)
Imagen1.Línea?(500,?1566.7)-(550,?1566.7)
Imagen1. ¿Línea?(500,?1733.3)-(550,?1733.3)
Imagen1.¿Línea?(500,?2066.7)-(550,?2066.7)
Imagen1.¿Línea? (500,?2233.3)-(500,?2233.3)
Imagen1.Línea?(500,?2233.3)-(500,?2233.3)
Imagen1.Línea?(500 ,?2233.3)-(550,?2233.3)
Imagen1.Línea?(500,?2400)-(550,?2400)
Imagen1.Línea?(500,? 2566.7)-(550,?2566.7)
Imagen1.Línea?(500,?2733.3)-(550,?2733.3)
Imagen1.Línea?(500,?2900) -(550,?2900)
Imagen1.Línea?(500,?3066.7)-(550,?3066.7)
Imagen1. p>Imagen1.Línea?(500,? 3233.3)-(550,?3233.3)
Imagen1.Línea?(500,?3566.7)-(550,?3566.7)
Imagen1.Línea?(500,?3733.3) -(550,?3733.3)
Imagen1.Línea?(500,?3900)-(550,?3900)
Imagen1.Línea?(500,?4066.7)-( 550,?4066.7)
Imagen1.Línea?(500,?4233.3)-(550,?4233.3)-(550,?4266.7)
Imagen1.Línea?(500, 4233.3)-(550, 4233.3)
Imagen1.Línea?(500, 4400)-(550, 4400)
Imagen1.Línea?(500, 4566.7 )-(550 ,?4566.7)
Imagen1.Línea?(500,?4733.3)-(550,?4733.3)
Imagen1.Línea?(500,?5066.7)- (550,? 5066.7)
Imagen1.p>
Imagen1. ¿Línea?(500,?5400)-(550,?5400)
Imagen1. ,?5566.7)-(550,?55
66.7)
Imagen1.Línea?(500,?5733.3)-(550,?5733.3)
Imagen1.Línea?(500,?5900)-(550,?5900 )
Imagen1.Línea?(500,?6066.7)-(550,?6066.7)
Imagen1.Línea?(500,?6233.3)-(550,?6233.3) p>
Imagen1.ForeColor?=?vbWhite
Imagen1.Line?(450,?1900)-(11300,?1900)
Imagen1.Line?(450, ? 2200)-(500,?2200)
Imagen1.Línea?(450,?2500)-(500,?2500)
Imagen1.Línea?(450,? 2800) )-(500,?2800)
Imagen1.Línea?(450,?3100)-(500,?3100)
Imagen1.Línea?(450,?3400) - (11300,?3400)
Imagen1.Línea?(450,?3700)-(500,?3700)
Imagen1.Línea?(450,?4000)-( 500 ,?4000)
Imagen1.Línea?(450,?4300)-(500,?4300)
Imagen1.Línea?(450,?4600)-(500,? 4600)
Imagen1.Línea?(450,?4900)-(11300,?4900)
Imagen1.Línea?(450,?5200)-(500,?5200 )
Imagen1.Imagen1.Línea?(450,?5800)-(500,?5800)
Imagen1.Línea?(450,?6100)-(500,?6100 )
Imagen1.Línea?(450,?6400)-(11300,?6400)
Imagen1.Línea?(500,?400)-(500,?6400) p>
Imagen1.Line?(11300,?400)-(11300,?6400)
'Dibujar coordenadas de tiempo
'Picture1.ForeColor?=? p>
Si?? ?fen1?*?30?gt;?200?Entonces
Imagen1.Línea?(-400? ?fen1?*?30,?400)-(- 400 ? ?fen1?*?30,?6400)
¿Fin?Si?
Imagen1.Línea?(500? ?fen1?*?30,?400)-(500 ? ?fen1?*?30,?6400)
Imagen1.Línea?(1400? ?fen1?*?30,?400)-(1400? ?fen1?*?30,?6400) p>
Imagen1.?6400)
Imagen1.Línea?(2300? ?fen1?*?30,?400)-(2300? ?fen1?*?30,?6400) pag
>
Imagen1.fen1?*?30,?6400)
Imagen1.Línea?(4100? ?fen1?*?30,?400)-(4100? ?fen1?*?30, ?6400)
Imagen1.(5000? ?fen1?*?30,?6400)
Imagen1.Línea?(5900? ?fen1?*?30,?400)- (5900? ?fen1?*?30,?6400)
Imagen1.Línea?(6800? ?fen1?*?30,?400)
Imagen1.Línea?(6800 ?fen1?*?30,?400)-(6800? ?fen1?*?30,?6400)
Imagen1.Línea?(7700? ?fen1?*?30,?400)- (7700? ?fen1?*?30,?6400)
Imagen1.Línea?(8600? ?fen1?*?30,?6400)
Imagen1.?fen1?* ?30,?400)-(8600? ?fen1?*?30,?6400)
Imagen 1. ¿Línea?(9500? ?fen1?*?30, ?400)-(9500? ?fen1 ?*?30,?6400)
Si?10400??fen1?*?30?lt;?11300?Entonces
Imagen1.Línea?(10400??fen1?* ?30,?400)-(10400? ?fen1?*?30,?6400)
Fin?Si
Si?11300 entonces
Imagen1. Línea(11300? ?fen1?*?30,?400)-(11300? ?fen1?*?30,?6400)
Fin?Si
'Mostrar registro p> p>
Imagen1.ForeColor?=?vbAmarillo
For?j?=?0?To?359
Imagen1.Línea?(j?*?30? ?500 ,?record(0,?j)??3395)-(j?*?30??502,?record(0,?j)??3405),?vbRed,?BF
Imagen1 .Línea?(j?*?30? ?500,?registro(1,?j)? ?3395)-(j?*?30? ?502,?registro(1,?j)? ?3405) ,? QBColor(7),?BF
Imagen1.Línea?(j?*?30? ?500, ?record(2,?j)? ?3395)-(j?*?30? ?502 ,?record(2,?j)??3405),?vbWhite,?BF
Imagen1.Línea?(j?*?30??500,?record(3,?j) ? 3395)-(j?*?30? ?502,?record(3,?j)? ?3405),?vbAmarillo,?BF
Imagen1.Línea?(j?*?30 ? 500,?record(4,?j)??3395)-(j?*?30??502,?record(4,?j)??3405),?vbVerde,?BF
si reco
rd(5,?j)?/? -30?lt;?10?Entonces
wy_wy?=?-0 ?166.7
br_br?=?5.5556
ElseIf?record(5,?j)?/? -30? gt;=?10?y?record(5,?j)?/? -30? lt;? 100? Entonces
wy_wy? -1500?166.7
br_br?=?0.5555
ElseIf?record(5,?j)?=?100?And?record(5,?j)?/Entonces
wy_wy=? -3000? ?166.7
br_br?=?0.055555
ElseIf?record(5,?j)?/? -30?gt;=?1000?And?record(5) ,?j)?/? -30?lt;?10000?Entonces
wy_wy?=?-4500 ?166.7
br_br?=?0.0055555
Fin?Si
Imagen1.Línea?(j?*?30? ?500,?record(5,?j)?*?br_br? ?wy_wy? ?3395? ?3000)-(j ?*?30? ?502,?registro(5,?j)?*?br_br? ?wy_wy?3405,?QBColor(11),?BF
Siguiente?j
Imagen1.Actualizar
¿Fin?