Working on charts

This commit is contained in:
Hillel Coren 2018-02-27 21:19:46 +02:00
parent 31b8437dc6
commit e94e7cca80
2 changed files with 82 additions and 5 deletions

View File

@ -198,7 +198,6 @@ class AbstractReport
$datasets = [];
$labels = [];
$totals = new stdClass();
foreach ($this->chartData as $dimension => $data) {
$endDate->modify('+1 '.$groupBy);
@ -220,6 +219,7 @@ class AbstractReport
}
$color = '51,122,183';
/*
if ($entityType == ENTITY_INVOICE) {
$color = '51,122,183';
@ -234,7 +234,7 @@ class AbstractReport
$record->data = $records;
$record->label = trans("texts.{$dimension}");
$record->lineTension = 0;
$record->borderWidth = 4;
$record->borderWidth = 3;
$record->borderColor = "rgba({$color}, 1)";
$record->backgroundColor = "rgba({$color}, 0.1)";
$datasets[] = $record;
@ -249,6 +249,40 @@ class AbstractReport
public function getPieChartData()
{
$datasets = [];
$labels = [];
$totals = [];
$color = '51,122,183';
foreach ($this->chartData as $dimension => $data) {
foreach ($data as $date => $value) {
if (! isset($totals[$dimension])) {
$totals[$dimension] = 0;
}
$totals[$dimension] += $value;
}
}
$response = new stdClass();
$response->labels = [];
$datasets = new stdClass();
$datasets->data = [];
$datasets->backgroundColor = [];
foreach ($totals as $dimension => $value) {
$response->labels[] = $dimension;
$datasets->data[] = $value;
$datasets->lineTension = 0;
$datasets->borderWidth = 3;
$datasets->borderColor = "rgba({$color}, 1)";
$datasets->backgroundColor = "rgba({$color}, 0.1)";
}
$response->datasets = [$datasets];
return $response;
}
}

View File

@ -52,6 +52,51 @@ function loadLineChart(data) {
}
function loadPieChart(data) {
var ctx = document.getElementById('pieChartCanvas').getContext('2d');
new Chart(ctx, {
type: 'doughnut',
data: data,
options: {
/*
tooltips: {
mode: 'x-axis',
titleFontSize: 15,
titleMarginBottom: 12,
bodyFontSize: 15,
bodySpacing: 10,
callbacks: {
title: function(item) {
return moment(item[0].xLabel).format("{{ $account->getMomentDateFormat() }}");
},
label: function(item, data) {
//return label + formatMoney(item.yLabel, chartCurrencyId, account.country_id);
return item.yLabel;
}
}
},
scales: {
xAxes: [{
type: 'time',
time: {
unit: "{{ $report->chartGroupBy() }}",
round: "{{ $report->chartGroupBy() }}",
},
gridLines: {
display: false,
},
}],
yAxes: [{
ticks: {
beginAtZero: true,
callback: function(label, index, labels) {
return roundSignificant(label);
}
},
}]
}
*/
}
});
}
@ -61,11 +106,9 @@ $(function() {
loadLineChart(lineChartData);
//console.log(chartData);
/*
var pieChartData = {!! json_encode($report->getPieChartData()) !!};
loadPieChart(pieChartData);
console.log(pieChartData);
*/
});
</script>