欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

laravel5.5添加echarts實(shí)現(xiàn)畫圖功能的方法

 更新時(shí)間:2019年10月09日 16:00:13   作者:yiluohan0307  
今天小編就為大家分享一篇laravel5.5添加echarts實(shí)現(xiàn)畫圖功能的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

一、下載echarts

我用的是3.X版本,下載地址

二、在頁面中引入echarts

<script type="text/javascript" src="/js/echarts.min.js"></script>

我把下載下來的echarts.min.js放在了public/js/目錄下

三、通過post的請(qǐng)求獲取數(shù)據(jù)并在頁面展示

1.添加路由

Route::get('/test2', 'CunliangController@test2')->name('test2');

Route::post('/odata', 'CunliangController@odata');

/test2用來展示echarts的界面,/odata獲取數(shù)據(jù)。

2.控制器添加代碼

public function test2()
{
 return view('cunliang.test2');
}
public function odata()
{
 //返回最近七天的數(shù)據(jù)
 $data = Cunliang::where("file_type", "O")->latest()
     ->take(7)
     ->get();

 return array_reverse($data->toArray(),false);

}

3.頁面blade模板添加

<div id="contain" style="width: 950px;height:400px;"></div>

4.添加js

<script type="text/javascript">
 var names = [];
 var ttls = [];
 function getData()
 {
  $.post("{{ url('/odata') }}", {
   "_token": "{{ csrf_token() }}"
  }, function(data) {
   $.each(data, function(i, item) {
    names.push(item.update_date);
    ttls.push(item.space_size);
   });
  });
 }
 getData();
 function chart() {
  var myChart = echarts.init(document.getElementById("contain"));


  option = {
   title : {
    text: 'O域數(shù)據(jù)最近7天更新情況'
   },
   tooltip : {
    trigger: 'axis'
   },
   legend: {
    data:['數(shù)據(jù)大小']
   },
   toolbox: {
    show : true,
    feature : {
     mark : {show: true},
     dataView : {show: true, readOnly: false},
     magicType : {show: true, type: ['line', 'bar']},
     restore : {show: true},
     saveAsImage : {show: true}
    }
   },
   calculable : true,
   xAxis : [
    {
     axisLine: {
      lineStyle: { color: '#333' }
     },
     axisLabel: {
      rotate: 30,
      interval: 0
     },
     type : 'category',
     boundaryGap : false,
     data : names // x的數(shù)據(jù),為上個(gè)方法中得到的names
    }
   ],
   yAxis : [
    {
     type : 'value',
     axisLabel : {
      formatter: '{value} M'
     },
     axisLine: {
      lineStyle: { color: '#333' }
     }
    }
   ],
   series : [
    {
     name:'數(shù)據(jù)大小',
     type:'line',
     smooth: 0.3,
     data: ttls // y軸的數(shù)據(jù),由上個(gè)方法中得到的ttls
    }
   ]
 };
 // 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表。
 myChart.setOption(option);
 }
 setTimeout('chart()', 1000);
</script>

其中g(shù)etdata通過post得到的數(shù)據(jù)為echart準(zhǔn)備數(shù)據(jù),function chart()為echart的數(shù)據(jù)展示形式,可以根據(jù)自己需求在官網(wǎng)查找。

參考資料

使用laravel和ECharts實(shí)現(xiàn)折線圖效果

官網(wǎng)教程

以上這篇laravel5.5添加echarts實(shí)現(xiàn)畫圖功能的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論