Anonymous
Я хочу отобразить динамическую легенду и всплывающую подсказку для codeigniter highchart.
Сообщение
Anonymous » 06 дек 2024, 06:20
"Вот мой код"
Код: Выделить всё
public function data()
{
.....
$data = $this->data->get_data($month1, $year1, $month2, $year2,$CtypeID);
$category = array();
$category['name'] = 'Category';
$series1 = array();
foreach ($data as $row)
{
$legend_date = date("F-y", strtotime($row->CreatedOn));
$category['data'][] =$legend_date;
$series1['data'][] = $row->ID;
$series1['name'] = 'Sales';
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
print json_encode($result, JSON_NUMERIC_CHECK);
}
$(document).ready(function() {
$('#pie').click(function(){
var options = {
chart: {
renderTo: 'container2',
type: 'pie',
marginRight: 130,
marginBottom: 25
},
title: {
text: '',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: [],
labels: {
enabled: false
}
},
yAxis: {
title: {
text: 'No Of Sales'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return this.series.name +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0,
},
plotOptions: {
series: {
animation: {
duration: 2000
}
},
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '{point.name}[/b]: {point.percentage:.1f} %',
},
showInLegend: true,
},
},
series: []
}
var month1 = document.getElementById('month1').value;
var year1 = document.getElementById('year1').value;
var month2 = document.getElementById('month2').value;
var CtypeID = document.getElementById('CtypeID').value;
var value = 'month1='+month1+'&year1='+year1+'&month2='+month2+'&year2='+year2+'&CtypeID='+CtypeID;
$.getJSON("data", value, function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
chart = new Highcharts.Chart(options);
});
});
});
Проблема в том, что этот код выводит фрагмент вместо динамической легенды.
Подробнее здесь:
https://stackoverflow.com/questions/276 ... odeigniter
1733455223
Anonymous
"Вот мой код"[b] [code]public function data() { ..... $data = $this->data->get_data($month1, $year1, $month2, $year2,$CtypeID); $category = array(); $category['name'] = 'Category'; $series1 = array(); foreach ($data as $row) { $legend_date = date("F-y", strtotime($row->CreatedOn)); $category['data'][] =$legend_date; $series1['data'][] = $row->ID; $series1['name'] = 'Sales'; } $result = array(); array_push($result,$category); array_push($result,$series1); print json_encode($result, JSON_NUMERIC_CHECK); } $(document).ready(function() { $('#pie').click(function(){ var options = { chart: { renderTo: 'container2', type: 'pie', marginRight: 130, marginBottom: 25 }, title: { text: '', x: -20 //center }, subtitle: { text: '', x: -20 }, xAxis: { categories: [], labels: { enabled: false } }, yAxis: { title: { text: 'No Of Sales' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, tooltip: { formatter: function() { return this.series.name +': '+ this.y; } }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y: 100, borderWidth: 0, }, plotOptions: { series: { animation: { duration: 2000 } }, pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '{point.name}[/b]: {point.percentage:.1f} %', }, showInLegend: true, }, }, series: [] } var month1 = document.getElementById('month1').value; var year1 = document.getElementById('year1').value; var month2 = document.getElementById('month2').value; var CtypeID = document.getElementById('CtypeID').value; var value = 'month1='+month1+'&year1='+year1+'&month2='+month2+'&year2='+year2+'&CtypeID='+CtypeID; $.getJSON("data", value, function(json) { options.xAxis.categories = json[0]['data']; options.series[0] = json[1]; chart = new Highcharts.Chart(options); }); }); }); [/code] Проблема в том, что этот код выводит фрагмент вместо динамической легенды. Подробнее здесь: [url]https://stackoverflow.com/questions/27634605/i-want-to-display-dynamic-legend-and-tooltip-for-pie-highchart-codeigniter[/url]