简体   繁体   English

具有 2 个数据集的 Echarts 图表未显示第二个 xAxis 标签

[英]Echarts graph with 2 dataset not showing up 2nd xAxis labels

I have an eCharts graph with 2 datasets and I want to show 2 xAxis, one on top of the chart and the other one at the bottom.我有一个包含 2 个数据集的 eCharts 图,我想显示 2 个 xAxis,一个在图表顶部,另一个在底部。 I must be missing some config settings because I can't figure out how to show the second xAxis labels.我一定错过了一些配置设置,因为我不知道如何显示第二个 xAxis 标签。 1st xAxis shows correctly but 2nd one only shows the axis name, no ticks labels.第一个 xAxis 正确显示,但第二个仅显示轴名称,没有刻度标签。

Please see attached screenshot for a visual reference.请参阅随附的屏幕截图以获取视觉参考。

Missing labels for 2nd xAxis第二个 xAxis 缺少标签

I've tried multiple settings but no luck, these are my chart options so far:我尝试了多种设置,但没有运气,这些是我的图表选项:

this.chartOptions = {
        backgroundColor: this.isFirstChart ? '' : '#F7F8FD',
        grid: {
            show: true,
            top: 50,
            left: this.isFirstChart ? 75 : 15,
            right: this.isFirstChart ? 0 : 15,
            bottom: 50,
            borderColor: this.isFirstChart ? '#00000000' : '#DBDDE6',
        },
        yAxis: {
            id: 0,
            gridIndex: 0,
            type: 'time',
            inverse: true,
            data: this.channel1.map(({ time }) => time ?? 0),
            axisLabel: {
                hideOverlap: true,
                show: !!this.isFirstChart,
                formatter: ((ms: number) => DateUtil.format(ms)),
            },
            axisTick: {
                lineStyle: {
                    width: 0
                },
                inside: this.isFirstChart
            },
            axisLine: {
                show: false
            },
            splitLine: {
                show: true
            },
        },
        xAxis: [{
            type: 'value',
            axisLabel: {
                showMinLabel: true,
                showMaxLabel: true,
                fontSize: 10,
                color: '#8086B1',
                show: !this.isFirstChart,
            },
            interval: 1000000,
            axisLine: {
                show: false,
            },
            splitLine: {
                show: true,
                lineStyle: { type: 'dashed' }
            },
            name: this.chartMeta.channelsNames[0],
            nameLocation: 'middle',
            nameGap: 30,
            nameTextStyle: {
                color: this.chartMeta.colors[0]
            },
        },
        {
            type: 'value',
            axisLabel: {
                showMinLabel: true,
                showMaxLabel: true,
                show: !this.isFirstChart,
                fontSize: 10,
                color: '#8086B1',
            },
            interval: 1000000,
            axisLine: {
                show: false,
            },
            splitLine: {
                show: true,
                lineStyle: { type: 'dashed' }
            },
            name: this.chartMeta.channelsNames[1],
            nameLocation: 'middle',
            nameGap: 30,
            nameTextStyle: {
                color: this.chartMeta.colors[1]
            }
        }],
        series: [
            {
                name: this.chartMeta.channelsNames[0],
                type: 'line',
                symbol: 'none',
                connectNulls: true,
                color: this.chartMeta.colors[0],
                data: this.channel1.map((data) => [data.value as number, data.time]),
            },
            {
                name: this.chartMeta.channelsNames[1],
                type: 'line',
                symbol: 'none',
                connectNulls: true,
                color: this.chartMeta.colors[1],
                data: this.channel2.map((data) => [data.value as number, data.time]),

            },
        ],
    };

Ok so after a few more attempts I found the issue:好的,经过几次尝试后,我发现了问题:

  • Removing both interval from xAxis从 xAxis 中删除两个interval
  • Referencing each series to its respective axes.将每个series引用到其各自的轴。

Working now as expected.现在按预期工作。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM