>  기사  >  백엔드 개발  >  laravel 使用 highcharts 传值,前端不显示

laravel 使用 highcharts 传值,前端不显示

WBOY
WBOY원래의
2016-06-06 20:25:141365검색

后端使用laravel将参数传递给前端,但是前端无法正常显示数据,请问到底是哪里出了问题?

laravel 代码:

<code class="php"> $res = HistoryData::where('product_id','1')->get();
            
            //将获取的数据重新排版
            if(count($res) > 0){
                foreach( $res as $value){
                    $timestamp = strtotime(str_replace('/','-',$value['time']));
                    $data[] = [ $timestamp , $value['cumulativeNet']];
                }
            }
            
            //highchart设置内容
            
            //x坐标轴
            $highchart['xAxis'] = [ 'title' => [ 'text' => '时间' ] ];
            
            //y坐标轴
            $highchart['yAxis'] = [ 'title' => [ 'text' => '净值' ] ];
            
            //数据
            $highchart['series'] = [ 'name'=>'净值' , 'data' => $data ];
            
            $highchart['rangeSelector'] = array( 'selected' => '1' );</code>

html代码

<code class="html"><script type="text/javascript" src="/js/highstock.js"></script>
<script type="text/javascript">
    $(function(){
      $('#highchart').highcharts('StockChart',
                                 {!! json_encode($highchart)!!}
      )
      })</script></code>

json数据

<code class="json">{
    "xAxis": {
        "title": {
            "text": "时间"
        }
    },
    "yAxis": {
        "title": {
            "text": "净值"
        }
    },
    "series": {
        "name": "净值",
        "data": [
            [
                1441900800,
                1
            ],
            [
                1439222400,
                1
            ]
        ]
    },
    "rangeSelector": {
        "selected": "1"
    }
}</code>

回复内容:

后端使用laravel将参数传递给前端,但是前端无法正常显示数据,请问到底是哪里出了问题?

laravel 代码:

<code class="php"> $res = HistoryData::where('product_id','1')->get();
            
            //将获取的数据重新排版
            if(count($res) > 0){
                foreach( $res as $value){
                    $timestamp = strtotime(str_replace('/','-',$value['time']));
                    $data[] = [ $timestamp , $value['cumulativeNet']];
                }
            }
            
            //highchart设置内容
            
            //x坐标轴
            $highchart['xAxis'] = [ 'title' => [ 'text' => '时间' ] ];
            
            //y坐标轴
            $highchart['yAxis'] = [ 'title' => [ 'text' => '净值' ] ];
            
            //数据
            $highchart['series'] = [ 'name'=>'净值' , 'data' => $data ];
            
            $highchart['rangeSelector'] = array( 'selected' => '1' );</code>

html代码

<code class="html"><script type="text/javascript" src="/js/highstock.js"></script>
<script type="text/javascript">
    $(function(){
      $('#highchart').highcharts('StockChart',
                                 {!! json_encode($highchart)!!}
      )
      })</script></code>

json数据

<code class="json">{
    "xAxis": {
        "title": {
            "text": "时间"
        }
    },
    "yAxis": {
        "title": {
            "text": "净值"
        }
    },
    "series": {
        "name": "净值",
        "data": [
            [
                1441900800,
                1
            ],
            [
                1439222400,
                1
            ]
        ]
    },
    "rangeSelector": {
        "selected": "1"
    }
}</code>

前端不现实,无非就是前端展现有问题,或者你提供的数据格式并不是它希望得到的格式。

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.