首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在react-d3中只过滤掉chartSeries中的一个序列

在react-d3中只过滤掉chartSeries中的一个序列
EN

Stack Overflow用户
提问于 2017-09-25 15:54:32
回答 1查看 169关注 0票数 2

我正在使用react-d3创建一个具有多个相关数据集的图,我遇到的问题是其中一个数据集不一定对另一个数据集的每个点都有一个条目。我可以将值设置为0,但这会创建有数据的外观,但它是0,但事实并非如此。

下面是我的代码(deliverRate总是有数据,adjustedRate不一定有数据):

代码语言:javascript
复制
const chartSeries = [
        {
            field: 'deliverRate',
            name: 'Delivery Rate',
            color: "#ff7f03"

        },
        {
            field: 'adjustedRate',
            name: 'Adjusted Rate',
            color: 'blue'
        }
    ];

    const x = function (d) {
        return new Date(d.generatedAt);
    }

    return (
        <div>
            <LineTooltip
                data={deliveryInfo.throttleHistory}
                width={1000}
                height={300}
                chartSeries={chartSeries}
                yLabel="Rate"
                x={x}
                xScale="time"
                xDomain={d3.extent(deliveryInfo.throttleHistory,function(d){return x(d)})}
                xLabel="Date"

            >
                <SimpleTooltip/>
            </LineTooltip>
        </div>)

有没有办法创建一个过滤器,只在adjustedRate为null的地方放一个空格?

EN

回答 1

Stack Overflow用户

发布于 2017-10-03 20:56:51

只需在函数x d.adjustedRate = d.adjustedRate||'';中添加下面这一行

代码语言:javascript
复制
const chartSeries = [
            {
                field: 'deliverRate',
                name: 'Delivery Rate',
                color: "#ff7f03"

            },
            {
                field: 'adjustedRate',
                name: 'Adjusted Rate',
                color: 'blue'
            }
        ];

        const x = function (d) {
            d.adjustedRate = d.adjustedRate||'';
            return new Date(d.generatedAt);

        }

        return (
            <div>
                <LineTooltip
                    data={deliveryInfo.throttleHistory}
                    width={1000}
                    height={300}
                    chartSeries={chartSeries}
                    yLabel="Rate"
                    x={x}
                    xScale="time"
                    xDomain={d3.extent(deliveryInfo.throttleHistory,function(d){return x(d)})}
                    xLabel="Date"

                >
                    <SimpleTooltip/>
                </LineTooltip>
            </div>)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46400132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档