1

I am very new to javascript but unfortunately it is what I have to use for a thermometer chart that I'm using. I need to get the value of an ASP label text and then store that into a javascript variable which will be used to set the chart value.

For some reason it is not storing the value at all and the chart obviously doesn't have the value needed. Again I am extremely new to javascript so please be nice. :) Here is what I have so far.

Here is part of the ASPX page:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script>
    window.onload = function () {
        // Create the Thermometer chart. The arguments are: the canvas ID, the minimum,
        // the maximum and the indicated value.

        var grossSales = $('#<%= MtdLBL.ClientID %>').next().text;
        var thermometer = new RGraph.Thermometer('salesThermometer', 0, 180000, parseInt(grossSales.valueOf))

        // Configure the thermometer chart to look as you want.
                    .Set('chart.gutter.left', 45)
                    .Set('chart.gutter.right', 45)
                    .Set('chart.colors', ['rgba(255,0,0,1)'])
                    .Set('chart.units.pre', '$')
        // Now call the .Draw() method to draw the chart.
                    .Draw();
    }
            </script>
<link href="Charts/RGraph/demos/demos.css" rel="stylesheet" type="text/css" />
<script src="Charts/RGraph/libraries/RGraph.common.core.js" type="text/javascript"></script>
<script src="Charts/RGraph/libraries/RGraph.thermometer.js" type="text/javascript"></script>
</asp:Content>

And this is from the code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["TeamID"] == null || Session["TeamID"] == "")
    {
        Response.Redirect("~/Default.aspx");
    }
    else
    {
        //Populate department average
        double deptAvg = achievementData.DeptAverage();
        DeptAvgValueLBL.Text = deptAvg.ToString("P0");

        //Get sales data
        Sales getSalesData = new Sales();
        MtdLBL.Text = getSalesData.GrossSalesByTeam(Session["TeamID"].ToString());
    }
}
2
  • Why are you calling .next() after getting the correct control in your JavaScript code? Commented Jul 10, 2013 at 16:41
  • I found a similiar question here stackoverflow.com/questions/7431464/…. However when I remove the .next() it still doesn't work. Commented Jul 10, 2013 at 16:45

2 Answers 2

3
var grossSales = $('#<%= MtdLBL.ClientID %>').text();

Note parentheses; text is a function, not a simple value. The next() is out of place unless you want the following control, which doesn't seem right.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a ton! That worked. <script> window.onload = function () { // Create the Thermometer chart. The arguments are: the canvas ID, the minimum, // the maximum and the indicated value. var grossSales = $('#<%= MtdLBL.ClientID %>').text(); var thermometer = new RGraph.Thermometer('salesThermometer', 0, 180000, parseInt(grossSales)).....
0

Remove the valueOf() call in the thermometer variable definition line. valueOf is used to return a primitive boolean. I'm assuming you're trying to use the grossSales number for something other than a boolean flag.

See http://www.w3schools.com/jsref/jsref_valueof_boolean.asp

Also, as @catfood said, you don't need the .next()

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.