Код: Выделить всё
[
{ "option": "Czech Republic", "percentage": 156.90,"color":"#2175d9"},
{ "option": "Ireland", "percentage": 131.10,"color":"#ff9900"},
{ "option": "Germany", "percentage": 115.80,"color":"#448800"},
{ "option": "Australia", "percentage": 109.90,"color":"#2175d9"},
{ "option": "Austria", "percentage": 108.30,"color":"#2175d9"},
{ "option": "UK", "percentage": 99.00,"color":"#2175d9"}
]
Код: Выделить всё
$("#viewResult").click(function(){
$("#chart").show();
var qstnId = $("div[name='pollqstn']").attr("id");
//Ajax to load all poll results
$.post("fetchpollresult.php", {qstnid: qstnId}, function (data) {
drawStuff(data);
});
});
Код: Выделить всё
$questionid = $_REQUEST['qstnid'];
$arranstext = array();
$arranscount = array();
$arranscolours = array("#2175d9","#448800","#448800","#ff9900");
//find qstn text
$pollqstndetails = $DB->get_records('epoll_questions', array('id' => $questionid));
$optiondetails = $DB->get_records('epoll_answers', array('questionid' => $questionid));
foreach($optiondetails as $optval){
$optionresponseCount = $DB->get_records('epoll_responses', array('answerid' => $optval->id,'questionid'=>$questionid));
$countOptresponse = count($optionresponseCount);
array_push($arranstext ,$optval->answertext);
array_push($arranscount ,count($optionresponseCount));
}
$data =array();
for($i=0;$i$arranstext[$i],'percentage'=>$arranscount[$i],'color'=>$arranscolours[$i]) ;
}
$optionnoresponseCount = $DB->get_records('epoll_responses', array('answerid' => 0,'questionid'=>$questionid));
$data[] = array('option' =>"NA",'percentage'=>count($optionnoresponseCount),'color'=>"#ff9900") ;
echo json_encode($data);
Код: Выделить всё
[
{ "option": "Czech Republic", "percentage": 156.90,"color":"#2175d9"},
{ "option": "Ireland", "percentage": 131.10,"color":"#ff9900"},
{ "option": "Germany", "percentage": 115.80,"color":"#448800"},
{ "option": "Australia", "percentage": 109.90,"color":"#2175d9"},
{ "option": "Austria", "percentage": 108.30,"color":"#2175d9"},
{ "option": "UK", "percentage": 99.00,"color":"#2175d9"}
]
Than I have a function calling in ajax response:
function drawStuff(val){
// RADAR CHART
chart = new AmCharts.AmSerialChart();
chartData =val; //assigning ajax response
chart.dataProvider = chartData;
chart.categoryField = "option";
chart.startDuration = 3;
chart.sequencedAnimation = false;
// VALUE AXIS
var valueAxis = new AmCharts.ValueAxis();
valueAxis.axisAlpha = 0.15;
valueAxis.minimum = 0;
valueAxis.dashLength = 3;
chart.addValueAxis(valueAxis);
// GRAPH
var graph = new AmCharts.AmGraph();
graph.type = "column";
graph.colorField = "color"
graph.valueField = "percentage";
graph.fillAlphas = 0.6;
graph.balloonText = "[[value]] litres of beer per year";
chart.addGraph(graph);
// WRITE
chart.write("chart");
}
Я понимаю следующее:
Код: Выделить всё
var chartData =
[
{ "option": "Czech Republic", "percentage": 156.90,"color":"#2175d9"},
{ "option": "Ireland", "percentage": 131.10,"color":"#ff9900"},
{ "option": "Germany", "percentage": 115.80,"color":"#448800"},
{ "option": "Australia", "percentage": 109.90,"color":"#2175d9"},
{ "option": "Austria", "percentage": 108.30,"color":"#2175d9"},
{ "option": "UK", "percentage": 99.00,"color":"#2175d9"}
]
Как я могу проанализировать только процентную пару Float, например 156.90,131.10.... из этого json и передать ее какchartData??
Я получаю диаграмму следующим образом:
Я получаю следующую диаграмму:
р>

Подробнее здесь: https://stackoverflow.com/questions/320 ... x-response