I am beginner in Laravel. I use in my project Laravel 5.8. I am beginner web developer. I want show my stats in chars.
I have this Schema:
Schema::create('statistics', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('company_id')->unsigned();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->text('agent')->nullable();
$table->date('date')->nullable();
$table->ipAddress('ip');
$table->bigInteger('user_id')->default(0);
$table->bigInteger('quest_id')->default(0);
$table->string('browser', 70)->nullable();
$table->string('platform', 70)->nullable();
$table->string('language', 12)->nullable();
$table->engine = "InnoDB";
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
});
I generate stats by:
public function generateStatistics(string $dateFrom, string $dateTo, int $id)
{
return Statistics::whereBetween('date', [$dateFrom, $dateTo])->where('user_id', $id)->get();
}
In results I need generate this code:
<script>
window.chartColors = {
red: 'rgb(169, 26, 205)',
blue: 'rgb(107, 128, 194)'
};
var config = {
type: 'line',
data: {
labels: ['2019-10-14', '2019-10-15', '2019-10-16', '2019-10-17', '2019-10-18', '2019-10-19', '2019-10-20'],
datasets: [{
label: 'Total views in day',
fill: false,
borderColor: window.chartColors.red,
backgroundColor: window.chartColors.red,
data: [
50,
10,
99,
1,
290,
333,
24
]
}, {
label: 'Unique views in day,
fill: false,
borderColor: window.chartColors.blue,
backgroundColor: window.chartColors.blue,
data: [
150,
130,
949,
11,
2920,
3333,
244
]
}]
},
options: {
responsive: true,
title: {
display: false,
text: 'Historia odwiedzin'
},
scales: {
xAxes: [{
display: true,
ticks: {
callback: function (dataLabel, index) {
return index % 2 === 0 ? dataLabel : '';
}
}
}],
yAxes: [{
display: true,
beginAtZero: false
}]
}
}
};
window.onload = function () {
var ctx = document.getElementById('canvas').getContext('2d');
window.myLine = new Chart(ctx, config);
};
</script>
How can I generate: days and data for unique views and total views for JS? I want replace my sample data - my results from Laravel
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2MJVvIa
via IFTTT
Aucun commentaire:
Enregistrer un commentaire