资料

  1. 问题解决前后的展示截图(截图被压缩了,实际效果比较明显)

显示模糊的展示截图
问题解决后的展示

  1. 产生问题的原因

canvas 在使用的时候给的 widthheight 与实际展示出来的宽高比例不为 1:1,造成像素值的偏离
canvas 标签截图

  1. 解决问题
  • 解决参考地址

echart github 项目中问题所回复的有效答案
image.png

  • 具体添加代码 ``` null, {devicePixelRatio: 2}
  1. ### 2. 隐藏掉柱形图表的数据分裂线,因为两次的比例不同造成重叠了
  2. - 示例图片
  3. > ![隐藏前](https://upload-images.jianshu.io/upload_images/9064013-4b8b20632134a19f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)<br />
  4. ![隐藏后](https://upload-images.jianshu.io/upload_images/9064013-855a6720922ea0a6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
  5. - 设置的方法

option.yAxis[index].splitLine.show: false

  1. ### 3. 多种数据时 `series[index]` 引用不同的 `yAxis` 设置,以及在 `series[index]` 中嵌套数据
  2. - 示例图片
  3. > ![示例图片](https://upload-images.jianshu.io/upload_images/9064013-855a6720922ea0a6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)<br />
  4. 【月收入】数据使用的是左侧的数据作参考,【同比】使用的是右侧的百分比数据作参考,【TO】使用的也是左侧的数据作参考
  5. - 总的展示方案:
  6. > 【月收入】数据中单独展示出【TO】的一行数据,这两个数据都是以左侧为参照,【同比】数据单独展示,并 以右侧为参考
  7. - `option` 配置代码展示

opation = { title: { text: ‘月收入趋势’, textStyle: { fontSize: 17, fontWeight: 800, color: “#37394C” }, left: ‘1%’, top: “5%” }, tooltip: { trigger: ‘axis’ }, grid: { left: ‘2%’, right: ‘2%’, top: “20%”, bottom: ‘5%’, containLabel: true }, legend: { data: [‘月收入’, ‘同比’, { name: ‘T0’, icon: ‘image:///static/img/module/index/S.png’ } ], top: 15, selectedMode: false, formatter: function (data) { return data + “ “; } }, xAxis: [ { type: ‘category’, data: [‘1月’, ‘2月’, ‘3月’, ‘4月’, ‘5月’, ‘6月’, ‘7月’, ‘8月’, ‘9月’, ‘10月’, ‘11月’, ‘12月’], axisPointer: { type: ‘shadow’ }, axisLine: { show: false, color: ‘#8795A8’

  1. },
  2. axisTick: {
  3. show: false
  4. },
  5. axisPointer: {
  6. type: 'line'
  7. },
  8. axisLabel: {
  9. textStyle: {
  10. color: '#8795A8',
  11. }
  12. }
  13. }],
  14. yAxis: [
  15. {
  16. // 月收入 规则
  17. type: 'value',
  18. min: 0,
  19. axisLine: {
  20. show: false
  21. },
  22. axisTick: {
  23. show: false
  24. },
  25. axisLabel: {
  26. formatter: '{value}',
  27. textStyle: {
  28. color: '#8795A8',
  29. }
  30. }
  31. },
  32. {
  33. // 同比 规则
  34. type: 'value',
  35. min: -5,
  36. // 起始线是否显示
  37. axisLine: {
  38. show: false
  39. },
  40. // 起始线延长出的分裂线是否展示
  41. splitLine: {
  42. show: false
  43. },
  44. axisTick: {
  45. show: false
  46. },
  47. axisLabel: {
  48. formatter: '{value} %',
  49. textStyle: {
  50. color: '#8795A8',
  51. }
  52. }
  53. }
  54. ],
  55. series: [
  56. {
  57. name: '月收入',
  58. type: 'bar',
  59. color: '#3E82FE',
  60. barWidth: 20,
  61. // 嵌套【TO】数据
  62. markLine: {
  63. symbol: 'none',
  64. silent: false,
  65. itemStyle: {
  66. normal: {
  67. borderWidth: 2,
  68. lineStyle: {
  69. type: 'dashed',
  70. color: '#D0021B',
  71. width: 1.5
  72. },
  73. }
  74. },
  75. data: [{
  76. yAxis: $T0
  77. }]
  78. },
  79. data: $incom
  80. },
  81. {
  82. name: '同比',
  83. type: 'line',
  84. symbolSize: 8,
  85. color: '#01BF8F',
  86. // 使用【同比】规则
  87. yAxisIndex: 1,
  88. data: $percent
  89. }
  90. ]

}

  1. ### 4. 让地图中显示的文字居中
  2. - 默认的文字显示位置的规则
  3. > 全国:省份名称默认位置是在省会的位置;<br />
  4. 这个规则是 `jsonData.features[index].properties.cp` 字段的经纬度,两个数值设置的<br />
  5. ![默认显示截图](https://upload-images.jianshu.io/upload_images/9064013-d2f619a18c792fbf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
  6. - 解决方法
  7. > 参考文章:[地图区域的label 文字显示在区域边界上了,如何调整label的位置 #4866](https://github.com/apache/incubator-echarts/issues/4866#issuecomment-270562424)<br />
  8. ![解决方法](https://upload-images.jianshu.io/upload_images/9064013-815f6f3fa914090d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

let mapJson = require(“@/utils/map/json/china.json”);

mapJson.features.forEach(element => { delete element.properties.cp; });

  1. - 最后的显示效果
  2. > ![调整后的显示效果](https://upload-images.jianshu.io/upload_images/9064013-70029ab017374f57.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
  3. ### 5. 地图的默认大小和滚动缩放的功能设置

series: [ { name: “测试”, type: “map”, // 默认展示的比例 zoom: 1.2, // 是否开启平游或缩放 roam: true, // 滚轮缩放的极限控制 scaleLimit: { min: 1, max: 10 }, } ]

  1. ### 6. 为 `series.label.formatter` 函数内部的内容单独设置样式
  2. > [官网配置文档](https://echarts.apache.org/zh/option.html#series-funnel.label.rich)
  3. - 思路
  4. > 使用上面官方网站提供的方法添加一个样式变量,之后在 `formatter` 中使用
  5. - 配置源码
  1. // 漏斗形
  2. funnelChart: {
  3. calculable: true,
  4. color: ["#FFA944", "#39A0FF"],
  5. series: [
  6. {
  7. name: "漏斗图",
  8. type: "funnel",
  9. gap: 1,
  10. width: "40%",
  11. left: "0",
  12. right: "0",
  13. top: "0",
  14. bottom: "0",
  15. minSize: "0%",
  16. maxSize: "100%",
  17. sort: "ascending",
  18. label: {
  19. show: true,
  20. formatter: params => {
  21. console.log(params);
  22. const { name = "", data = "", money = "" } =
  23. params.data || {};
  24. return `${name} ${data} {gray| ${money}元}`;
  25. },
  26. // 这里是增加自定义样式的地方,可在 label.formatter 中使用
  27. rich: {
  28. gray: {
  29. color: "gray"
  30. }
  31. }
  32. },
  33. labelLine: {
  34. length: 20,
  35. lineStyle: {
  36. width: 1,
  37. type: "solid"
  38. }
  39. },
  40. data: [
  41. {
  42. value: "10",
  43. data: "1000",
  44. money: 1000,
  45. name: "头部客户"
  46. },
  47. {
  48. value: "20",
  49. data: "3000",
  50. money: 3000,
  51. name: "其他客户"
  52. }
  53. ]
  54. }
  55. ]
  56. },
  1. - 最终演示效果
  2. > ![最终演示效果.png](https://upload-images.jianshu.io/upload_images/9064013-592eb8ed5fc4961b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
  3. ### 7. 将 `series[0].type = funnel` 的漏斗图,强行展示成一个固定的 "金字塔" 三角形
  4. > 查阅了很多资料,发现 `echarts` 一直都没有做 `金字塔` 图形的打算,由于 `funnel` 的本身的机制,很容易就造成生成出来的图表 "变形" 的问题,为了解决上述 "变形" 的问题,我只好取巧设置:将 `value` 的属性设置成 `1:2` 的值,注意 `这个 vlue 值,最终只是为了显示起来好看,显示数据的字段并不是这个`,所以需要手动增加展示数据的字段 `data`(这个属性可以自定义,只要在 `formatter` 时取对即可)
  5. - 配置源码
  1. // 漏斗形
  2. funnelChart: {
  3. calculable: true,
  4. color: ["#FFA944", "#39A0FF"],
  5. series: [
  6. {
  7. name: "漏斗图",
  8. type: "funnel",
  9. gap: 1,
  10. width: "40%",
  11. left: "0",
  12. right: "0",
  13. top: "0",
  14. bottom: "0",
  15. minSize: "0%",
  16. maxSize: "100%",
  17. sort: "ascending",
  18. label: {
  19. show: true,
  20. formatter: params => {
  21. console.log(params);
  22. const { name = "", data = "", money = "" } =
  23. params.data || {};
  24. return `${name} ${data} {gray| ${money}元}`;
  25. },
  26. // 这里是增加自定义样式的地方,可在 label.formatter 中使用
  27. rich: {
  28. gray: {
  29. color: "gray"
  30. }
  31. }
  32. },
  33. labelLine: {
  34. length: 20,
  35. lineStyle: {
  36. width: 1,
  37. type: "solid"
  38. }
  39. },
  40. data: [
  41. {
  42. value: "10",
  43. data: "1000",
  44. money: 1000,
  45. name: "头部客户"
  46. },
  47. {
  48. value: "20",
  49. data: "3000",
  50. money: 3000,
  51. name: "其他客户"
  52. }
  53. ]
  54. }
  55. ]
  56. },

```

  • 最终演示效果

最终演示效果.png