score:1
$value->created_at
is a full date/time string. since you want to organize it by dates, then you'll need to format it first. thankfully, laravel's timestamps are automatically converted to carbon, so it's easy to format
$attrs[$value->created_at->todatestring()][] = $value->order;
if you want just the year/month, then use format()
instead
$attrs[$value->created_at->format('y-m')][] = $value->order;
edit i see now you're using query builder (db), not eloquent, so you'll need to actually parse the timestamp separately.
$date = carbon::create($value->created_at);
$attrs[$date->todatestring()][] = $value->order; // 2021-07-14
$attrs[$date->format('y-m')][] = $value->order; // 2021-07
score:0
if you are using collection then
$user=db::table('analytics')->get()
->maptodictionary(function ($analytics){
$date=carbon::parse($analytics->created_at)->format('d-m-y');
$data[$date]=$analytics->order;
return $data;
})->toarray();
score:0
my recommendation would be to use eloquent instead of the db query builder. if you have an analytic
model, then this is quite simple. you could just add created_at
to your $dates
array and it will automatically be cast as a carbon
instance. for instance, in your model:
protected $dates = ['created_at'];
Source: stackoverflow.com
Related Query
- How to add datetime formate for public function as key(stdClass) in controller/laravel
- How to add second Y-axis for Bar and Line chart in Chart.js?
- How to add label for ChartJs Legend
- How to add ChartJS code in Html2Pdf to view image
- How to add label in chart.js for polar chart area
- How to add background color for doughnut mid using chart,js
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- How to add labels for only some of the data point?
- How to add null value rows into pandas dataframe for missing years in a multi-line chart plot
- How to write better code in es6 for formatting an object with array values
- Chart.js : Controller for Scatter chart doesn't work for draw function
- How to add left padding for my charts done in ChartJs and my Google Map so it is not glued to the limit of the page on the left
- How to add data to chart.js with a for loop
- How to add the value for each label to pie legend
- How can I get chart.js to automatically add colours for dynamic labels?
- How to add color to text using pluginService for Chart.js?
- How to dynamically call function with a for loop within Chart.js (JS)
- How to run Chart.js samples using source code
- How to add tooltip for the inner doughnut
- How can I add vertical line and label for each point in Chart.js?
- How to set max and min value for Y axis
- How to add text inside the doughnut chart using Chart.js?
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- How to add labels into Chart.js canvas plugin?
- How to change colours for Angular-Chart.js
- How to disable a tooltip for a specific dataset in ChartJS
- How to modify chartjs tooltip so i can add customized strings in tooltips
- How to add tooltips to chart.js graph
- How to create rounded bars for Bar Chart.js v2?
- How to push datasets dynamically for chart.js (bar chart)?
More Query from same tag
- ChartJS is slow
- How can I sort data from highest to lowest in chart.js
- Unable to get Line Chart tooltip on ChartJS
- Formatting Data With Charts.JS
- Chart.js - How To Show Value of Label as Percent of X and Y Values - Currently Always 100%
- Cannot change the color of column chart according to its value
- How to show second set of labels to Chart.js doughtnut chart?
- How do i find area under the graph
- Chart.js how to set cutoutPercentages for each dataset
- Chart.js BarChart not appearing
- How to include chart js annotations in ember?
- Accessing data in an associative array in CodeIgniter 3
- Making chartjs scrollable on the x-axis
- Displaying labels on a Doughnut Chart using Chart.js
- How can I avoid NaN on pie chart label in Chart JS
- How to remove Grid lines except for zero line and border Chartjs?
- Second tab doesn't show the chart . Can anybody see why?
- Pie chart using chart.js and asp.net web Service (asmx)
- I am Creating pie chart using Chartjs 2.6.0. I want to show label on Slices
- JavaScript. Find the sum of a certain parameter in an array to produce a popup if that sum == 0
- Chart.js - (intermediate value).Doughnut is not a function
- php to json to chart.js
- Zoom chartjs with many X values
- Fail to load chart on Flask/jinja2 html using chart.js
- How to add text in centre of the doughnut chart using Chart.js?
- Chart.js v3.60 - Add % symbol to the end of the tooltip label on a doughnut chart?
- I have a chart but it is not updating the chart with react chart-js-2
- chart.js: How do I make the radar chart axis labels bigger?
- web page doesn't display chart or any error
- Loop through array for chart.js input