none
Como faço para criar grafico com dataset contendo três tabelas? RRS feed

  • Pergunta

  • Boa noite a todos!
    Estou com dificuldades para apresentar os dados das tabelas abaixo em um gráfico ou seja mostrar no gráfico
    Três colunas distintas em uma mesma area, a quem puder ajudar-me agradeço!
    Segue fragmento do código que estou utilizando em minha aplicação!

    Dim tblFields As String = "SELECT * from tbRelGrafVenda Order By CodPizzaFormula, Dia" Dim tblField1 As String = "SELECT * from tbRelGrafVend1 Order By CDPF1, Dia1" Dim tblField2 As String = "SELECT * from tbRelGrafVend2 Order By CDPF2, Dia2" '~~> Connecting to Data base and storing the data in a dataset Dim oCmd As New OleDbCommand(tblFields, gCN) Dim oData As New OleDbDataAdapter(tblFields, gCN) Dim oCmd1 As New OleDbCommand(tblField1, gCN) Dim oDat1 As New OleDbDataAdapter(tblField1, gCN) Dim oCmd2 As New OleDbCommand(tblField2, gCN) Dim oDat2 As New OleDbDataAdapter(tblField2, gCN) Dim ds As New DataSet If gCN.State = ConnectionState.Open Then gCN.Close() gCN.Open() oData.Fill(ds, "tbRelGrafVenda") oDat1.Fill(ds, "tbRelGrafVend1") oDat2.Fill(ds, "tbRelGrafVend2") gCN.Close() ''''''''''''''''''''''''''''' '~~> SET DATA SOURCE <~~' ''''''''''''''''''''''''''''' Chart1.DataSource = ds <----- Não está carregando as três tabelas aqui '''''''''''''''''''''''''''''''' '~~> WORKING WITH CHARTAREA <~~' '''''''''''''''''''''''''''''''' Dim CArea As ChartArea = Chart1.ChartAreas(0) CArea.BackColor = Color.Azure '~~> Changing the Back Color of the Chart Area CArea.ShadowColor = Color.Red '~~> Changing the Shadow Color of the Chart Area CArea.Area3DStyle.Enable3D = False '~~> Changing the Chart Style Not 3D '~~> Formatting X Axis CArea.AxisX.MajorGrid.Enabled = False '~~> Removed the X axis major grids CArea.AxisX.LabelStyle.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Italic) '~~> Setting Font, Font Size and Italicizing CArea.AxisX.Interval = 1 CArea.AxisX.Maximum = 31 CArea.AxisX.Minimum = 1 '~~> Formatting Y Axis CArea.AxisY.MinorGrid.Enabled = True '~~> Removed the Y axis major grids CArea.AxisY.LabelStyle.Format = "000" '~~> Formatting Y axis to display values in %age CArea.AxisY.Interval = 4 '~~> Formatting Y axis Interval to 20% CArea.AxisY.Minimum = 1 '''''''''''''''''''''''''''' '~~> WORKING WITH TITLE <~~' '''''''''''''''''''''''''''' '~~> Adding a Title Dim T As Title = Chart1.Titles.Add("Relatório de Vendas - MES") '~~> Formatting the Title With T .ForeColor = Color.Black '~~> Changing the Fore Color of the Title .BackColor = Color.White '~~> Changing the Back Color of the Title '~~> Setting Font, Font Size and Bold/Italicizing .Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold) .Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Underline) .BorderColor = Color.Black '~~> Changing the Border Color of the Title .BorderDashStyle = ChartDashStyle.NotSet '~~> Changing the Border Dash Style of the Title End With ''''''''''''''''''''''''''''' '~~> WORKING WITH SERIES <~~' ''''''''''''''''''''''''''''' '~~> Assigning values to X and Y Axis If ds.Tables("tbRelGrafVenda").Columns.Contains("Dia") Then Chart1.Series(0).LabelFormat = "00" Chart1.Series(0).XValueMember = "Dia" Chart1.Series(0).YValueMembers = "TotQtd" Chart1.Series(0).Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold) Chart1.Series(0).YValueType = ChartValueType.Double Chart1.Series(0).IsValueShownAsLabel = False Chart1.Series(0).LabelForeColor = Color.DarkGreen End If 'If ds.Tables("tbRelGrafVend1").Columns.Contains("Dia1") Then ' Chart1.Series(1).LabelFormat = "00" ' Chart1.Series(1).XValueMember = "Dia1" <--------- Aqui diz que não encontrou o campo "Dia1" ' Chart1.Series(1).YValueMembers = "TotQtd1" ' Chart1.Series(1).Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold) ' Chart1.Series(1).YValueType = ChartValueType.Double ' Chart1.Series(1).IsValueShownAsLabel = False ' Chart1.Series(1).LabelForeColor = Color.Red ' MsgBox("Coluna dia1 encontrada") <---------------------- Aqui mostra que achou o campo! 'End If

    Att.

    Dilson J. Hasselmann Desenvolvedor VB.NET

    sábado, 18 de abril de 2015 05:41

