image.png

    1. option = {
    2. width: 165,
    3. height: 165,
    4. series: [
    5. {
    6. name: 'Access From',
    7. type: 'pie',
    8. radius: ['70%', '85%'],
    9. avoidLabelOverlap: false,
    10. itemStyle: {
    11. borderRadius: 10,
    12. borderWidth: 5,
    13. borderColor: "#fff", // "rgba(12, 49, 95, 0.5)",
    14. color: function(params) {
    15. // 传入的是数据项 seriesIndex, dataIndex, data, value 等各个参数
    16. const color = ['#1ab0a5', '#6db436', '#d53f46', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc']
    17. return color[params.dataIndex];
    18. }
    19. },
    20. label: {
    21. show: false,
    22. },
    23. emphasis: {
    24. label: {
    25. show: false,
    26. }
    27. },
    28. labelLine: {
    29. show: false
    30. },
    31. data: [
    32. { value: 1048, name: 'Search Engine' },
    33. { value: 735, name: 'Direct' },
    34. { value: 580, name: 'Email' },
    35. ]
    36. }
    37. ]
    38. }
    1. <template>
    2. <div
    3. ref="echartsDemo"
    4. class="charts chart-pie"
    5. ></div>
    6. </template>
    7. <script>
    8. import * as echarts from 'echarts'
    9. export default {
    10. name: 'CockpitEChartPie',
    11. props: {
    12. value: Array,
    13. },
    14. data() {
    15. return {}
    16. },
    17. mounted() {
    18. this.$nextTick(() => {
    19. this.init();
    20. })
    21. },
    22. methods: {
    23. init() {
    24. const option = {
    25. series: [
    26. {
    27. name: 'Access From',
    28. type: 'pie',
    29. radius: ['70%', '85%'],
    30. avoidLabelOverlap: false,
    31. itemStyle: {
    32. borderRadius: 10,
    33. borderWidth: 5,
    34. borderColor: "#0c315f", // "rgba(12, 49, 95, 0.5)",
    35. color: function(params) {
    36. // 传入的是数据项 seriesIndex, dataIndex, data, value 等各个参数
    37. const color = ['#1ab0a5', '#6db436', '#d53f46', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc']
    38. return color[params.dataIndex];
    39. }
    40. },
    41. label: {
    42. show: false,
    43. },
    44. emphasis: {
    45. label: {
    46. show: false,
    47. }
    48. },
    49. labelLine: {
    50. show: false
    51. },
    52. data: [
    53. { value: 1048, name: 'Search Engine' },
    54. { value: 735, name: 'Direct' },
    55. { value: 580, name: 'Email' },
    56. ]
    57. }
    58. ]
    59. };
    60. const echartsPie = echarts.init(this.$refs.echartsDemo);
    61. echartsPie.setOption(option)
    62. }
    63. }
    64. }
    65. </script>
    66. <style lang="scss">
    67. .charts {
    68. width: 100%;
    69. height: 100%;
    70. }
    71. </style>