zoukankan      html  css  js  c++  java
  • echarts+thinkphp 学习写的第一个程序

    一、前台

    建个名为map.html,代码如下。

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
      <title>分类页面</title>
      <script type="text/javascript" src="__PUBLIC__/js/echarts.min.js"></script>

      <script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>

    </head>
    <body>
      <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
      <div id="main" style=" 600px;height:400px;"></div>
    </body>
    <script type="text/javascript">
      var myChart = echarts.init(document.getElementById('main'));
      var arr1=[],arr2=[];
      function arrTest(meter_no){
      $.ajax({
      type: "post",
      async:false,
      url: "{:U("Property/maptext")}",
      data: {},
      dataType: "JSON",
      success: function(data){
        for (var i = 0; i < data['name'].length; i++) {
          arr1.push(data['name'][i]);
        }
        for (var i = 0; i < data['age'].length; i++) {
          arr2.push(data['age'][i]);
        }
      }
    });
    return arr1,arr2;
    }
    arrTest();
    var option = {
      title: {
        text: '测试'
      },
      tooltip: {
        show: true
      },
      legend: {
        data:['age']
      },
      xAxis : [
      {
        type : 'category',
        data : arr1
      }
      ],
      yAxis : [
      {
        type : 'value'
      }
      ],
      series : [
      {
        "name":"age",
        "type":"bar",
        "data":arr2
      }
      ]
    };
    // 为echarts对象加载数据
    myChart.setOption(option);

    </script>
    </html>

    二、后台

    建个名为PropertyController.class.php控制器,代码如下。

    public function map(){
    $this->display();
    }


    public function maptext(){
    $poem = array();
    $poem['name'] = ["测试1","测试2","测试3","测试4","测试5","测试6"];
    $poem['age'] = [15, 25, 45, 34, 40, 25];
    $this->ajaxReturn ($poem,'JSON');

    }

    三、展示画面:

  • 相关阅读:
    P2522 [HAOI2011]Problem b(容斥)
    P3455 [POI2007]ZAP-Queries
    P2519 [HAOI2011]problem a(线段树优化dp+思维)
    P2516 [HAOI2010]最长公共子序列 (lcs+容斥)
    [HAOI2010]软件安装(缩点+树形dp)
    P2508 [HAOI2008]圆上的整点(神仙题)
    [SDOI2011]消防(树的直径+二分||单调队列)
    QLabel设置字体颜色
    Qt绘制不规则串口
    C++继承关系
  • 原文地址:https://www.cnblogs.com/michellexiaoqi/p/7195351.html
Copyright © 2011-2022 走看看