SOURCE

console 命令行工具 X clear

                    
>
console
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>双Y轴示例</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
    <style>
        body {
            margin: 0;
            padding: 20px;
            background: #f5f5f5;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 12px rgba(0,0,0,0.1);
        }

        #chart {
            width: 100%;
            height: 500px;
        }

    </style>
</head>
<body>
    <div class="container">
        <div id="chart"></div>
    </div>

    <script>
        const chart = echarts.init(document.getElementById('chart'));
        
        const option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'category',
                data: ['1月', '2月', '3月', '4月', '5月', '6月']
            },
            yAxis: [
                {
                    type: 'value',
                    name: '销量',
                    position: 'left',
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: '#5470c6'
                        }
                    },
                    axisLabel: {
                        formatter: '{value} 个'
                    }
                },
                {
                    type: 'value',
                    name: '收入',
                    position: 'right',
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: '#91cc75'
                        }
                    },
                    axisLabel: {
                        formatter: '{value} 元'
                    }
                }
            ],
            series: [
                {
                    name: '销量',
                    type: 'bar',
                    yAxisIndex: 0,
                    data: [120, 200, 150, 80, 70, 110],
                    itemStyle: {
                        color: '#5470c6'
                    }
                },
                {
                    name: '收入',
                    type: 'line',
                    yAxisIndex: 1,
                    data: [1200, 2000, 1500, 800, 700, 1100],
                    itemStyle: {
                        color: '#91cc75'
                    }
                }
            ]
        };

        chart.setOption(option);

        window.addEventListener('resize', () => {
            chart.resize();
        });
    </script>
</body>
</html>