0

I want create a pie chart on my web page. I read data from my database and set them in two variable credit and remain_cost.

I want show a pie chart with that two values. And I find a pie chart that created with DevExpress company.

This is my asp.net code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>chart</title>
    <meta charset="utf-8" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/globalize/0.1.1/globalize.min.js"></script>
        <script type="text/javascript" src="http://cdn3.devexpress.com/jslib/14.1.7/js/dx.chartjs.js"></script>

        <script>

            var pieChartDataSource = [
                { category: 'Credit', value: 44 },
                { category: 'reamaincost', value: 34 },

            ];
            $(function () {


                $("#pieChartContainer").dxPieChart({
                    dataSource: pieChartDataSource,
                    series: {
                        argumentField: 'category',
                        valueField: 'value',
                        label: {
                            visible: true,
                            connector: {
                                visible: true
                            }
                        }
                    },
                    tooltip: {
                        enabled: true,
                        percentPrecision: 2,
                        customizeTooltip: function (value) {
                            return {
                                text: value.percentText
                            };
                        }
                    },
                    title: {
                        text: 'user over view'
                    },
                    legend: {
                        horizontalAlignment: 'center',
                        verticalAlignment: 'bottom'
                    }
                });
            });
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <asp:Literal ID="credittxt" runat="server" /> <br /> <asp:Literal ID="remain_costtxt" runat="server" />
            <asp:TextBox runat="server" ClientIDMode="Static" ID="txt" />
        </div>
    <div id="pieChartContainer" style="height:400px; max-width:700px; margin: 0 auto"></div>
    </div>
    </form>
</body>
</html>

and this is my code behind:

protected void Page_Load(object sender, EventArgs e)
{
    DataSet1.usersDataTable ousersDataTable = new DataSet1.usersDataTable();
    DataSet1TableAdapters.usersTableAdapter ousersTableAdapter = new DataSet1TableAdapters.usersTableAdapter();
    ousersTableAdapter.FillBysip(ousersDataTable, "my_data");
    DataSet1.usersRow ousersRow = ousersDataTable[0];
    string credit = ousersRow.credit.ToString();
    string remain_cost = ousersRow.schduled_cost.ToString();
    credittxt.Text = credit;
    remain_costtxt.Text = remain_cost;
    txt.Text = credit;
}

The data successfully appeared in literal and text box control.

My question is that I want set the credit value in c# to credit value in jQuery and remain _cost in c# to remain_cost variable in jQuery.

Please help me.

1
  • Make use of the C# function Page.ClientScript.RegisterHiddenField("HiddenField", (string) Session["C#ValueInputforJquery"]); Commented Sep 29, 2014 at 19:07

2 Answers 2

2

Before </body>

<script>
           credit ='<%getCredit()%>';
           remain_cost ='<%getRemainCost()%>';
</script>

At your code behind file:

string credit, remain_cost;
public getCredit(){return credit ;}
public getRemainCost(){return remain_cost ;}

protected void Page_Load(object sender, EventArgs e)
{
 credit = ousersRow.credit.ToString();
 remain_cost = ousersRow.schduled_cost.ToString();
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can do like this:

protected void Page_Load(object sender, EventArgs e)
{
    DataSet1.usersDataTable ousersDataTable = new DataSet1.usersDataTable();
    DataSet1TableAdapters.usersTableAdapter ousersTableAdapter = new           DataSet1TableAdapters.usersTableAdapter();

     ousersTableAdapter.FillBysip(ousersDataTable, "my_data");
     DataSet1.usersRow ousersRow = ousersDataTable[0];
   string credit = ousersRow.credit.ToString();
  string remain_cost = ousersRow.schduled_cost.ToString();
   credittxt.Text = credit;
   remain_costtxt.Text = remain_cost;
   txt.Text = credit;



Page.RegisterClientScriptBlock("MyScript","<SCRIPT Language='JavaScript'>credit = " +credut +"; _cost = " + cost +";</SCRIPT>");

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.