0
我想使用我的數據在JavaScript中製作圖表,但我不知道如何。 這裏是圖表,我想用:https://www.amcharts.com/demos/professional-candlesticks/:圖表數據javascript
和內部代碼我發現這樣的事情:
{"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'));?>
CSV值:
DATE,開盤價,最高價,最低價,收盤價
然後我使用JavaScript代碼:var jArray= <?php echo json_encode($csv); ?>;
到rewrit PHP數組的JavaScript陣列 這裏是問題: 如何改變
日期 「:」 2011-08- 01" ,
「開放」: 「136.65」,
「高」: 「136.96」,
「低」: 「134.15」,
「close」:「136.49」
與陣列數據。 請幫助
您好,感謝的答覆。我把你的代碼,仍然有問題。加載文件顯示「試圖獲取非對象的屬性在.....行12 – Ruben
把你的代碼,並仍然有問題。加載文件顯示」試圖獲得非對象的屬性在.....行12 我的php代碼現在是 '<?php $ records = array_map('str_getcsv',file(''../ projekt/lataset_2009.csv'')); $ chartdata = null; foreach($ records as $ row){ $ chartdata。=「{date:\」$ row-> date \「,open:\」$ row-> open \「,high:\」$ row- >高\「,低:\」$ row-> low \「,關閉:\」$ row-> close \「},」;我的JS代碼是: ''dataProvider「:[<?= $ chartdata;?>]' 我仍然在尋找解決方案,因爲這是行不通的。 – Ruben
我已經更改了答案,因此它基於您的CSV而非以前的數據庫日期。 – Dave