javascript - 如何执行日期范围以查看选定日期 Highcharts 中的数据

标签 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>

大家好,目前我已经成功完成了一项功能,我可以从表单中选择一个日期(仅一个日期)并查看数据(饼图)。但我想知道如何进行 2 个日期输入以执行“从”和“到”以执行日期范围以查看所选日期范围的图表中的数据,例如 1/1/2017 - 5/1/2017所以我只能查看从1号到5号的数据。

最佳答案

要获取 2 个日期之间的数据,您可以使用 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();

关于javascript - 如何执行日期范围以查看选定日期 Highcharts 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46845899/

相关文章:

javascript - 难以对齐 div

javascript - 当我单击操作下拉菜单时,选项显示在滚动条中,为什么?

mysql - Laravel:服务器发送的未知类型 245。

php从sql数据库读取数据

javascript - 为什么脚本类型前面有 "text/"?

javascript - jQuery:动画背景图像

php - 单击发送按钮后列表框将数据发送到文本区域

PHP 警告 : proc_open(): CreateProcess failed, 错误代码 - 267

php - 在包含大量文件的文件夹中匹配文件名的更快方法

sql - 用于检索 'most popular' 表行的高效数据库设计