need help in pie chart

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muddasirmunir
    Contributor
    • Jan 2007
    • 284

    #16
    first of all i am writing the coding which i am using on the click evnet
    of the button

    Code:
    salesrs.Open "SELECT DATENAME(mm, [date]) + ' ' + DATENAME(yy, [date]) AS Months, SUM([total(Credit)]-[total(debit)]) AS Amount FROM		 sales WHERE	 ([date] BETWEEN '" & fromdate & "' AND'" & todate & "') GROUP BY DATENAME(mm, [date]) + ' ' + DATENAME(yy, [date]), MONTH([date]), YEAR([date]) ORDER BY YEAR([date]), MONTH([date]) ", con, adOpenStatic, adLockReadOnly
    Set salesgraph.DataSource = salesrs
    If graphtype.Text = "Pie Graph" Then
    salesgraph.ChartType = VtChChartType2dPie
    ElseIf graphtype.Text = "Bar Graph" Then
    salesgraph.ChartType = VtChChartType2dBar
    ElseIf graphtype.Text = "Area Graph" Then
    salesgraph.ChartType = VtChChartType2dArea
    End If
    where salesgrpah is the name of graph
    and graphtype is the combobox where user can select
    type of graph

    also tell me how to change
    from

    a1 a2 a3 a4

    to
    a1
    a2
    a3
    a4

    which kadghar suggestion

    also qveena how can i use excel chart in vb,i develp my application
    in vb and sqlserver 2000 and the pictures i use to show in the link
    which i want to be is manually made by me in excel





    Originally posted by QVeen72
    Hi,

    Why dont you use Excel Chart itself..?
    It looks good and you can set all the parameters from the code..

    Regards
    Veena

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #17
      Hi,

      Showing Graph in Excel is quite Simple..
      Add Excel References to your Project and check this code:

      [code=vb]
      Dim i As Integer
      Dim exel As Object
      Dim WBEx As Object
      Dim TStr As String
      ' ******** Open Your Sales Recordset here *******
      If Not salesrs.EOF Then
      Set exel = CreateObject("E xcel.Applicatio n")
      Set WBEx = exel.Workbooks. Add
      exel.Visible = True
      salesrs.MoveFir st
      i = 0
      Do While ot salesrs.EOF
      i = i+1
      WBEx.Worksheets .Item("Sheet1") .Cells(i, 1) = (salesrs(0) & "")
      WBEx.Worksheets .Item("Sheet1") .Cells(i, 2) = (salesrs(1) & "")
      salesrs.MoveNex t
      Loop
      TStr = "A1:B" & Cstr(i)
      With exel
      .Charts.Add
      .ActiveChart.Ch artType = xl3DPie
      .ActiveChart.Se tSourceData Source:=Sheets( "Sheet1").Range (TStr), PlotBy:=xlColum ns
      .ActiveChart.Lo cation Where:=xlLocati onAsObject, name:="Sheet1"
      .ActiveChart.Ha sLegend = False
      .ActiveChart.Ap plyDataLabels Type:=xlDataLab elsShowLabelAnd Percent, LegendKey:=True , HasLeaderLines: =True
      End With
      '
      DoEvents
      '
      Set WBEx = Nothing
      Set exel = Nothing
      '
      End If
      [/code]

      Regards
      Veena

      Comment

      • kadghar
        Recognized Expert Top Contributor
        • Apr 2007
        • 1302

        #18
        Originally posted by muddasirmunir
        ...
        also tell me how to change
        from

        a1 a2 a3 a4

        to
        a1
        a2
        a3
        a4

        which kadghar suggestion...
        Check postst 11 and 12, but instead of Values and ValuesT, change 'salesrs', the array you're using.

        HTH

        Comment

        • muddasirmunir
          Contributor
          • Jan 2007
          • 284

          #19
          Hellow Qveen

          i had used the code for excel it is giving me just a circle in excel and
          not a pie chart i will try to upload a picture

          also on vb at the same the error
          "Sever is throuing an exception"
          Attached Files

          Comment

          • muddasirmunir
            Contributor
            • Jan 2007
            • 284

            #20
            Hellow Kadghar,

            first i am not understanding your post 11 and 12.
            can you please expalin in some easy way

            the code and query which i am using
            on click event of button is on post 16 see it


            and about data I had only two fields which i had to show in graphs
            like this in database

            Code:
             
            Month			Sales
            Jan				 10000 
            Feb				 5000
            Mar				 8000
            can you make a pie chart from it , if there is error in my coding tell
            me

            Comment

            • kadghar
              Recognized Expert Top Contributor
              • Apr 2007
              • 1302

              #21
              Originally posted by muddasirmunir
              Hellow Kadghar,

              first i am not understanding your post 11 and 12.
              can you please expalin in some easy way

              the code and query which i am using
              on click event of button is on post 16 see it
              I'll assume 'salesrs' is a Recordset, I'll put it into an array and then give you a couple of possible solutions. Im not sure of any, since i'm not very good using charts. But i'll put the posible combinations of the arrays orders, so any of them should fit what the MSChart needs to get what you need.

              You're code should be fine, but now lets add some lines betwen the first and second ones, i.e. before the DataSource method.

              Solution1:

              [CODE=vb]Dim a
              a = salesrs.getrows[/CODE]
              and replace the second line with:
              [CODE=vb]Set salesgraph.Data Source = a[/CODE]

              Solution2:
              [CODE=vb]dim a
              dim b()
              dim i as long
              dim j as long
              a = salesrs.getrows
              redim b (ubound(a,2), ubound(a))
              for i = lbound(a,2) to ubound(a,2)
              for j = lbound(a) to ubound(a)
              b(i,j) = a(j,i)
              next
              next[/CODE]
              and replace the second line with
              [CODE=vb]Set salesgraph.Data Source = b[/CODE]

              I hope this helps you... but im not sure, since the code Veena provided seems to assume 'salesrs' is a recordset too, and it showed you a server's error...
              By the way, one good way to check Veena's code will be, once the excel application is open and visible, check if the data was written in the first sheet.

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #22
                Originally posted by muddasirmunir
                Hellow Qveen

                i had used the code for excel it is giving me just a circle in excel and
                not a pie chart i will try to upload a picture

                also on vb at the same the error
                "Sever is throuing an exception"
                Hi
                after Modifying to your Requirements, can you post the Code here...?

                REgards
                Veena

                Comment

                • muddasirmunir
                  Contributor
                  • Jan 2007
                  • 284

                  #23
                  i got it now,by using code to export to excel by QVeena
                  i am previously not opening the recorset that why it is giving me the error


                  Thank Qveena, Kadghar and other expert.Fianlly , it is decided that we can not make we can not make this type of chart in vb rather we have to export it to excel.
                  Also if any body know some other controls of chart please give me names
                  Thanks Again

                  Comment

                  • QVeen72
                    Recognized Expert Top Contributor
                    • Oct 2006
                    • 1445

                    #24
                    Hi,

                    Use Crystal-Reports, the Chart control there looks very good..

                    Regards
                    Veena

                    Comment

                    Working...