Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lawkunchi's avatar

Laravel Graph using Chartist JS

I'm using Chartist JS to create a graph for number of registered users against the registered month. Below is my code so far. I'm getting repeated months and it's not tallying with the number of users. So I need help. Thanks

Javascript

var chart = new Chartist.Line('.ct-chart1', {
  labels: [
      @foreach ($users as $user)
        [ "{{ $user->created_at->format('M') }}"], 
      @endforeach  
  ],
  series: [
   @foreach ($users as $user)
        [ "{{ $user->count() }}"], 
    @endforeach
  ]
}, {
  low: 0,
  showLine: false,
});
Controller

 public function getChart()
    {
        $users = User::All()->where('type', 'default');
        return view('users.chart')->with('users', $users);
    }
0 likes
0 replies

Please or to participate in this conversation.