score:1
Assuming you set up the relationship between Permit and State models, and you want to count the number of permits for each state (so I think you meant to have a 1:N relation), you could do like this:
$data = State::withCount('permits')->all();
// Then when you need to extract data
$chart = new PermitsChart;
$chart->labels($data->pluck('name'));
// To retrive the permit_count foreach state you can to
$data->pluck('permits_count'); // Array of counts
Update
To set up relationships between your model you have to add:
Permit.php
class Permit extends Model
{
// Your existing code
public function state()
{
return $this->belongsTo(State::class);
}
}
State.php
class State extends Model
{
// Your existing code
public function permits()
{
return $this->hasMany(Permit::class);
}
}
Source: stackoverflow.com
Related Query
- how to show labels in laravel charts when the name of the label is on another table?
- How can I change the label name when you hover your data in Chart.js?
- how I can get label name when user click on particular area in doughnut chart.js? I am not able to find the index of selected area for chart.js
- PrimeNg bar chart how to show a label for the y-axis
- How do I keep chart.js charts in one JS file, and not get errors when the ID from the JS file don't exist on one specific html page?
- Angular chart how to show the legend data value by default along with legend name
- Chart.JS: How can I only display data labels when the bar width is big enough for the text?
- How can I show a subset of data on pie pieces in Chart.JS while still displaying the superset when hovering?
- How to show a "total" sum label on the top of stacked bars
- Chart.JS: How can I only display data labels when the doughnut size is big enough for the text?
- How to show labels beside the bar in Char js 2?
- How to show the chartjs bar chart data values labels as text?
- How show data label in the graph on Chart.js?
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- Chart.js how to show line chart without displaying the labels on xaxis and yaxis
- how to show several labels and data's in the chart.js similar to npmtrend website?
- How to show tick marks and labels with grid line for the specific one on the X axis with Chart.js?
- Chart.js, increase space between bars and its labels when increasing the charts width
- How to show the data labels without hovering the mouse on the bubbles
- How do I customize the chart.js tooltip? Two labels have the same data, which I want to show you with each data
- Render labels only when the data is available for a particular label
- How do I prevent the scale labels from being cut off in chartjs?
- Truncating canvas labels in ChartJS while keeping the full label value in the tooltips
- Chart.js how to show cursor pointer for labels & legends in line chart
- How to add images as labels to Canvas Charts using chart.js
- chart js tooltip how to control the data that show
- Chart.js2 Radar, how to configure the label padding/spacing?
- How to wrap X axis labels to multi-lines (X axis label formatting) in ng2-Charts?
- How to change the color of Chart.js points depending on the label
- Chart JS show multiple data points for the same label
More Query from same tag
- Line chart with large number of labels on X axis
- Setting ticks of Chart.js in html.erb file
- Fill Chart.js bar chart with diagonal stripes or other patterns
- Multiple charts in one page with chart.js
- Pushing API Data into Chart.js
- How to prevent tick labels from "jumping" when drawn with ChartJS BeforeDraw
- Chart.js bar chart is overflowing its containing element
- Django Chartjs outputs "No data" when data has value 0
- ChartJS autoskip:False not working on line chart
- How can I make streaming chart with react?
- I need help on Optimization of Laravel Controller
- chart.js bar chart datalabel vanishes on hovering over chart
- Chart.js - change the scale background color of Radar type
- How to create custom legend in ChartJS
- Why is chart.js not showing charts?
- Gradient is too blurred in Chart.js Line Chart
- Why can't I use a variable in same function scope in Javascript?
- Apply/Register conflicting plugins to different charts
- Add data to line chart js dynamically with multiple lines
- How to embed php code in min.js file
- How do I change the bar colors in chart.js barcharts?
- chart.js working fine on my localhost but it is not working online
- How to set the number of of rows in a line chart in chart.js?
- Trying to use axios, vuejs and a dummy api for my chartjs and googlecharts (get requests only)
- Is there any way to use 2 different color for the same bar in a chart?
- Chart.js is always increasing height on chart.resize()
- Draw bubbles to show details in line chart using chart js
- How to reorganize data to display how many times a string appears in an array object?
- Uncaught ReferenceError: Chart is not defined at test.html:11
- Why don't my datasets show up on line graph using Chart.js?