简体   繁体   English

如何进行日期范围查看选定日期的图表的数据

[英]How to do a date range to view data from selected date highcharts

HTML, JS and Controller HTML,JS和控制器

 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> 

Hi guys, so currently i have successfully done a function where i can select a date from a form (just one date) and view the data (pie chart). 嗨,大家好,所以目前我已经成功完成了一项功能,可以从表单中选择一个日期(仅一个日期)并查看数据(饼图)。 But i want to know how can i make 2 date input to do a "from" and "to" to do a date range to view the data in the chart of the selected dates range for example 1/1/2017 - 5/1/2017 so i can only view the data from the 1st till the 5th. 但是我想知道如何进行2个日期输入来做一个“从”到“做”一个日期范围,以查看所选日期范围的图表中的数据,例如1/1/2017-5/1 / 2017,因此我只能从1号到5号查看数据。

For get data beetween 2 dates you can use whereBetween function. 要获取两个日期之间的数据,可以使用whereBetween函数。 Here the documentation: https://laravel.com/docs/5.5/queries 这里的文档: https : //laravel.com/docs/5.5/queries

Example: 例:

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

so in your code something like: 所以在您的代码中类似:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM