d3中的负和零对数值

时间:2018-09-18 12:14:56

标签: javascript d3.js

我试图用X轴时间绘制多个叠加图表,而Y轴应在线性和对数刻度之间切换。即使使用d3.scale.log()。clamp(true).domain([])。range([])。nice()

,我也无法以对数刻度来恰当地表示我的图表

下面是我用来将数据点映射到Y轴的代码

_initScaleYMap = function() {
    const chart = this.$root().datum();
    const data = chart.getDataSets() || [];
    const dataSets = chart.getDataSets().filter((ds) => ds.getValueAxisId());
    this.scaleYMap(new Map());
    const dataSetsGroupedByValueAxisId = _.groupBy(dataSets, (dataSet) => dataSet.getValueAxisId());
    Object.entries(dataSetsGroupedByValueAxisId).forEach(([valueAxisId, matchedDataSets]) => {
        data.forEach((d) => {
            const chartValueAxis = chart._getValueAxisById(valueAxisId);
            if (!chartValueAxis) {
                throw `Value axis '${valueAxisId} '`;
            }
            const min = chartValueAxis.getMin();
            const max = chartValueAxis.getMax();
            const domain = (Number.isFinite(min) && Number.isFinite(max) && !this.forceArea()) ? [min, max] : getYDomain(chart, matchedDataSets);
            if (!d.getShowLog()) {
                this.scaleYMap().set(valueAxisId,
                    d3.scale.linear()
                        .domain(domain)
                        .range([this.height() - this.margin().top - this.margin().bottom, 0])
            );
            } else {
                this.scaleYMap().set(valueAxisId,
                d3.scale.log().domain(domain).range([this.height() - this.margin().top - this.margin().bottom, 1]).nice()
            );
            }
        });
    });
    return this;
};

我要在照片的前后附上,分别是y的线性比例和对数比例

On Linear Scale

On Log Scale

0 个答案:

没有答案