LaravelDaily/laravel-charts

When the statistical target has only one piece of data, continuous_time doesn't work

Closed this issue · 3 comments

I try to count the number of users in 30 days by day
But I found a problem
When there is only one user in 30 days, continuous_time doesn't work
When I add another user to the database with a different created_at, continuous_time works

php code

namespace App\Http\Controllers\Manager;

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Http\Request;
use LaravelDaily\LaravelCharts\Classes\LaravelChart;

class StatisticsController extends Controller
{
    public function index(Request $request)
    {

        $user_register_count = [
            'all' => User::count(),
            '30'  => User::where([['created_at', '>=', date('Y-m-d H:i:s', time() - 2592000)]])->count(),
            '7'   => User::where([['created_at', '>=', date('Y-m-d H:i:s', time() - 604800)]])->count(),
            '1'   => User::where([['created_at', '>=', date('Y-m-d H:i:s', time() - 86400)]])->count(),
        ];

        $chart_options = [
            'chart_title'     => 'user register for month',
            'report_type'     => 'group_by_date',
            'model'           => User::class,
            'group_by_field'  => 'created_at',
            'group_by_period' => 'day',
            'chart_type'      => 'line',
            'filter_days'     => 30,
            'continuous_time' => true,
        ];
        $user_chart = new LaravelChart($chart_options);
        return view('manager.statistics.index', [
            'user_chart'          => $user_chart,
            'user_register_count' => $user_register_count,
        ]);

    }
}

html code

                <div class="chart">
                    {!! $user_chart->renderHtml() !!}
                </div>
    {!! $user_chart->renderChartJsLibrary() !!}
    {!! $user_chart->renderJs() !!}

image

@shirakun hi, thanks for the reporting. Currently we don't have free time to spend on this package, will have only in a few weeks. Meanwhile maybe you can propose the solution to this and make a Pull Request?

@shirakun hi, thanks for the reporting. Currently we don't have free time to spend on this package, will have only in a few weeks. Meanwhile maybe you can propose the solution to this and make a Pull Request?

Hi
When I have time, I check it and try to fix it.

Fixed in PR #65