Respostas

  • Private Sub Monta_Grafico()
    
          Dim tblFields As String = "SELECT * from tbRelGrafVenda Order By CodPizzaFormula, Dia"
    
          '~~> Connecting to Data base and storing the data in a dataset
          Dim oCmd As New OleDbCommand(tblFields, gCN)
          Dim oData As New OleDbDataAdapter(tblFields, gCN)
    
          Dim ds As New DataSet
    
          If gCN.State = ConnectionState.Open Then gCN.Close()
          gCN.Open()
    
          oData.Fill(ds, "tbRelGrafVenda")
          gCN.Close()
    
          '''''''''''''''''''''''''''''
          '~~> SET DATA SOURCE <~~'
          '''''''''''''''''''''''''''''
          Chart1.DataSource = ds.Tables("tbRelGrafVenda")
    
          ''''''''''''''''''''''''''''''''
          '~~> WORKING WITH CHARTAREA <~~'
          ''''''''''''''''''''''''''''''''
          Dim CArea As ChartArea = Chart1.ChartAreas(0)
    
          CArea.BackColor = Color.DarkOliveGreen  '~~> Changing the Back Color of the Chart Area 
          CArea.BackGradientStyle = GradientStyle.TopBottom
          CArea.ShadowColor = Color.Red           '~~> Changing the Shadow Color of the Chart Area 
          CArea.ShadowColor = Color.Red           '~~> Changing the Shadow Color of the Chart Area 
          CArea.Area3DStyle.Enable3D = False      '~~> Changing the Chart Style Not 3D 
    
          '~~> Formatting X Axis
          CArea.AxisX.MajorGrid.Enabled = False   '~~> Removed the X axis major grids
          CArea.AxisX.LabelStyle.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Italic) '~~> Setting Font, Font Size and Italicizing
          CArea.AxisX.Interval = 1
          CArea.AxisX.Maximum = 31
          CArea.AxisX.Minimum = 1
    
          '~~> Formatting Y Axis
          CArea.AxisY.MinorGrid.Enabled = False   '~~> Removed the Y axis major grids
          CArea.AxisY.LabelStyle.Format = "000"   '~~> Formatting Y axis to display values in %age
          CArea.AxisY.Interval = 2                '~~> Formatting Y axis Interval to 20%
    
          ''''''''''''''''''''''''''''
          '~~> WORKING WITH TITLE <~~'
          ''''''''''''''''''''''''''''
          '~~> Adding a Title
          Dim T As Title = Chart1.Titles.Add("Relatório de Vendas - MES")
    
          '~~> Formatting the Title
          With T
             .ForeColor = Color.Black            '~~> Changing the Fore Color of the Title 
             .BackColor = Color.White            '~~> Changing the Back Color of the Title 
             '~~> Setting Font, Font Size and Bold/Italicizing
             .Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
             .Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Underline)
             .BorderColor = Color.Black                   '~~> Changing the Border Color of the Title 
             .BorderDashStyle = ChartDashStyle.NotSet  '~~> Changing the Border Dash Style of the Title 
          End With
    
          '''''''''''''''''''''''''''''
          '~~> WORKING WITH SERIES <~~'
          '''''''''''''''''''''''''''''
          '~~> Assigning values to X and Y Axis
    
          'Tamanho Grande
          Chart1.Series(0).LabelFormat = "00"
          Chart1.Series(0).XValueMember = "Dia"
          Chart1.Series(0).YValueMembers = "TotQtd"
          Chart1.Series(0).Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
          Chart1.Series(0).YValueType = ChartValueType.Double
          Chart1.Series(0).IsValueShownAsLabel = False
    
          'Tamanho Médio
          Chart1.Series(1).LabelFormat = "00"
          Chart1.Series(1).XValueMember = "Dia"
          Chart1.Series(1).YValueMembers = "TotQtd1"
          Chart1.Series(1).Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
          Chart1.Series(1).YValueType = ChartValueType.Double
          Chart1.Series(1).IsValueShownAsLabel = False
    
          'Tamanho Broto
          Chart1.Series(2).LabelFormat = "00"
          Chart1.Series(2).XValueMember = "Dia"
          Chart1.Series(2).YValueMembers = "TotQtd2"
          Chart1.Series(2).Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
          Chart1.Series(2).YValueType = ChartValueType.Double
          Chart1.Series(2).IsValueShownAsLabel = False
    
          '''''''''''''''''''''''''''''
          '~~> WORKING WITH LEGEND <~~'
          '''''''''''''''''''''''''''''
          Dim LG As Legend = Chart1.Legends(0)
          '~~> Changing the Back Color of the Legend 
          LG.BackColor = Color.Wheat
          '~~> Changing the Fore Color of the Legend
          LG.ForeColor = Color.DarkSlateBlue
          '~~> Setting Font, Font Size and Bold
          LG.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
          '~~> Assigning a title for the legend
          LG.Title = "Legenda"
    
          '~~> Setting the location for the chart
          Chart1.Size = New System.Drawing.Size(1232, 594)
          Chart1.Location = New Point(12, 68)
    
       End Sub

    Pronto, espero poder ajudar a quem estiver com a mesma dificuldade, agora só preciso saber como limpar o gráfico para colocar novos dados?

    Att.


    Dilson J. Hasselmann Desenvolvedor VB.NET

    segunda-feira, 20 de abril de 2015 14:14
  • Problema resolvido!

    Obrigado a todos pela atenção!

    Att.


    Dilson J. Hasselmann Desenvolvedor VB.NET

    • Marcado como Resposta DJHasselmann sábado, 18 de abril de 2015 22:38
    sábado, 18 de abril de 2015 22:38

