我想用我的数据在javascript中制作图表,但我不知道如何。下面是我想使用的图表:https://www.amcharts.com/demos/professional-candlesticks/:
和代码里面我发现了这样的东西:
{"dataProvider": [ {
"date": "2011-08-01",
"open": "136.65",
"high": "136.96",
"low": "134.15",
"close": "136.49"
}
等。我加载数据到php数组:
<?php $csv = array_map('str_getcsv', file('../projekt/lataset_2009.csv'));?>
VALUES in CSV:
日期、开放,高,低,接近
然后我使用javascript代码:var jArray= <?php echo json_encode($csv); ?>;
重写php数组javascript数组问题是:如何修改
日期":" 2011-08-01 ",
"开放":"136.65",
"高":"136.96",
"低":"134.15",
"关闭":" 136.49 "
包含数组数据。请帮助
我已经将解决方案重写为多维数组中的数据,这将工作:
//get the csv data
$records = array_map('str_getcsv', file('../projekt/lataset_2009.csv'));
//create empty array
$data = array();
//loop through the csv data
foreach($records as $row){
//ignore the first array line so only the lines containing the data is used
if($row[0] != 'date'){
//create an array into the parent $data array
$data[] = array(
'date' => $row[0],
'open' => $row[1],
'high' => $row[2],
'low' => $row[3],
'close' => $row[4],
);
}
}
//turn the array to json
$chartData = json_encode($data);
//alter the date so it's in a valid date format
$chartData = str_replace(''/', '/', $chartData);
//output the data
echo $chartData;