当前位置:   article > 正文

若以框架学习(3),echarts结合后端数据展示,暂时完结。_ruoyi echarts

ruoyi echarts

前三天,参加毕业典礼,领毕业证,顿时感到空落落的失去感,没有工作,啥也没有,总感觉一辈子白活了。晚上ktv了一晚上,由于我不咋个唱歌,没心情,听哥几个唱了一晚上周杰伦,回来的时候,还下大雨,躺在床上满满的失败感。

导入echartss

npm install echarts

然后在main.js中配置

import * as echarts from 'echarts';
//导入echats
Vue.prototype.$echarts = echarts;

对了,不要一味粘贴复制,因为我用的ruoyi框架的apis发送的请求,不是axios哦,还有我data中的参数,很多都是没用过的,是我中间思考,测试中没用的变量。

自己的界面先用一个案例

  1. <template>
  2. <div id="app">
  3. <div id="myChart" :style="{width: '800px', height: '600px'}"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import * as echarts from "echarts";
  8. import {listCar} from "@/api/shopcar/car";
  9. import {listSchool, qryName} from "@/api/shool/school";
  10. export default {
  11. data() {
  12. return {
  13. // 遮罩层
  14. loading: true,
  15. // 选中数组
  16. ids: [],
  17. // 非单个禁用
  18. single: true,
  19. // 非多个禁用
  20. multiple: true,
  21. // 显示搜索条件
  22. showSearch: true,
  23. // 总条数
  24. total: 0,
  25. // 【请填写功能名称】表格数据
  26. carList: [],
  27. //测试数组
  28. demoList:[],
  29. // 弹出层标题
  30. title: "",
  31. // 是否显示弹出层
  32. open: false,
  33. // 查询参数
  34. queryParams: {
  35. pageNum: 1,
  36. pageSize: 10,
  37. spuId: null,
  38. spuName: null,
  39. skuId: null,
  40. skuInfo: null,
  41. num: null,
  42. tenantId: null,
  43. tenantName: null,
  44. userId: null,
  45. username: null,
  46. isSelect: null,
  47. addPrice: null,
  48. price: null,
  49. },
  50. // 表单参数
  51. form: {},
  52. // 表单校验
  53. rules: {
  54. }
  55. }
  56. },
  57. created() {
  58. this.getList();
  59. },
  60. //钩子函数
  61. mounted() {
  62. this.draw();
  63. console.log(123456)
  64. console.log(this.carList)
  65. },
  66. methods: {
  67. getList() {
  68. this.loading = true;
  69. listSchool(this.queryParams).then(response => {
  70. console.log(12)
  71. console.log(response)
  72. this.carList = response.rows;
  73. console.log(this.carList)
  74. this.total = response.total;
  75. this.loading = false;
  76. });
  77. },
  78. getName() {
  79. this.loading = true;
  80. qryName().then(response => {
  81. console.log("name")
  82. console.log(response)
  83. this.demoList = response.rows
  84. });
  85. },
  86. draw() {
  87. // 初始化echarts实例
  88. let myChart = echarts.init(document.getElementById('myChart'))
  89. console.log(this.$echarts)
  90. myChart.setOption( {
  91. title: {
  92. text: 'ECharts 入门示例'
  93. },
  94. tooltip: {},
  95. xAxis: {
  96. data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
  97. },
  98. yAxis: {},
  99. series: [
  100. {
  101. name: '销量',
  102. type: 'bar',
  103. data: [5, 20, 36, 10, 10, 20]
  104. }
  105. ]
  106. });
  107. }
  108. }
  109. }
  110. </script>
  111. <style>
  112. #app {
  113. font-family: Avenir, Helvetica, Arial, sans-serif;
  114. -webkit-font-smoothing: antialiased;
  115. -moz-osx-font-smoothing: grayscale;
  116. text-align: center;
  117. color: #2c3e50;
  118. margin-top: 60px;
  119. }
  120. </style>

调整了下代码,终于完成了前后端echars数据

因为数据太多了,有1000条,其实可以限制下不查那么多。

由于自己前端技术问题,迟迟不能完成前后端数据对照,所以很打脑壳,关于this,似乎只能在方法内部使用,全局并不能使用,所以我直接把echarts方法放在回调函数里面。

修改后的代码如下,大家可以参考下

前端当初没搞懂,后端就太简单了,返回一个map

  1. <template>
  2. <div id="app">
  3. <div id="myChart" :style="{width: '800px', height: '600px'}"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import * as echarts from "echarts";
  8. import {listCar} from "@/api/shopcar/car";
  9. import {listSchool, qryName, qryScore} from "@/api/shool/school";
  10. export default {
  11. data() {
  12. return {
  13. // 遮罩层
  14. loading: true,
  15. // 选中数组
  16. ids: [],
  17. // 非单个禁用
  18. single: true,
  19. // 非多个禁用
  20. multiple: true,
  21. // 显示搜索条件
  22. showSearch: true,
  23. // 总条数
  24. total: 0,
  25. // 【请填写功能名称】表格数据
  26. carList: [],
  27. //测试数组
  28. demoList:[],
  29. // 弹出层标题
  30. title: "",
  31. // 是否显示弹出层
  32. open: false,
  33. // 查询参数
  34. queryParams: {
  35. pageNum: 1,
  36. pageSize: 10,
  37. spuId: null,
  38. spuName: null,
  39. skuId: null,
  40. skuInfo: null,
  41. num: null,
  42. tenantId: null,
  43. tenantName: null,
  44. userId: null,
  45. username: null,
  46. isSelect: null,
  47. addPrice: null,
  48. price: null,
  49. },
  50. // 表单参数
  51. form: {},
  52. // 表单校验
  53. rules: {
  54. }
  55. }
  56. },
  57. created() {
  58. },
  59. //钩子函数
  60. mounted() {
  61. this.qryScore();
  62. },
  63. methods: {
  64. qryScore() {
  65. this.loading = true;
  66. qryScore().then(response => {
  67. console.log(1234)
  68. console.log(response)
  69. this.draw(response)
  70. });
  71. },
  72. draw(data) {
  73. // 初始化echarts实例
  74. let myChart = echarts.init(document.getElementById('myChart'))
  75. console.log(this.$echarts)
  76. myChart.setOption( {
  77. title: {
  78. text: 'ECharts 入门示例'
  79. },
  80. tooltip: {},
  81. xAxis: {
  82. data: data.name
  83. },
  84. yAxis: {},
  85. series: [
  86. {
  87. name: '销量',
  88. type: 'bar',
  89. data: data.grade
  90. }
  91. ]
  92. });
  93. }
  94. }
  95. }
  96. </script>
  97. <style>
  98. #app {
  99. font-family: Avenir, Helvetica, Arial, sans-serif;
  100. -webkit-font-smoothing: antialiased;
  101. -moz-osx-font-smoothing: grayscale;
  102. text-align: center;
  103. color: #2c3e50;
  104. margin-top: 60px;
  105. }
  106. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/769302
推荐阅读
相关标签
  

闽ICP备14008679号