locked
how to make pie chart RRS feed

  • Question

  • User66371569 posted

    hi people

    I have this query

    select Dept_en Department,nvl(TRIM(TO_CHAR(sum(VACATION_AMOUNT), '999,999,999,999,999')),0) Vacation,TRIM(TO_CHAR(sum(GOSI_C), '999,999,999,999,999'))Gosi,TRIM(TO_CHAR(sum(MEDICAL_INS_C), '999,999,999,999,999'))Medical,TRIM(TO_CHAR(sum(ROUND (650 / 12)), '999,999,999,999,999')) Iqama,  TRIM(TO_CHAR(sum(ROUND (7300 / 12)), '999,999,999,999,999')) Labor,TRIM(TO_CHAR(sum(ROUND (200 / SUBSTR (CONTRACT_PERIODS, 1, 2))) , '999,999,999,999,999')) Reentry, TRIM(TO_CHAR(nvl(sum(TICKET_C),0)+ nvl(sum(VACATION_AMOUNT),0)+sum(GOSI_C)+sum(MEDICAL_INS_C)+sum(ROUND (650 / 12))+sum(ROUND (7300 / 12))+sum(ROUND (200 / SUBSTR (CONTRACT_PERIODS, 1, 2))), '999,999,999,999,999'))Total from apps.XX_EMP_MASTER_DETAILS_MV_temp WHERE     PERSON_TYPE = 'Employee'     group by dept_en having lower(dept_en )like'%" & TextBox2.Text & "%' OR UPPER(dept_en )like'%" & TextBox2.Text & "%' OR initcap(dept_en )like'%" & TextBox2.Text & "%'  order by dept_en")
    

    I want to make 3d pie an line chart   using  vb.net code          

     how can make

    thank you so much

    Sunday, February 24, 2019 12:27 PM

