图表示例

横屏模式 - 图1

标准数据格式

  1. "Column": {
  2. "categories": ["2012", "2013", "2014", "2015", "2016", "2017"],
  3. "series": [{
  4. "name": "成交量1",
  5. "data": [15, {"value": 20,"color": "#f04864"}, 45, 37, 43, 34]
  6. }, {
  7. "name": "成交量2",
  8. "data": [30, {"value": 40,"color": "#facc14"}, 25, 14, 34, 18]
  9. }]
  10. }

调用方法

  1. canvaColumn=new uCharts({
  2. $this:_self,
  3. canvasId: canvasId,
  4. type: 'column',
  5. legend:true,
  6. fontSize:11,
  7. background:'#FFFFFF',
  8. pixelRatio:_self.pixelRatio,
  9. animation: true,
  10. rotate:true,
  11. categories: chartData.categories,
  12. series: chartData.series,
  13. xAxis: {
  14. disableGrid:true,
  15. },
  16. yAxis: {
  17. //disabled:true
  18. },
  19. dataLabel: true,
  20. width: _self.cWidth2*_self.pixelRatio,
  21. height: _self.cHeight2*_self.pixelRatio,
  22. extra: {
  23. column: {
  24. type:'group',
  25. width: _self.cWidth*_self.pixelRatio*0.45/chartData.categories.length,
  26. meter:{
  27. //这个是外层边框的宽度
  28. border:4,
  29. //这个是内部填充颜色
  30. fillColor:'#E5FDC3'
  31. }
  32. }
  33. }
  34. });

完整代码示例

  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-rotate" >
  7. <canvas canvas-id="canvasColumn" id="canvasColumn" class="charts-rotate" @touchstart="touchColumn"></canvas>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import uCharts from '@/components/u-charts/u-charts.js';
  13. var _self;
  14. var canvaColumn=null;
  15. export default {
  16. data() {
  17. return {
  18. cWidth2:'',//横屏图表
  19. cHeight2:'',//横屏图表
  20. pixelRatio:1,
  21. }
  22. },
  23. onLoad() {
  24. _self = this;
  25. this.cWidth2=uni.upx2px(700);
  26. this.cHeight2=uni.upx2px(1100);
  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 ColumnColumn={categories:[],series:[]};
  38. //这里我后台返回的是数组,所以用等于,如果您后台返回的是单条数据,需要push进去
  39. ColumnColumn.categories=res.data.data.ColumnB.categories;
  40. ColumnColumn.series=res.data.data.ColumnB.series;
  41. _self.showColumnColumn("canvasColumn",ColumnColumn);
  42. },
  43. fail: () => {
  44. _self.tips="网络错误,小程序端请检查合法域名";
  45. },
  46. });
  47. },
  48. showColumnColumn(canvasId,chartData){
  49. canvaColumn=new uCharts({
  50. $this:_self,
  51. canvasId: canvasId,
  52. type: 'column',
  53. legend:true,
  54. fontSize:11,
  55. background:'#FFFFFF',
  56. pixelRatio:_self.pixelRatio,
  57. animation: true,
  58. rotate:true,
  59. // #ifdef MP-ALIPAY || MP-BAIDU
  60. rotateLock:true,//百度及支付宝需要锁定旋转
  61. // #endif
  62. categories: chartData.categories,
  63. series: chartData.series,
  64. xAxis: {
  65. disableGrid:true,
  66. },
  67. yAxis: {
  68. //disabled:true
  69. },
  70. dataLabel: true,
  71. width: _self.cWidth2*_self.pixelRatio,
  72. height: _self.cHeight2*_self.pixelRatio,
  73. extra: {
  74. column: {
  75. type:'group',
  76. width: _self.cWidth*_self.pixelRatio*0.45/chartData.categories.length,
  77. meter:{
  78. //这个是外层边框的宽度
  79. border:4,
  80. //这个是内部填充颜色
  81. fillColor:'#E5FDC3'
  82. }
  83. }
  84. }
  85. });
  86. },
  87. touchColumn(e){
  88. canvaColumn.showToolTip(e, {
  89. format: function (item, category) {
  90. return category + ' ' + item.name + ':' + item.data
  91. }
  92. });
  93. }
  94. }
  95. }
  96. </script>
  97. <style>
  98. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  99. .qiun-charts-rotate {
  100. width: 700upx;
  101. height: 1100upx;
  102. background-color: #FFFFFF;
  103. padding: 25upx;
  104. }
  105. .charts-rotate {
  106. width: 700upx;
  107. height: 1100upx;
  108. background-color: #FFFFFF;
  109. }
  110. </style>