ucharts.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <view class="report-content">
  3. <view class="topinfo">
  4. <image style="margin: 40upx;" src="/static/img/ai_top.png"></image>
  5. <view class="mark">得分:18</view>
  6. </view>
  7. <view class="ehcarts-title">测评结果等级</view>
  8. <view>
  9. <image style="margin: 40upx;" src="/static/img/A.png"></image>
  10. <!-- <view>得分DSDSD</view> -->
  11. </view>
  12. <view class="ehcarts-title">评测分析</view>
  13. <view class="qiun-columns">
  14. <view >
  15. <view class="item">学科: 语文</view>
  16. <view class="item">试题数量: 100</view>
  17. </view>
  18. <view >
  19. <view class="item">总分: 100</view>
  20. <view class="item">知识点: 100</view>
  21. </view>
  22. <view class="qiun-charts">
  23. <canvas canvas-id="canvasPie"
  24. id="canvasPie"
  25. class="charts"
  26. :width="cWidth * pixelRatio"
  27. :height="cHeight * pixelRatio"
  28. :style="{'width': cWidth + 'px', 'height' : cHeight+'px'}"
  29. @touchstart="touchPie($event, 'canvasPie')">
  30. </canvas>
  31. </view>
  32. </view>
  33. <view class="ehcarts-title">知识点掌握情况</view>
  34. <view class="qiun-columns">
  35. <view class="qiun-charts3">
  36. <!--#ifdef MP-ALIPAY -->
  37. <canvas
  38. canvas-id="canvasArcbar1"
  39. id="canvasArcbar1"
  40. class="charts3"
  41. :style="{'position': relative, 'left': 20%, 'width':cWidth3*pixelRatio+'px','height':cHeight3*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left': '200px','margin-top':-cHeight3*(pixelRatio-1)/2+'px'}"></canvas>
  42. <canvas canvas-id="canvasArcbar2" id="canvasArcbar2" class="charts3" :style="{'width':cWidth3*pixelRatio+'px','height':cHeight3*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':cWidth3-cWidth3*(pixelRatio-1)/2+'px','margin-top':-cHeight3*(pixelRatio-1)/2+'px'}"></canvas>
  43. <!--#endif-->
  44. <!--#ifndef MP-ALIPAY -->
  45. <canvas
  46. canvas-id="canvasArcbar1"
  47. id="canvasArcbar1" class="charts3"></canvas>
  48. <canvas
  49. canvas-id="canvasArcbar2"
  50. id="canvasArcbar2"
  51. class="charts3" style="margin-left: 250upx;">
  52. </canvas>
  53. <!--#endif-->
  54. </view>
  55. </view>
  56. <view class="ehcarts-title">测评结果</view>
  57. <view style="margin-top: 10px;" class="qiun-columns">
  58. <ai-progress
  59. content="知识点二"
  60. :lineData="true"
  61. strokeWidth="20"
  62. :textInside="true" percentage="80">
  63. </ai-progress>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import uCharts from '@/components/u-charts/u-charts.js'
  69. import aiProgress from '@/components/ai-progress/ai-progress.vue'
  70. import { mapGetters } from 'vuex'
  71. var _self;
  72. var canvasObj = {};
  73. export default {
  74. components: {aiProgress},
  75. data() {
  76. return {
  77. cWidth: '',
  78. cHeight: '',
  79. cWidth2: '', //横屏图表
  80. cHeight2: '', //横屏图表
  81. cWidth3: '', //圆弧进度图
  82. cHeight3: '', //圆弧进度图
  83. arcbarWidth: '', //圆弧进度图,进度条宽度,此设置可使各端宽度一致
  84. gaugeWidth: '', //仪表盘宽度,此设置可使各端宽度一致
  85. tips: '',
  86. pixelRatio: 1,
  87. serverData: '',
  88. itemCount: 30, //x轴单屏数据密度
  89. sliderMax: 50
  90. }
  91. },
  92. computed: {
  93. ...mapGetters({
  94. studentId: 'paper/getStudentId'
  95. })
  96. },
  97. onLoad() {
  98. _self = this;
  99. //#ifdef MP-ALIPAY
  100. uni.getSystemInfo({
  101. success: function(res) {
  102. if (res.pixelRatio > 1) {
  103. //正常这里给2就行,如果pixelRatio=3性能会降低一点
  104. //_self.pixelRatio =res.pixelRatio;
  105. _self.pixelRatio = 2;
  106. }
  107. }
  108. });
  109. //#endif
  110. this.cWidth = uni.upx2px(750);
  111. this.cHeight = uni.upx2px(500);
  112. this.cWidth2 = uni.upx2px(700);
  113. this.cHeight2 = uni.upx2px(1100);
  114. this.cWidth3 = uni.upx2px(250);
  115. this.cHeight3 = uni.upx2px(250);
  116. this.arcbarWidth = uni.upx2px(24);
  117. this.gaugeWidth = uni.upx2px(30);
  118. this.getCtTestReport()
  119. //this.fillData(Data);
  120. },
  121. onReady() {
  122. this.getServerData();
  123. },
  124. methods: {
  125. getCtTestReport () {
  126. this.$httpApi.get('/front/paper/getQuestionByPaperId', params)
  127. .then(response => {
  128. })
  129. },
  130. getServerData() {
  131. uni.showLoading({
  132. title: "正在加载数据..."
  133. })
  134. uni.request({
  135. url: 'https://unidemo.dcloud.net.cn/hello-uniapp-ucharts-data.json',
  136. data: {},
  137. success: function(res) {
  138. _self.fillData(res.data);
  139. },
  140. fail: () => {
  141. _self.tips = "网络错误,小程序端请检查合法域名";
  142. },
  143. complete() {
  144. uni.hideLoading();
  145. }
  146. });
  147. },
  148. fillData(data) {
  149. this.serverData = data;
  150. this.tips = data.tips;
  151. this.sliderMax = data.Candle.categories.length;
  152. let Pie = {
  153. series: []
  154. }
  155. let Arcbar1 = {
  156. series: []
  157. }
  158. let Arcbar2 = {
  159. series: []
  160. }
  161. Pie.series = data.Pie.series;
  162. Arcbar1.series = data.Arcbar1.series;
  163. Arcbar2.series = data.Arcbar2.series;
  164. this.showPie("canvasPie", Pie);
  165. this.showArcbar("canvasArcbar1", Arcbar1);
  166. this.showArcbar2("canvasArcbar2", Arcbar2);
  167. },
  168. showPie(canvasId, chartData) {
  169. canvasObj[canvasId] = new uCharts({
  170. $this: _self,
  171. canvasId: canvasId,
  172. type: 'pie',
  173. fontSize: 11,
  174. padding:[15,15,0,15],
  175. legend:{
  176. show:true,
  177. padding:5,
  178. lineHeight:11,
  179. margin:0,
  180. },
  181. background: '#FFFFFF',
  182. pixelRatio: _self.pixelRatio,
  183. series: chartData.series,
  184. animation: false,
  185. width: _self.cWidth * _self.pixelRatio,
  186. height: _self.cHeight * _self.pixelRatio,
  187. dataLabel: true,
  188. extra: {
  189. pie: {
  190. lableWidth: 15
  191. }
  192. },
  193. })
  194. },
  195. showRadar(canvasId, chartData) {
  196. canvasObj[canvasId] = new uCharts({
  197. $this: _self,
  198. canvasId: canvasId,
  199. type: 'radar',
  200. fontSize: 11,
  201. padding:[15,15,0,15],
  202. legend:{
  203. show:true,
  204. padding:5,
  205. lineHeight:11,
  206. margin:0,
  207. },
  208. background: '#FFFFFF',
  209. pixelRatio: _self.pixelRatio,
  210. animation: false,
  211. dataLabel: true,
  212. categories: chartData.categories,
  213. series: chartData.series,
  214. width: _self.cWidth * _self.pixelRatio,
  215. height: _self.cHeight * _self.pixelRatio,
  216. extra: {
  217. radar: {
  218. max: 200 //雷达数值的最大值
  219. }
  220. }
  221. })
  222. },
  223. showArcbar(canvasId, chartData) {
  224. new uCharts({
  225. $this: _self,
  226. canvasId: canvasId,
  227. type: 'arcbar',
  228. fontSize: 11,
  229. title: {
  230. name: Math.round(chartData.series[0].data * 100) + '%',
  231. color: chartData.series[0].color,
  232. fontSize: 25 * _self.pixelRatio
  233. },
  234. subtitle: {
  235. name: chartData.series[0].name,
  236. color: '#666666',
  237. fontSize: 15 * _self.pixelRatio
  238. },
  239. extra: {
  240. arcbar: {
  241. type: 'default',
  242. width: _self.arcbarWidth * _self.pixelRatio, //圆弧的宽度
  243. }
  244. },
  245. background: '#FFFFFF',
  246. pixelRatio: _self.pixelRatio,
  247. series: chartData.series,
  248. animation: false,
  249. width: _self.cWidth3 * _self.pixelRatio,
  250. height: _self.cHeight3 * _self.pixelRatio,
  251. dataLabel: true,
  252. })
  253. },
  254. showArcbar2(canvasId, chartData) {
  255. new uCharts({
  256. $this: _self,
  257. canvasId: canvasId,
  258. type: 'arcbar',
  259. fontSize: 11,
  260. title: {
  261. name: Math.round(chartData.series[0].data * 100) + '%',
  262. color: chartData.series[0].color,
  263. fontSize: 25 * _self.pixelRatio
  264. },
  265. subtitle: {
  266. name: chartData.series[0].name,
  267. color: '#666666',
  268. fontSize: 15 * _self.pixelRatio
  269. },
  270. extra: {
  271. arcbar: {
  272. type: 'default',
  273. width: _self.arcbarWidth * _self.pixelRatio, //圆弧的宽度
  274. backgroundColor: '#ffe3e8',
  275. startAngle: 1.25,
  276. endAngle: 0.75
  277. }
  278. },
  279. background: '#FFFFFF',
  280. pixelRatio: _self.pixelRatio,
  281. series: chartData.series,
  282. animation: false,
  283. width: _self.cWidth3 * _self.pixelRatio,
  284. height: _self.cHeight3 * _self.pixelRatio,
  285. dataLabel: true,
  286. })
  287. },
  288. changeData() {
  289. canvasObj['canvasColumn'].updateData({
  290. series: _self.serverData.ColumnB.series,
  291. categories: _self.serverData.ColumnB.categories
  292. })
  293. },
  294. touchPie(e,id) {
  295. canvasObj[id].showToolTip(e, {
  296. format: function(item) {
  297. return item.name + ':' + item.data
  298. }
  299. })
  300. },
  301. }
  302. }
  303. </script>
  304. <style>
  305. .report-content {
  306. width: 100%;
  307. height: 100%;
  308. }
  309. .mark {
  310. position: relative;
  311. right: 5%;
  312. text-align: center;
  313. font-size: 22px;
  314. font-weight: 700;
  315. }
  316. .ehcarts-title {
  317. display: flex;
  318. justify-content: space-between;
  319. align-items: center;
  320. font-size: 32upx;
  321. color: white;
  322. padding: 30upx 30upx 30upx 50upx;
  323. margin-top: 20upx;
  324. width: 100%;
  325. position: relative;
  326. background-color: #FF9966;
  327. border-bottom: 1px #FF9966 solid
  328. }
  329. .qiun-columns .item {
  330. /* width: 20upx; */
  331. display: inline-block;
  332. float: left;
  333. margin-top: 20upx;
  334. margin-bottom: 20upx;
  335. margin-left: 50upx;
  336. }
  337. page {
  338. background: #F2F2F2;
  339. width: 750upx;
  340. overflow-x: hidden;
  341. }
  342. .qiun-padding {
  343. padding: 2%;
  344. width: 96%;
  345. }
  346. .qiun-wrap {
  347. display: flex;
  348. flex-wrap: wrap;
  349. }
  350. .qiun-rows {
  351. display: flex;
  352. flex-direction: row !important;
  353. }
  354. .qiun-columns {
  355. display: flex;
  356. flex-direction: column !important;
  357. }
  358. .qiun-common-mt {
  359. margin-top: 10upx;
  360. }
  361. .qiun-bg-white {
  362. background: #FFFFFF;
  363. }
  364. .qiun-title-bar {
  365. width: 96%;
  366. padding: 10upx 2%;
  367. flex-wrap: nowrap;
  368. }
  369. .qiun-title-dot-light {
  370. border-left: 10upx solid #0ea391;
  371. padding-left: 10upx;
  372. font-size: 32upx;
  373. color: #000000
  374. }
  375. /* 通用样式 */
  376. .qiun-charts {
  377. width: 750upx;
  378. height: 500upx;
  379. background-color: #FFFFFF;
  380. }
  381. .charts {
  382. width: 750upx;
  383. height: 500upx;
  384. background-color: #FFFFFF;
  385. }
  386. /* 横屏样式 */
  387. .qiun-charts-rotate {
  388. width: 700upx;
  389. height: 1100upx;
  390. background-color: #FFFFFF;
  391. padding: 25upx;
  392. }
  393. .charts-rotate {
  394. width: 700upx;
  395. height: 1100upx;
  396. background-color: #FFFFFF;
  397. }
  398. /* 圆弧进度样式 */
  399. .qiun-charts3 {
  400. width: 750upx;
  401. height: 250upx;
  402. background-color: #FFFFFF;
  403. position: relative;
  404. }
  405. .charts3 {
  406. position: absolute;
  407. width: 250upx;
  408. height: 250upx;
  409. background-color: #FFFFFF;
  410. }
  411. .qiun-tip {
  412. display: block;
  413. width: auto;
  414. overflow: hidden;
  415. padding: 15upx;
  416. height: 30upx;
  417. line-height: 30upx;
  418. margin: 10upx;
  419. background: #ff9933;
  420. font-size: 30upx;
  421. border-radius: 8upx;
  422. justify-content: center;
  423. text-align: center;
  424. border: 1px solid #dc7004;
  425. color: #FFFFFF;
  426. }
  427. </style>