All replies

  • User839733648 posted

    Hi thepast,

    You could use Chart Control in asp.net to achieve your requirement.

    The key point is to bind the data you've got to the chart control.

    I've made a sample on my side and maybe you could refer to.

    .aspx

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Chart ID="Chart1" runat="server">
                    <Series>
                        <asp:Series Name="Series1" ChartType="Pie"></asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true"></asp:ChartArea>
                    </ChartAreas>
                </asp:Chart>
            </div>
        </form>
    </body>
    </html>

    code-behind.

    Imports System.Configuration
    Imports System.Data
    Imports System.Data.SqlClient
    		Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    			If Not IsPostBack Then
    				BindData()
    			End If
    		End Sub
    		Private constr As String = ConfigurationManager.ConnectionStrings("EmployeeManagementConnectionString").ConnectionString
    		Private Sub BindData()
    			Using con As New SqlConnection(constr)
    				Dim dt As New DataTable()
    				Dim myquery As String = "SELECT * FROM traffic_data"
    				Dim cmd As New SqlCommand(myquery, con)
    				con.Open()
    				Dim sda As New SqlDataAdapter(cmd)
    				sda.Fill(dt)
    				Chart1.DataSource = dt
    				Chart1.Series("Series1").XValueMember = "year"
    				Chart1.Series("Series1").YValueMembers = "month"
    				Chart1.DataBind()
    			End Using
    		End Sub
    

    result:

    You could just change ChartType="Pie" to ChartType="Line" and there will be a line chart.

    Reference: https://docs.microsoft.com/en-us/previous-versions/dd456769(v=vs.140) 

    Best Regards,

    Jenifer

    Monday, February 25, 2019 6:40 AM
  • User66371569 posted

    hi 

    I tried your code I change my table   when I run    pie chart not shown

    how can fix this

    Monday, February 25, 2019 10:26 AM
  • User-2054057000 posted

    You can simply use Chart.js to make your Pie Chart. See docs here

    Pic chart Demo here.

    There is similar question that explains how to create the charts using C# and jQuery- 

    help : populate chart  

    Monday, February 25, 2019 10:59 AM
  • User66371569 posted
    I want to make in pie chart name of color

    forexample if i have 2 colors red and green i want to write what each color means
    and also how can i change color in chart
    Monday, February 25, 2019 4:41 PM
  • User839733648 posted

    Hi thepast,

    I've modified the code and maybe you could refer to.

    The key point is to show the color as expected.

    		Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    			Dim dt As New DataTable()
    			dt.Columns.Add("ColorName")
    			dt.Columns.Add("Percentage")
    			Dim dr1 As DataRow = dt.NewRow()
    			dr1("ColorName") = "red"
    			dr1("Percentage") = "30"
    			dt.Rows.Add(dr1)
    
    			Dim dr2 As DataRow = dt.NewRow()
    			dr2("ColorName") = "green"
    			dr2("Percentage") = "50"
    			dt.Rows.Add(dr2)
    			Dim dr3 As DataRow = dt.NewRow()
    			dr3("ColorName") = "yellow"
    			dr3("Percentage") = "20"
    			dt.Rows.Add(dr3)
    			Dim chartData As New Dictionary(Of String, Integer)()
    			For Each r As DataRow In dt.Rows
    				Dim key As String = r("ColorName").ToString()
    				Dim value As Integer = Convert.ToInt32(r("Percentage"))
    				chartData.Add(key, value)
    			Next r
    			Chart1.Series("Series1").Points.DataBind(chartData, "Key", "Value", String.Empty)
    			Chart1.Series("Series1").ChartType = SeriesChartType.Pie
    			Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
    			Chart1.ChartAreas(0).Area3DStyle.Inclination = Convert.ToInt32(20)
    			For Each charts As Series In Chart1.Series
    				For Each point As DataPoint In charts.Points
    					Select Case point.AxisLabel
    						Case "red"
    							point.Color = Color.Red
    						Case "green"
    							point.Color = Color.Green
    						Case "yellow"
    							point.Color = Color.Yellow
    					End Select
    				Next point
    			Next charts
    
    		End Sub

    result:

    Best Regards,

    Jenifer

    Tuesday, February 26, 2019 5:46 AM
  • User66371569 posted
    how can I do same your code but using select statment
    Tuesday, February 26, 2019 7:59 AM
  • User839733648 posted

    Hi thepast,

    You could use ado.net to read the data from your database.

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    			If Not IsPostBack Then
    				BindData()
    			End If
      End Sub
    		Private constr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
    		Private Sub BindData()
    			Using con As New SqlConnection(constr)
    				Dim dt As New DataTable()
    				Dim myquery As String = "SELECT * FROM tb_Color" 
    				Dim cmd As New SqlCommand(myquery, con)
    				con.Open()
    				Dim sda As New SqlDataAdapter(cmd)
    				sda.Fill(dt)
    				Dim chartData As New Dictionary(Of String, Integer)()
    				For Each r As DataRow In dt.Rows
    					Dim key As String = r("ColorName").ToString()
    					Dim value As Integer = Convert.ToInt32(r("Percentage"))
    					chartData.Add(key, value)
    				Next r
    
    				Chart1.Series("Series1").Points.DataBind(chartData, "Key", "Value", String.Empty)
    				Chart1.Series("Series1").ChartType = SeriesChartType.Pie
    				Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
    				Chart1.ChartAreas(0).Area3DStyle.Inclination = Convert.ToInt32(20)
    				For Each charts As Series In Chart1.Series
    					For Each point As DataPoint In charts.Points
    						Select Case point.AxisLabel
    							Case "red"
    								point.Color = Color.Red
    							Case "green"
    								point.Color = Color.Green
    							Case "yellow"
    								point.Color = Color.Yellow
    						End Select
    
    					Next point
    				Next charts
    			End Using
    		End Sub
    

    Best Regards,

    Jenifer

    Tuesday, February 26, 2019 8:22 AM
  • User66371569 posted
    i have 2 column in my query but always first coulumn shows in chart second no

    select sum(column1) as ss,sum(column2) as dd from ...........

    how can i solve that
    Tuesday, February 26, 2019 9:18 AM
  • User839733648 posted

    Hi thepast,

    I think it may be because of the data type returning from database.

    How is your database designed? Could you share your example data from your query statement?

    This will be helpful to find the issue.

    Best Regards,

    Jenifer

    Tuesday, February 26, 2019 10:07 AM