jviana Posted March 24, 2012 at 10:00 AM Report #445443 Posted March 24, 2012 at 10:00 AM Se se lembrarem deste programa, servia para calcular a distância a que estava um trovão pelo intervalo clarão-som. Recentemente resolvi fazer um gráfico para o utilizador ver se a trovoada se estava a aproximar ou afastar. Tem 10 barras o gráfico. Sem nenhum trovão - A = distância máxima A | | | | __ __ __ __ __ __ __ __ __ __ 1º trovão x x __ __ __ __ __ __ __ __ __ __ 2º trovão x x x __ __ __ __ __ __ __ __ __ __ 3º trovão x x x x x x __ __ __ __ __ __ __ __ __ __ Estão a ver? Vai sempre andando para a esquerda. Já fiz este código Mas não estou a conseguir e não sei porque, alguém pode analisar o código e explicar-me o erro? Imports System.Windows.Forms.DataVisualization.Charting Public Class Form1 Dim numero As Integer Dim clarao As Boolean = True Dim distancia As Decimal Dim tempo As Decimal Dim temperatura As String Dim hora As String Private Inicio As DateTime Private SW As New Stopwatch ' Inicio do Y Dim y1 As Decimal = 0 Dim y2 As Decimal = 0 Dim y3 As Decimal = 0 Dim y4 As Decimal = 0 Dim y5 As Decimal = 0 Dim y6 As Decimal = 0 Dim y7 As Decimal = 0 Dim y8 As Decimal = 0 Dim y9 As Decimal = 0 'Fim do Y 'Inicio do x Dim x1 As Decimal = 0 Dim x2 As Decimal = 0 Dim x3 As Decimal = 0 Dim x4 As Decimal = 0 Dim x5 As Decimal = 0 Dim x6 As Decimal = 0 Dim x7 As Decimal = 0 Dim x8 As Decimal = 0 Dim x9 As Decimal = 0 'Fim do X 'define os valores do eixo y - milhoes de pessoas - 9 Dim newx As Decimal Dim newy As Decimal Dim ydistancia() As Double = {y1, y2, y3, y4, y5, y6, y7, y8, y9} 'define os valoes do eixo x - nome dos paises Dim xnumero() As String = {x1, x2, x3, x4, x5, x6, x7, x8, x9} Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load clarao = True newx = 0 newy = 0 grafico() graficoupdate() End Sub Private Sub graficoupdate() newy = distancia y1 = y2 y2 = y3 y3 = y4 y4 = y5 y5 = y6 y6 = y7 y7 = y8 y8 = y9 y9 = newy 'Fim do Y inicio do X x1 = x2 x2 = x3 x3 = x4 x4 = x5 x5 = x6 x6 = x7 x7 = x8 x8 = x9 x9 = newx + 1 Dim ydistancia() As String = {y1.ToString, y2.ToString, y3.ToString, y4.ToString, y5.ToString, y6.ToString, y7.ToString, y8.ToString, y9.ToString} Dim xnumero() As String = {x1.ToString, x2.ToString, x3.ToString, x4.ToString, x5.ToString, x6.ToString, x7.ToString, x8.ToString, x9.ToString} grafico() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ajuda.ShowDialog() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'cl = True = Clarão 'cl = False = Som! If clarao = True Then Button1.Text = "Som" Else Button1.Text = "Clarão" End If Select Case ComboBox1.Text Case -10 n10() Case -5 n5() Case 0 p0() Case 5 p5() Case 10 p10() Case 15 p15() Case 20 p20() Case 25 p25() Case 30 p30() End Select End Sub Sub p15() temperatura = 0 If clarao = True Then If ComboBox1.Text = "15" Then ComboBox1.Enabled = False numero = numero + 1 Timer2.Start() clarao = False Inicio = Now SW.Start() End If ElseIf clarao = False Then ComboBox1.Enabled = True clarao = True tempo = tempo Timer2.Stop() tempo = SW.ElapsedMilliseconds.ToString / 1000 SW.Stop() distancia = tempo * 340.5 temperatura = "15 ºC" hora = Now.Hour & ":" & Now.Minute & ":" & Now.Second & ":" & Now.Millisecond Dim newitem As New ListViewItem(numero) newitem.SubItems.Add(distancia) newitem.SubItems.Add(tempo) newitem.SubItems.Add(temperatura) newitem.SubItems.Add(hora) ListView1.Items.Add(newitem) newitem.EnsureVisible() SW.Reset() End If End Sub Private Sub grafico() With Chart1 'define o tipo de gráfico .Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Line 'define o texto da legenda .Series(0).LegendText = "Distância da Trovoada" .ChartAreas(0).Area3DStyle.LightStyle = LightStyle.Simplistic 'define o titulo do eixo y , sua fonte e a cor .ChartAreas(0).AxisY.Title = "Distância" .ChartAreas(0).AxisY.TitleFont = New Font("Times New Roman", 12, FontStyle.Bold) .ChartAreas(0).AxisY.TitleForeColor = Color.Blue 'define o titulo do eixo x , sua fonte e a cor .ChartAreas(0).AxisX.Title = "Graus Celcius" .ChartAreas(0).AxisX.TitleFont = New Font("Times New Roman", 12, FontStyle.Bold) .ChartAreas(0).AxisX.TitleForeColor = Color.Blue 'define a paleta de cores usada .Palette = ChartColorPalette.Fire 'vincula os dados ao gráfico .Series(0).Points.DataBindXY(xnumero, ydistancia) 'exibe os valores nos eixos .Series(0).IsValueShownAsLabel = True 'desabilita a exibição 3D .ChartAreas(0).Area3DStyle.Enable3D = True End With End Sub End Class Muito obrigado pela vossa ajuda Cumps. J.Viana Learning VB.Net HTML C/C++
ribeiro55 Posted March 24, 2012 at 10:28 AM Report #445444 Posted March 24, 2012 at 10:28 AM Sim, vai para a esquerda... e tu pretendes...? Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips"
jviana Posted March 24, 2012 at 11:32 AM Author Report #445450 Posted March 24, 2012 at 11:32 AM Não funciona, porque? Cumps J.Viana Learning VB.Net HTML C/C++
ribeiro55 Posted March 26, 2012 at 10:57 AM Report #445692 Posted March 26, 2012 at 10:57 AM O que é para ti "não funcionar" ? Não vou andar à caça de agulha nesse palheiro que aí meteste... 😄 Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips"
Blackvelvet Posted March 26, 2012 at 03:00 PM Report #445729 Posted March 26, 2012 at 03:00 PM Não percebo onde vais buscar o n() e o p() podias explicar melhor. If ComboBox1.Text = "-10" Then n10() ElseIf ComboBox1.Text = "-5" Then n5() ElseIf ComboBox1.Text = "0" Then p0() ElseIf ComboBox1.Text = "5" Then p5() e na minha modesta opinião eu trocava os if's por case . Fica melhor e a aplicação não fica muito "pesada" EDIT: GeSHi adicionado
jviana Posted March 27, 2012 at 07:57 AM Author Report #445846 Posted March 27, 2012 at 07:57 AM p10 = 10º C Positivos n5 = 5º C Negativos @ribeiro O problema é que o gráfico não adota novos valores e fica sempre igual, e não percebo qual é o erro Cumps. J.Viana EDIT: Querem o Source da aplicação, para verem melhor? Learning VB.Net HTML C/C++
jviana Posted April 1, 2012 at 07:49 AM Author Report #446851 Posted April 1, 2012 at 07:49 AM Decidi atualizar o tópico. Alguém me pode explicar porque o gráfico não executa as suas funções? Source: Download Cumps. J.Viana EDIT: Link com um bug e Select Case adaptado, obrigado Blackvelvet Learning VB.Net HTML C/C++
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now