Todas as Respostas

  • Problema resolvido!

    Obrigado a todos pela atenção!

    Att.


    Dilson J. Hasselmann Desenvolvedor VB.NET

    • Marcado como Resposta DJHasselmann sábado, 18 de abril de 2015 22:38
    sábado, 18 de abril de 2015 22:38
  • Bom dia DJ,

    Que bom que resolveu seu problema. Poderia nos postar aqui como fez para que isso fosse resolvido? Assim, facilitará quando outra pessoa passe pela mesma situação.

    Qualquer nova dúvida estamos à disposição.

    Obrigado,

    Abraço!


    Eduardo Romero

    Esse conteudo e fornecido sem garantias de qualquer tipo, seja expressa ou implicita.

    MSDN Community Support

    Por favor, lembre-se de Marcar como Resposta as respostas que resolveram o seu problema. Essa e uma maneira comum de reconhecer aqueles que o ajudaram e fazer com que seja mais facil para os outros visitantes encontrarem a resolucao mais tarde.

    segunda-feira, 20 de abril de 2015 12:33
    Moderador
  • Private Sub Monta_Grafico()
    
          Dim tblFields As String = "SELECT * from tbRelGrafVenda Order By CodPizzaFormula, Dia"
    
          '~~> Connecting to Data base and storing the data in a dataset
          Dim oCmd As New OleDbCommand(tblFields, gCN)
          Dim oData As New OleDbDataAdapter(tblFields, gCN)
    
          Dim ds As New DataSet
    
          If gCN.State = ConnectionState.Open Then gCN.Close()
          gCN.Open()
    
          oData.Fill(ds, "tbRelGrafVenda")
          gCN.Close()
    
          '''''''''''''''''''''''''''''
          '~~> SET DATA SOURCE <~~'
          '''''''''''''''''''''''''''''
          Chart1.DataSource = ds.Tables("tbRelGrafVenda")
    
          ''''''''''''''''''''''''''''''''
          '~~> WORKING WITH CHARTAREA <~~'
          ''''''''''''''''''''''''''''''''
          Dim CArea As ChartArea = Chart1.ChartAreas(0)
    
          CArea.BackColor = Color.DarkOliveGreen  '~~> Changing the Back Color of the Chart Area 
          CArea.BackGradientStyle = GradientStyle.TopBottom
          CArea.ShadowColor = Color.Red           '~~> Changing the Shadow Color of the Chart Area 
          CArea.ShadowColor = Color.Red           '~~> Changing the Shadow Color of the Chart Area 
          CArea.Area3DStyle.Enable3D = False      '~~> Changing the Chart Style Not 3D 
    
          '~~> Formatting X Axis
          CArea.AxisX.MajorGrid.Enabled = False   '~~> Removed the X axis major grids
          CArea.AxisX.LabelStyle.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Italic) '~~> Setting Font, Font Size and Italicizing
          CArea.AxisX.Interval = 1
          CArea.AxisX.Maximum = 31
          CArea.AxisX.Minimum = 1
    
          '~~> Formatting Y Axis
          CArea.AxisY.MinorGrid.Enabled = False   '~~> Removed the Y axis major grids
          CArea.AxisY.LabelStyle.Format = "000"   '~~> Formatting Y axis to display values in %age
          CArea.AxisY.Interval = 2                '~~> Formatting Y axis Interval to 20%
    
          ''''''''''''''''''''''''''''
          '~~> WORKING WITH TITLE <~~'
          ''''''''''''''''''''''''''''
          '~~> Adding a Title
          Dim T As Title = Chart1.Titles.Add("Relatório de Vendas - MES")
    
          '~~> Formatting the Title
          With T
             .ForeColor = Color.Black            '~~> Changing the Fore Color of the Title 
             .BackColor = Color.White            '~~> Changing the Back Color of the Title 
             '~~> Setting Font, Font Size and Bold/Italicizing
             .Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
             .Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Underline)
             .BorderColor = Color.Black                   '~~> Changing the Border Color of the Title 
             .BorderDashStyle = ChartDashStyle.NotSet  '~~> Changing the Border Dash Style of the Title 
          End With
    
          '''''''''''''''''''''''''''''
          '~~> WORKING WITH SERIES <~~'
          '''''''''''''''''''''''''''''
          '~~> Assigning values to X and Y Axis
    
          'Tamanho Grande
          Chart1.Series(0).LabelFormat = "00"
          Chart1.Series(0).XValueMember = "Dia"
          Chart1.Series(0).YValueMembers = "TotQtd"
          Chart1.Series(0).Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
          Chart1.Series(0).YValueType = ChartValueType.Double
          Chart1.Series(0).IsValueShownAsLabel = False
    
          'Tamanho Médio
          Chart1.Series(1).LabelFormat = "00"
          Chart1.Series(1).XValueMember = "Dia"
          Chart1.Series(1).YValueMembers = "TotQtd1"
          Chart1.Series(1).Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
          Chart1.Series(1).YValueType = ChartValueType.Double
          Chart1.Series(1).IsValueShownAsLabel = False
    
          'Tamanho Broto
          Chart1.Series(2).LabelFormat = "00"
          Chart1.Series(2).XValueMember = "Dia"
          Chart1.Series(2).YValueMembers = "TotQtd2"
          Chart1.Series(2).Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
          Chart1.Series(2).YValueType = ChartValueType.Double
          Chart1.Series(2).IsValueShownAsLabel = False
    
          '''''''''''''''''''''''''''''
          '~~> WORKING WITH LEGEND <~~'
          '''''''''''''''''''''''''''''
          Dim LG As Legend = Chart1.Legends(0)
          '~~> Changing the Back Color of the Legend 
          LG.BackColor = Color.Wheat
          '~~> Changing the Fore Color of the Legend
          LG.ForeColor = Color.DarkSlateBlue
          '~~> Setting Font, Font Size and Bold
          LG.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
          '~~> Assigning a title for the legend
          LG.Title = "Legenda"
    
          '~~> Setting the location for the chart
          Chart1.Size = New System.Drawing.Size(1232, 594)
          Chart1.Location = New Point(12, 68)
    
       End Sub

    Pronto, espero poder ajudar a quem estiver com a mesma dificuldade, agora só preciso saber como limpar o gráfico para colocar novos dados?

    Att.


    Dilson J. Hasselmann Desenvolvedor VB.NET

    segunda-feira, 20 de abril de 2015 14:14