English 中文(简体)
Protype Javascript , Unable to return value from Java Array
原标题:

I am unable to get the Date Values into X axis

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
            <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
                    <title>Flotr: Basic Radar Example</title>
                    <link rel="stylesheet" href="style.css" type="text/css" />

                    <script type="text/javascript" src="prototype.js"></script>
                    <script type="text/javascript" src="examples.js"></script>

                    <script type="text/javascript" src="canvas2image.js"></script>
                    <script type="text/javascript" src="canvastext.js"></script>
                    <script type="text/javascript" src="flotr.js"></script>
            </head>
            <body>


                            <div id="container" style="width:600px;height:400px;"></div>



    <script type="text/javascript">
    var jsonData = [{date: August 19, 2004 ,open:100.01,high:104.06,low:95.96,close:100.34,volume:22088000},{date: August 20, 2004 ,open:101.48,high:109.08,low:100.50,close:108.31,volume:11377000},{date: August 23, 2004 ,open:110.76,high:113.48,low:109.05,close:109.40,volume:9090700},{date: July 19, 2007 ,open:553.46,high:553.52,low:542.24,close:548.59,volume:6477800},{date: July 20, 2007 ,open:511.90,high:523.18,low:509.50,close:520.12,volume:16026500},{date: July 23, 2007 ,open:519.01,high:520.00,low:512.15,close:512.51,volume:6227900}];


     var priceData = [];


      for(var i = 0; i<jsonData.length; i++) {
      priceData.push([i, jsonData[i].low]);
    }


    var f = Flotr.draw(
        $( container ),[ priceData],{
            xaxis:{
                tickFormatter: function(n)

                {

                        var date = jsonData[n].date;

            return date; 



                }
            }

        }
    );



    </script>



            </body>
    </html>

It is throwing an Error as detailed error: jsonData[n] is undefined

问题回答

sounds like n is not what you think it is. on a side note as your using prototype, you can simplify your code using:

var priceData = jsonData.pluck( low );

From looking at this question I can see that tickFormatter is passed a timestamp, not an index. jsonData[n] is undefined because n is not the index you think it is.

The linked question also seems to have a good solution too, you should try that.
Flotr x-axis date/time





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签