图表示例

雷达图基本用法 - 图1

标准数据格式

  1. Radar: {
  2. categories: ['维度1', '维度2', '维度3', '维度4', '维度5', '维度6'],
  3. series: [{
  4. name: '成交量1',
  5. data: [90, 110, 165, 195, 187, 172]
  6. }, {
  7. name: '成交量2',
  8. data: [190, 210, 105, 35, 27, 102]
  9. }]
  10. }

调用方法

  1. canvaRadar=new uCharts({
  2. $this:_self,
  3. canvasId: canvasId,
  4. type: 'radar',
  5. fontSize:11,
  6. legend:true,
  7. background:'#FFFFFF',
  8. pixelRatio:_self.pixelRatio,
  9. animation: true,
  10. dataLabel: true,
  11. categories: chartData.categories,
  12. series: chartData.series,
  13. width: _self.cWidth*_self.pixelRatio,
  14. height: _self.cHeight*_self.pixelRatio,
  15. extra: {
  16. radar: {
  17. max: 200//雷达数值的最大值
  18. }
  19. }
  20. });

完整代码示例

  1. <template>
  2. <view class="qiun-columns">
  3. <view class="qiun-bg-white qiun-title-bar qiun-common-mt" >
  4. <view class="qiun-title-dot-light">雷达图</view>
  5. </view>
  6. <view class="qiun-charts" >
  7. <canvas canvas-id="canvasRadar" id="canvasRadar" class="charts"></canvas>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import uCharts from '@/components/u-charts/u-charts.js';
  13. var _self;
  14. var canvaRadar=null;
  15. export default {
  16. data() {
  17. return {
  18. cWidth:'',
  19. cHeight:'',
  20. pixelRatio:1,
  21. }
  22. },
  23. onLoad() {
  24. _self = this;
  25. this.cWidth=uni.upx2px(750);
  26. this.cHeight=uni.upx2px(500);
  27. this.getServerData();
  28. },
  29. methods: {
  30. getServerData(){
  31. uni.request({
  32. url: 'https://www.easy-mock.com/mock/5cc586b64fc5576cba3d647b/uni-wx-charts/chartsdata2',
  33. data:{
  34. },
  35. success: function(res) {
  36. console.log(res.data.data)
  37. let Radar={categories:[],series:[]};
  38. Radar.categories=res.data.data.Radar.categories;
  39. Radar.series=res.data.data.Radar.series;
  40. _self.showRadar("canvasRadar",Radar);
  41. },
  42. fail: () => {
  43. _self.tips="网络错误,小程序端请检查合法域名";
  44. },
  45. });
  46. },
  47. showRadar(canvasId,chartData){
  48. canvaRadar=new uCharts({
  49. $this:_self,
  50. canvasId: canvasId,
  51. type: 'radar',
  52. fontSize:11,
  53. legend:true,
  54. background:'#FFFFFF',
  55. pixelRatio:_self.pixelRatio,
  56. animation: true,
  57. dataLabel: true,
  58. categories: chartData.categories,
  59. series: chartData.series,
  60. width: _self.cWidth*_self.pixelRatio,
  61. height: _self.cHeight*_self.pixelRatio,
  62. extra: {
  63. radar: {
  64. max: 200//雷达数值的最大值
  65. }
  66. }
  67. });
  68. }
  69. }
  70. }
  71. </script>
  72. <style>
  73. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  74. .qiun-charts {
  75. width: 750upx;
  76. height: 500upx;
  77. background-color: #FFFFFF;
  78. }
  79. .charts {
  80. width: 750upx;
  81. height: 500upx;
  82. background-color: #FFFFFF;
  83. }
  84. </style>