Я пытаюсь создать круговую диаграмму в приложении (Laravel MVC), создав структуру массива в PHP, затем, когда она передается в представление с использованием json_encode, чтобы сделать его совместимым, но мой круговая диаграмма все поднята.Создание круговой диаграммы с использованием PHP для создания json
Мой набор данных
gender | total
Female | 20
Male | 17
Other | 3
У меня есть это:
$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":"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
}
]
}
]
}
И мне нужно, чтобы получить что-то вроде этого (с сайта пример):
{
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 –