I want to load some CSV columns or contents in my Ajax code. Please help me or improve my code. This will be live API code for me.
Data will be downloaded from Yahoo Finance in CSV format on an interval, and updated into this chart code. The values will be updated and chart will continue to be updated.
<?php $row = 1; if(($handle = fopen("table.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){
$row++;
for ($c=0; $c<1; $c++)
{
echo $data[$c];
}
for ($c1=5; $c1<6; $c1++)
{
$data[$c];
}
for ($c2=4; $c2<5; $c2++)
{
$data[$c];
}
fclose($handle);
}
?>
<script type="text/javascript" src="http://www.stoquity.com/js/jazaa/amcharts.js"></script>
<script type="text/javascript" src="http://www.stoquity.com/js/jazaa/raphael.js" type="text/javascript"></script>
var chart;
var chartData = [
{ year: '(here is the data from csv "col 1 row 1")', income: '(here is the data from csv "col 5 row 1")', expenses: '(here is the data from csv "col 4 row 1")'},{ year: '(here is the data from csv "col 1 row 2")', income: '(here is the data from csv "col 5 row 2")', expenses: '(here is the data from csv "col 4 row 2")'},{year: '(here is the data from csv "col 1 row 3")', income: '(here is the data from csv "col 5 row 3")',expenses: '(here is the data from csv "col 3 row 3")'}];
AmCharts.ready(function () {
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.pathToImages = "../amcharts/images/";
chart.dataProvider = chartData;
chart.categoryField = "year";
chart.startDuration = 1;
// AXES
// category
var categoryAxis = chart.categoryAxis;
categoryAxis.gridPosition = "start";
// value
// in case you don't want to change default settings of value axis,
// you don't need to create it, as one value axis is created automatically.
// GRAPHS
// column graph
var graph1 = new AmCharts.AmGraph();
graph1.type = "column";
graph1.title = "Income";
graph1.valueField = "income";
graph1.lineAlpha = 0;
graph1.fillAlphas = 1;
chart.addGraph(graph1);
// line
var graph2 = new AmCharts.AmGraph();
graph2.type = "line";
graph2.title = "Expenses";
graph2.valueField = "expenses";
graph2.lineThickness = 2;
chart.addGraph(graph2);
// LEGEND
// WRITE
chart.write("chartdiv");
});
</script>
</head>
<body>
<div id="chartdiv" style="width:850px; height:300px;"></div>
</body>