定制开发小程序Echarts直角坐标系x轴y轴属性设置大全

1、Echarts版本

"echarts": "^5.3.3",

2、定制开发小程序最简单的直角坐标系,定制开发小程序以柱状图为例。

定制开发小程序常见的直角坐标系,x轴设置type: 'category',为类目轴,定制开发小程序适用于离散的类目数据;y轴设置type: 'value',为数值轴,定制开发小程序适用于连续数据。

  1. <template>
  2. <div ref="barChart" class="chart-content">暂无数据</div>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. export default {
  7. name: 'bar',
  8. data() {
  9. return {};
  10. },
  11. mounted() {
  12. this.draw();
  13. },
  14. methods: {
  15. draw() {
  16. this.chart = echarts.init(this.$refs.barChart);
  17. var option = {
  18. xAxis: {
  19. type: 'category',
  20. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
  21. },
  22. yAxis: {
  23. type: 'value'
  24. },
  25. series: [
  26. {
  27. data: [120, 200, 150, 80, 70, 110, 130],
  28. type: 'bar'
  29. }
  30. ]
  31. };
  32. this.chart.setOption(option);
  33. },
  34. },
  35. };
  36. </script>
  37. <style scoped>
  38. .chart-content {
  39. width: 600px;
  40. height: 400px;
  41. box-sizing: border-box;
  42. border: 1px solid #ccc;
  43. }
  44. </style>

渲染结果:

 3、定制开发小程序定制开发小程序坐标轴名称相关设置

  1. name: '时间', // 坐标轴名称
  2. nameLocation: 'end', // 定制开发小程序坐标轴名称显示位置,可取值'start'、'middle' 或 'center'、'end'
  3. // 定制开发小程序坐标轴名称文字样式设置
  4. nameTextStyle: {
  5. color: '#d46c89',
  6. fontWeight: 'bold',
  7. fontSize: '16px',
  8. },
  9. nameGap: 20, // 坐标轴名称与轴线之间的距离,默认值15
  10. nameRotate: 30, // 坐标轴名称旋转,角度值

只设置x轴,渲染效果:

 4、坐标轴轴线相关设置

  1. // 坐标轴轴线相关设置
  2. axisLine: {
  3. show: true, // 是否显示坐标轴轴线
  4. symbol: ['none', 'arrow'], // 轴线两边的箭头,none表示没有箭头,arrow表示有箭头,可取值为字符串或长度为2的数组:默认不显示箭头 'none'。两端都显示箭头 'arrow',只在末端显示箭头 ['none', 'arrow']
  5. symbolSize: [15, 20], // 轴线两边的箭头的大小,第一个数字表示宽度(垂直坐标轴方向),第二个数字表示高度(平行坐标轴方向),默认值[10, 15]。
  6. symbolOffset: 20, // 轴线两边的箭头的偏移,如果是数组,第一个数字表示起始箭头的偏移,第二个数字表示末端箭头的偏移;如果是数字,表示这两个箭头使用同样的偏移。
  7. // 坐标轴轴线样式设置
  8. lineStyle: {
  9. color: '#21a6e6',
  10. width: 2,
  11. type: 'dashed',
  12. }
  13. },

x轴y轴都设置,渲染效果:

 

 5、坐标轴刻度相关设置

  1. // 坐标轴刻度相关设置
  2. axisTick: {
  3. show: true, // 是否显示坐标轴刻度。
  4. interval: 0, // 坐标轴刻度的显示间隔,在类目轴中有效。不设置时默认同 axisLabel.interval 一样。设置成 0 强制显示所有标签。如果设置为 1,表示『隔一个标签显示一个标签』,如果值为 2,表示隔两个标签显示一个标签,以此类推。
  5. inside: true, // 默认值false。true 表示坐标轴刻度朝内,false 表示坐标轴刻度朝外
  6. // 坐标轴刻度样式设置
  7. lineStyle: {
  8. color: '#d96c67',
  9. width: 6,
  10. }
  11. },

只设置X轴,渲染效果:

 6、坐标轴刻度标签相关设置

  1. axisLabel: {
  2. show: true, // 是否显示坐标轴刻度标签。
  3. interval: 0, // 坐标轴刻度标签的显示间隔,在类目轴中有效。设置成 0 强制显示所有标签,如果设置为 1,表示『隔一个标签显示一个标签』,如果值为 2,表示隔两个标签显示一个标签,以此类推
  4. inside: false, // 默认值false。true 表示坐标轴刻度标签朝内,false 表示坐标轴刻度标签朝外
  5. rotate: 30, // 刻度标签旋转的角度,旋转的角度从 -90 度到 90 度
  6. margin: 20, // 刻度标签与轴线之间的距离
  7. color: '#d46c89', // 刻度标签文字的颜色。不设置就默认取 axisLine.lineStyle.color,即与轴线颜色一样
  8. },

