boyjarv
1 month ago
135
1
Laravel

distinct and count all records

Posted 1 month ago by boyjarv

Hi,

I have a database of venues, I would like to display a bar chart (or the right chart) to show the towns along the bottom and the number of each venues per town

This is kind of working but not properly?!

$result = Venue::distinct('town')->get();
        return response()->json($result);

here is my javascript for my chart:

$.get(url, function(response){
            response.forEach(function(data){
                town.push(data.town);
                id.push(data.id);
            });
            var ctx = document.getElementById("canvas").getContext('2d');
            var myChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels:town,
                    datasets: [{
                        label: 'Venue ID',
                        data: id,
                        borderWidth: 1
                    }]
                },
                options: {
                    scales: {
                        yAxes: [{
                            ticks: {
                                beginAtZero:true
                            }
                        }]
                    }
                }
            });
        });

Please help

Please sign in or create an account to participate in this conversation.