pie charprolem

17 views
Skip to first unread message

Sushant Jha

unread,
Apr 4, 2017, 4:01:05 AM4/4/17
to Google Visualization API

I could not see the years  list . 

here is my .net code


<script src="http://code.jquery.com/jquery-1.8.2.js"></script>  
    <script src="http://www.google.com/jsapi" type="text/javascript"></script>  
    <script type="text/javascript">
        google.load('visualization', '1', { packages: ['corechart'] });  
    </script>  
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                url: 'Home.aspx/GetChartData',
                data: '{}',
                success:
                function (response) {
                    drawchart(response.d);
                },

                error: function () {
                    alert("Error loading data!");
                }
            });
        })
        function drawchart(dataValues) {
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'year');

            data.addColumn('number', 'intake');
           
           
            for (var i = 0; i < dataValues.length; i++) {
                data.addRow([dataValues[i].Year,dataValues[i].Total]);
            }

            var options = { 
            'title': 'Data Analysis',
                'width': 600,
                'height': 500
            };
           var char= new google.visualization.PieChart(document.getElementById('myChartDiv')).
                  draw(data, options);
        }  
    </script>  
    
    <style type="text/css">
        .style1
        {
            font-size: medium;
        }
    </style>
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <br />
    <asp:Image ID="Image2" runat="server" Height="232px" 
        ImageUrl="~/images/8cz96d5cp.jpg" Width="914px" />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    Year&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:DropDownList ID="DropDownList1" runat="server" Height="37px">
        <asp:ListItem>2014</asp:ListItem>
        <asp:ListItem>2015</asp:ListItem>
    </asp:DropDownList>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Programe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:DropDownList ID="DropDownList2" runat="server" Height="37px">
        <asp:ListItem>---All---</asp:ListItem>
        <asp:ListItem>Applied Arts</asp:ListItem>
        <asp:ListItem>ntr</asp:ListItem>
    </asp:DropDownList>
&nbsp;&nbsp;&nbsp;
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submmit" 
        Width="100px" />
    <br />
    <br />
    <span class="style1" style="color: #000000">Filter of chart</span><br />
    <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Placed</asp:LinkButton>
    <br />
    <asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">Intake</asp:LinkButton>
    <br />
    <asp:LinkButton ID="LinkButton3" runat="server" onclick="LinkButton3_Click">Enroll</asp:LinkButton>
    <br />
    <asp:LinkButton ID="LinkButton4" runat="server" onclick="LinkButton4_Click">Passed</asp:LinkButton>
    <br />

        <div id="myChartDiv" style="width: 700px; height: 450px;">  
        </div>  
     
</asp:Content>







here is code behined home.aspx

 protected void Page_Load(object sender, EventArgs e)
        {
            n = "SELECT year, intake FROM overview WHERE program='Applied Arts' ORDER BY year";
        }
        //call google api
        [WebMethod]
        public static List<employeeDetails> GetChartData()
        {
            // first create table
            DataTable dt = new DataTable();
            //create connection string
            using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\sushant\career\career\App_Data\home.mdf;Integrated Security=True;User Instance=True"))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand(n, con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                con.Close();
            }
            List<employeeDetails> dataList = new List<employeeDetails>();
            foreach (DataRow dtrow in dt.Rows)
            {
                employeeDetails details = new employeeDetails();
                details.year = dtrow[0].ToString();
                details.Total = Convert.ToInt32(dtrow[1]);
                dataList.Add(details);
            }
            return dataList;
        }

        public class employeeDetails
        {
            public string year { get; set; }
                        public int Total { get; set; }
        }
Capture.PNG

Arghya chakroborty

unread,
Apr 4, 2017, 11:09:33 AM4/4/17
to Google Visualization API
To me, it seems like a problem with Chart Area. Could you please add chartArea in your options -

            var options = { 
                'title': 'Data Analysis',
                'width': 600,
                'height': 500,
        'chartArea':{left:00,top:0,width:'100%',height:'75%'}
            };

If you can't see the year still, you may vary the values for left and width and keep checking. It should work.

Regards,
Arghya
Reply all
Reply to author
Forward
0 new messages