只设置x轴,渲染效果:

  7、设置某个类目标签的文字样式

  1. type: 'category',
  2. data: [{ // 类目数据,在类目轴(type: 'category')中有效
  3. value: '周一',
  4. // 突出周一
  5. textStyle: {
  6. fontSize: 20,
  7. color: 'red'
  8. }
  9. }, '周二', '周三', '周四', '周五', '周六', '周日'],

 8、坐标轴指示器相关设置

直线指示器

  1. axisPointer: {
  2. show: true, // 默认不显示。但是如果 tooltip.trigger 设置为 'axis' 或者 tooltip.axisPointer.type 设置为 'cross',则自动显示 axisPointer。坐标系会自动选择显示哪个轴的 axisPointer,也可以使用 tooltip.axisPointer.axis 改变这种选择
  3. type: 'line', // 'line' 直线指示器,'shadow' 阴影指示器,'none' 无指示器
  4. // 坐标轴指示器的文本标签设置
  5. label: {
  6. show: true, // 是否显示文本标签。如果 tooltip.axisPointer.type 设置为 'cross' 则默认显示标签,否则默认不显示
  7. color: 'red',
  8. backgroundColor: '#999',
  9. },
  10. // type: 'line'时坐标轴指示器线的设置
  11. lineStyle: {
  12. color: 'orange', // 线的颜色
  13. width: 3, // 线的宽度
  14. },
  15. }

只设置X轴,鼠标悬浮上去渲染效果:

 阴影指示器

  1. axisPointer: {
  2. show: true, // 默认不显示。但是如果 tooltip.trigger 设置为 'axis' 或者 tooltip.axisPointer.type 设置为 'cross',则自动显示 axisPointer。坐标系会自动选择显示哪个轴的 axisPointer,也可以使用 tooltip.axisPointer.axis 改变这种选择
  3. type: 'shadow', // 'line' 直线指示器,'shadow' 阴影指示器,'none' 无指示器
  4. // 坐标轴指示器的文本标签设置
  5. label: {
  6. show: true, // 是否显示文本标签。如果 tooltip.axisPointer.type 设置为 'cross' 则默认显示标签,否则默认不显示
  7. color: 'red',
  8. backgroundColor: '#999',
  9. },
  10. // type: 'shadow'时坐标轴指示器填充区域的设置
  11. shadowStyle: {
  12. color: 'orange', // 填充的颜色
  13. opacity: 0.4,
  14. },
  15. }

只设置X轴,鼠标悬浮上去渲染效果:

 9、实现坐标轴刻度线和标签对齐

  1. boundaryGap: true, // 类目轴中boundaryGap可取值,true或false,默认true。
  2. axisTick: {
  3. alignWithLabel: true, // 类目轴中在 boundaryGap 为 true 的时候有效,可以保证刻度线和标签对齐。
  4. },

只设置X轴,渲染效果:

 10、设置坐标轴最小刻度值、最大刻度值、分割间隔

  1. min: 50, // 坐标轴刻度最小值
  2. max: 250, // 坐标轴刻度最大值
  3. interval: 40, // 强制设置坐标轴分割间隔

只设置y轴,渲染效果:

 11、完整示例

  1. var option = {
  2. xAxis: {
  3. type: 'category',
  4. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
  5. name: '时间',
  6. nameGap: 20,
  7. axisLine: {
  8. symbol: ['none', 'arrow'],
  9. symbolOffset: 14,
  10. lineStyle: {
  11. color: '#21a6e6',
  12. width: 2,
  13. type: 'dashed',
  14. }
  15. },
  16. axisTick: {
  17. alignWithLabel: true,
  18. lineStyle: {
  19. color: '#d96c67',
  20. width: 6,
  21. }
  22. },
  23. axisLabel: {
  24. interval: 2,
  25. rotate: 30,
  26. margin: 10,
  27. color: '#d46c89',
  28. },
  29. },
  30. yAxis: {
  31. type: 'value',
  32. name: '数值',
  33. nameGap: 20,
  34. axisLine: {
  35. show: true,
  36. symbol: ['none', 'arrow'],
  37. symbolOffset: 14,
  38. lineStyle: {
  39. color: '#21a6e6',
  40. width: 2,
  41. type: 'dashed',
  42. }
  43. },
  44. },
  45. series: [
  46. {
  47. data: [120, 200, 150, 80, 70, 110, 130],
  48. type: 'bar'
  49. },
  50. ]
  51. };

渲染效果:

12、更多配置可查看Echarts官网配置项、

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发