javascript - HighCharts reading from CSV basic example -


New in high writing and JS and am trying to plot data from a CSV file (data3.csv) .

At this time the code is:

    gt; Top & gt; Meta http-equiv =" content-type "content =" text / html; Charset = UTF-8 "& gt; Title & gt; Example of Heights & lt; / title & gt; & lt ;! - 1. Add these JavaScript Inversions to the top of your page - & gt; & Lt ; Script type = "text / javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> gt; & lt; / script & gt; Lt; script type = "text / javascript" src = "highcharts.js" & gt; & lt; / script & gt; & lt;! - [if IE]> gt; script type = "text / javascript "Src =" ../JS/ excanvas.compiled.js ">  & lt; [endif] - & gt; & lt ;! 2. Document Ready To start the chart, add javascript -> gt; script type = "text / javascript" & gt; $ {document} .ready (function () {var options = {chart: {renderTo: 'Container', defaultSeriesType: 'line'}, title: {text: 'stock chart'}, xAxis: {categories: []}, yaxis: {title: {text: 'price'}}, series: [] ; $ .get ('data3.csv', function) {$ .each (lines, function (line no, line) {var item = line. Split (','); Var series = {data: []}; $ .ei (item, function (item no, item) {if (item not == 0) {series.name = item;} else {series.data.push (parseFloat (item))}}); Options.series.push (series);}); Var chart = new highcharts.chart (option);});}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt ;! - 3. Add Container - & gt; & Lt; Div id = "container" style = "width: 800 px; height: 400px; margin: 0 auto" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

And the content of the CSV file is as follows:

  Open Date 29/01/2010 538.49 28/01/2010 544.49 27/01/2010 541.27   

However, this is not giving a chart (just gives headline).

Can someone suggest where I am going wrong?

Thanks

in line

  var Item = line.split (',');   

You should spray CSV with a comma, but you have space. So you can change this line like this:

  var item = line.split ('');   

Or generate CSV items that will be separated by commas.

As a result your parser should look like this:

  $ ('Data.csv', function (data) {// divide lines var line = data .split ('\ n'); // iterate over lines and add categories or series $. (Line, function (line , Line) {var items = line.split (','); if (lineNo> 0) {forms of options.xAxis.categories.push (item [0]); // categorie options.series [0] Set up the first call from CSV. Data pash (parsfot (item [1]) // set second column as point value from CSV}}} Chart vs chart = new highchart chart (option);} ;    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -