AMCHARTSのための動的ガイド
-
02-01-2020 - |
質問
私はこのように私のAMCHARTにガイド(垂直線)を追加することができます:
var guide1 = new AmCharts.Guide();
guide1.date = new Date(2014, 5, 27);
guide1.lineColor = "#CC0000";
guide1.lineAlpha = 1;
guide1.dashLength = 2;
guide1.inside = true;
guide1.labelRotation = 90;
guide1.label = "Guide label";
stockPanel.categoryAxis.addGuide(guide1);
.
データベース内の日付のリストからこれらのガイドの数を動的に追加する方法は? 私はPHPでそれぞれを生成することができて、それらを私のスクリプトに含めることができますか?
サンプルPHP(Echoguide.php):
<?php
$js = <<<JS
var guide1 = new AmCharts.Guide();
guide1.date = new Date(2014, 5, 27);
guide1.lineColor = "#CC0000";
guide1.lineAlpha = 1;
guide1.dashLength = 2;
guide1.inside = true;
guide1.labelRotation = 90;
guide1.label = "Guide label";
JS;
header("Content-type: text/javascript");
echo $js;
exit();
?>
.
HTMLファイルのサンプルJS:
var guide = AmCharts.loadJSON('echoGuide.php');
stockPanel.categoryAxis.addGuide(guide);
.
amcharts.loadjson:
AmCharts.loadJSON = function(url) {
// create the request
if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari
var request = new XMLHttpRequest();
} else {
// code for IE6, IE5
var request = new ActiveXObject('Microsoft.XMLHTTP');
}
// load it
// the last "false" parameter ensures that our code will wait before the
// data is loaded
request.open('GET', url, false);
request.send();
// parse and return the output
return eval(request.responseText);
};
. 解決
解決策を見つけた:
gDates = AmCharts.loadJSON('db/fetchgDates.php');
for (var key_2 in gDates) {
var obj_2 = gDates[key_2];
var date_2_temp = new Date(obj_2['date']);
var guide = new AmCharts.Guide();
guide.date = date_2_temp;
guide.lineColor = "#CC0000";
guide.lineAlpha = 1;
guide.dashLength = 2;
guide.inside = true;
guide.labelRotation = 90;
guide.label = "test";
stockPanel.categoryAxis.addGuide(guide);
}
. 所属していません StackOverflow