I have some question about Problem about PHP - parse a csv file and write output to another csv file with Google Charts . I want to get csv file from yahoo finance and use PHP to write some column into another csv file with Google Charts to represent a graph . I copy some code from "http://vizualyse.blogspot.com/2013/12/another-dashboard-with-google-charts.html" and "http://stackoverflow.com/questions/15610011/php-parse-a-csv-file-and-write-output-to-another-csv-file". After that I try to integrate 2 codes but it doesn't show anything.
Please help me to integrate these. Thank you. <head>. <title>Google Chart Example</title> <script src="https://www.google.com/jsapi"></script> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <!-- <script src="http://prithwis.x10.bz/charts/jquery.csv-0.71.js"></script> --> <script src="https://jquery-csv.googlecode.com/files/jquery.csv-0.71.js"></script> <script type="text/javascript"> // load the visualization library from Google and set a listener google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(drawChartfromCSV); function drawChartfromCSV(){ // Assume this variable contains CSV data from some external source, stored as a string //$my_csv_text = get_csv_from_internet(); // Open a memory "file" for read/write... //$f = fopen('table.csv', 'r+'); //fwrite($f, $my_csv_text); //rewind($f); //while (($data = fgetcsv($f)) !== FALSE) { // do stuff with the data! //} //$row = 1; if (($handle = fopen("table.csv", "r++")) !== FALSE) { while (($data = fgetcsv($handle, 1000, " ")) !== FALSE) { $num = count($data); //$date = $data[0]; $open = $data[1]; $high = $data[2]; $low = $data[3]; $close = $data[4]; $volume = $data[5]; $adjclose = $data[6]; $ema = $data[7]; //$sma = $data[8]; $fiboh = $data[9]; $fibol = $data[10]; //$fiboa = $data[11]; for ($c=0; $c < $num; $c++) { if($c == 0){ $fp = fopen('file.csv', 'a'); //Open for writing only; place the file pointer at the end of the file. $date = explode(',', $data[$c]); $date_count = count($date); for($i = 0; $i < $date_count; $i++){ fputcsv($fp, array($date[$i])); } fclose($fp); }/*else if($c == 8){ $fp = fopen('file.csv', 'a'); //Open for writing only; place the file pointer at the end of the file. $date = explode(',', $data[$c]); $date_count = count($date); for($i = 0; $i < $date_count; $i++){ fputcsv($fp,$sma); } fclose($fp); }else if($c == 11){ $fp = fopen('file.csv', 'a'); //Open for writing only; place the file pointer at the end of the file. $fiboa = explode(',', $data[$c]); $fiboa_count = count($fiboa); for($i = 0; $i < $date_count; $i++){ fputcsv($fp,$fiboa); } fclose($fp); }*/ } $row++; } fclose($handle); } // grab the CSV $.get("file.csv", function(csvString)) { // transform the CSV string into a 2-dimensional array var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar}); // use arrayData to load the select elements with the appropriate options for (var i = 1; i < arrayData[0].length; i++) { // i starts from 1, not 0 because the first column is text // this adds the given option to both select elements $("select").append("<option value='" + i + "'>" + arrayData[0][i] + "</option"); } // set the default selection $("#range option[value='1']").attr("selected","selected"); // this new DataTable object holds all the data var data = new google.visualization.arrayToDataTable(arrayData); // this view can select a subset of the data at a time var view = new google.visualization.DataView(data); view.setColumns([0,1]); var options = { title: "Stock Formula", hAxis: {title: data.getColumnLabel(0), minValue: data.getColumnRange(0).min, maxValue: data.getColumnRange(0).max}, vAxis: {title: data.getColumnLabel(1), minValue: data.getColumnRange(1).min, maxValue: data.getColumnRange(1).max}, legend: 'none' }; var chart = new google.visualization.LineChart(document.getElementById('csv2chart')); chart.draw(view, options); // this part makes the chart interactive $("select").change(function(){ // determine selected range - Vertical Axis var range = +$("#range option:selected").val(); // update the view view.setColumns([0,range]); // update the options options.vAxis.title = data.getColumnLabel(range); options.vAxis.minValue = data.getColumnRange(range).min; options.vAxis.maxValue = data.getColumnRange(range).max; // update the chart chart.draw(view, options); }); }); } ? </script> </head> <body> <div id="csv2chart" style="height: 500px; width: 900px;"> </div> <select id="range">Choose your chart</select> </body> -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-visualization-api. For more options, visit https://groups.google.com/d/optout.
