LineExample2.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { Line } from './BaseCharts'
  2. export default {
  3. extends: Line,
  4. props: {
  5. firstDate: { // 必须提供字段
  6. required: true,
  7. default:false
  8. },
  9. labels: { // 必须提供字段
  10. required: false,
  11. default:false
  12. },
  13. },
  14. watch: {
  15. // 动态加载
  16. firstDate(curVal, oldVal) {
  17. const that = this;
  18. if (curVal) {
  19. this.firstDate = curVal;
  20. that.renderChart({
  21. datasets: this.firstDate,
  22. labels: this.labels,
  23. // labels: '',
  24. }, {
  25. responsive: true,
  26. maintainAspectRatio: false,
  27. cutoutPercentage: 90,//环粗细
  28. showTooltips:false,
  29. title:false,
  30. tooltips:{
  31. mode:'index',
  32. intersect:false
  33. },
  34. legend: {
  35. position:'bottom',
  36. labels: {
  37. boxWidth:12,
  38. fontSize:10
  39. }
  40. },
  41. scales: {
  42. yAxes: [{
  43. ticks: {
  44. beginAtZero: true,
  45. callback: function (value) {
  46. if (value % 1 === 0) {
  47. return value;
  48. }
  49. }
  50. }
  51. }]
  52. }
  53. })
  54. }
  55. },
  56. },
  57. mounted() {
  58. const that = this;
  59. that.renderChart({
  60. labels: this.labels,
  61. datasets:this.firstDate
  62. }, {
  63. responsive: true,
  64. maintainAspectRatio: false,
  65. cutoutPercentage: 90,//环粗细
  66. showTooltips:false,
  67. title:false,
  68. tooltips:{
  69. mode:'index',
  70. intersect:false
  71. },
  72. legend: {
  73. position:'bottom',
  74. labels: {
  75. boxWidth:12,
  76. fontSize:10
  77. }
  78. },
  79. scales: {
  80. yAxes: [{
  81. ticks: {
  82. beginAtZero: true,
  83. callback: function (value) {
  84. if (value % 1 === 0) {
  85. return value;
  86. }
  87. }
  88. }
  89. }]
  90. }
  91. })
  92. }
  93. }