PHP에서 배열 구조를 생성하여 응용 프로그램 (Laravel MVC)에 파이 차트를 작성하려고합니다. 그러면 json_encode를 사용하여보기에 전달되어 호환 가능하지만 원형 차트는 모두 올려 놓았습니다.json을 만들기 위해 PHP를 사용하여 원형 차트 만들기
내 데이터 세트
gender | total
Female | 20
Male | 17
Other | 3
나는이있다 : 사이트에서 (
{
"chart":{
"plotBackgroundColor":"null",
"plotBorderWidth":"null",
"plotShadow":"false"
},
"title":{
"text":"Pet Intakes By Gender"
},
"tooltip":{
"pointFormat":"{series.name}: {point.percentage:.1f}%"
},
"plotOptions":{
"pie":{
"allowPointSelect":"true",
"cursor":"pointer",
"dataLabels":{
"enabled":"false"
},
"showInLegend":"true"
}
},
"series":[
{
"type":"pie",
"name":"Percentage of Gender",
"data":[
{
"Female":17,
"Male":12,
"Other":2
}
]
}
]
}
그리고 나는 이런 식으로 뭔가에 도착해야합니다 인코딩 할 때이 생산
$chartArray["chart"] = array("plotBackgroundColor" => "null", "plotBorderWidth" => "null", "plotShadow" => "false");
$chartArray["title"] = array("text" => "Pet Intakes By Gender");
$chartArray["tooltip"] = array("pointFormat" => "{series.name}: {point.percentage:.1f}%");
$chartArray['plotOptions'] = array("pie" => array("allowPointSelect"=>"true","cursor"=>"pointer","dataLabels"=>array("enabled" => "false"),"showInLegend" => "true"));
$data = [];
foreach($results as $result){
$data = $this->array_push_assoc($data, $result->gender, $result->total);
}
$chartArray["series"] = array(array("type" => 'pie', "name" => 'Percentage of Gender', "data" =>array($data)));
return $chartArray;
예 :
{
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
});
무엇이 누락 되었습니까? 감사!
그리고 이것은 작동하지 않습니다 ... 어떻게? –
차트 영역이 검은 색입니다. 서로 위에 쌓인 선 (또는 단 한 줄)이 있으며 범례에 슬라이스라고 표시되어 있습니다. http://beta.petpalmanager.com/files/pie.png –