如何查看日期范围以查看所选日期高级图表中的数据

时间:2017-10-20 09:11:44

标签: javascript php mysql laravel highcharts

HTML,JS和Controller



public function graph(Request $request) 
{
    $statistics = DiraStatistics::where('date_access',$request->date)->get();

    $question_asked_sum = $statistics->sum('question_asked');
    $low_confidence_sum = $statistics->sum('low_confidence');
    $no_answer_sum = $statistics->sum('no_answer');
    $missing_intent_sum = $statistics->sum('missing_intent');

    return view('AltHr.Chatbot.graph', compact('question_asked_sum', 'low_confidence_sum', 'no_answer_sum', 'missing_intent_sum'));
}

<form id="form-project" role="form" action="{{action('AltHr\Chatbot\TrackerController@graph')}}" autocomplete="off" method="POST">
  {{csrf_field()}}
  <div class="form-group form-group-default required" >
      <label>Date</label>
      <input type="date" class="form-control" name="date" required>
  </div>
  <button class="btn alt-btn-black btn-xs alt-btn pull-right" type="submit">Select</button>
</form>


<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<script type="text/javascript">
  
$(document).ready(function () {

    // Build the chart
    Highcharts.chart('container', {
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            type: 'pie'
        },
        title: {
            text: 'Pie Chart'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: false
                },
                showInLegend: true
            }
        },
        credits: {
          enabled: false
        },
        exporting: {
          enabled: false
        },
        series: [{
            name: 'Percentage',
            colorByPoint: true,
            data: [{
                name: 'Questions Asked',
                y: {!! $question_asked_sum !!},
                sliced: true,
                selected: true
            }, {
                name: 'Low Confidence',
                y: {!! $low_confidence_sum !!}
            }, {
                name: 'No Answer',
                y: {!! $no_answer_sum !!}
            }, {
                name: 'Missing Intent',
                y: {!! $missing_intent_sum !!}
            }]
        }]
    });
});


</script>
&#13;
&#13;
&#13;

大家好,所以目前我已成功完成了一项功能,我可以从表格中选择一个日期(只有一个日期)并查看数据(饼图)。但我想知道我怎么能做2个日期输入来做&#34;来自&#34;和&#34;到&#34;做一个日期范围来查看所选日期范围的图表中的数据,例如2017年1月1日至5月1日,所以我只能查看从1日到5日的数据。

1 个答案:

答案 0 :(得分:1)

要获取两个日期之间的数据,您可以使用whereBetween功能。 这里的文档: https://laravel.com/docs/5.5/queries

示例:

Model::whereBetween('field', array($date_start, $date_end))

所以在您的代码中如下:

DiraStatistics::whereBetween('date_access',array($request->date, $request->date_end))->get();