堆叠柱图 + 折线图 options配置

    1. import { getColor } from '../../util';
    2. export function stackedBarOption(props) {
    3. const { data, xData, yAxis = false, yAxisIndex, theme } = props;
    4. const { length } = data;
    5. const legendData = data.map(it => it.label);
    6. const _options = {
    7. color: getColor(length),
    8. tooltip: {
    9. trigger: 'axis',
    10. backgroundColor: 'rgba(50,50,50,.8)',
    11. textStyle: { color: '#ccc' },
    12. enterable: true,
    13. extraCssText: 'max-height: 300px; overflow: auto;',
    14. },
    15. yAxis: [
    16. {
    17. type: 'value',
    18. position: 'left',
    19. axisLine: { show: false },
    20. axisTick: { show: false },
    21. // 改为虚线网格
    22. splitLine: { lineStyle: { color: '#c1c5ca41', type: 'dashed' } },
    23. axisLabel: { color: '#9da5b2', fontSize: '11' },
    24. ...(yAxis && yAxis),
    25. },
    26. ],
    27. xAxis: {
    28. type: 'category',
    29. boundaryGap: false,
    30. data: xData,
    31. axisTick: {
    32. lineStyle: { color: '#c1c5ca41' },
    33. alignWithLabel: true,
    34. },
    35. splitLine: { show: false },
    36. axisLine: { lineStyle: { color: 'rgba(0,0,0,0)' } },
    37. axisLabel: { color: '#9da5b2', fontSize: '11' },
    38. },
    39. series: data.map(it => {
    40. return {
    41. data: it.value,
    42. name: it.label,
    43. type: it.type || 'bar',
    44. yAxisIndex: it.yAxisIndex,
    45. stack: it.type === 'bar' ? 'Count' : null,
    46. symbol: 'none',
    47. maxWidth: 24,
    48. };
    49. }),
    50. grid: {
    51. top: length > 1 ? 40 : 24,
    52. right: 8,
    53. bottom: 0,
    54. left: 0,
    55. containLabel: true,// 防止标签溢出
    56. },
    57. legend: {
    58. type: 'scroll',
    59. show: length > 1,
    60. data: legendData,
    61. icon: 'roundRect',
    62. top: -4,
    63. itemWidth: 12,
    64. itemHeight: 10,
    65. textStyle: {
    66. color: theme === 'dark' ? '#fff' : '#333',
    67. },
    68. },
    69. };
    70. if (yAxisIndex && typeof yAxisIndex === 'object') {
    71. _options.yAxis.push(yAxisIndex);
    72. }
    73. return _options;
    74. }