0

有没有办法在轻量级图表中为正确的价格比例调整内容?我在文档中没有找到任何相关信息。

我正在尝试显示两个数据系列,但它们的范围不同(数万与数十)

这是我的jsfiddle。我会很感激任何提示。 https://jsfiddle.net/05zx4e76/5/

var chart = LightweightCharts.createChart(tvchart, {
    width: '600',
    height: '300',
    rightPriceScale: {
        visible: true,
    borderColor: 'rgba(197, 203, 206, 1)',
    lockVisibleTimeRangeOnResize: true,
    },
      localization: {
        locale: 'en-US',
    },
    leftPriceScale: {
        visible: true,
    borderColor: 'rgba(197, 203, 206, 1)',
    lockVisibleTimeRangeOnResize: true,
    },
    grid: {
    horzLines: {
        color: '#363C4E',
    },
    vertLines: {
        color: '#2B2B43',
    },
    },
    crosshair: {
        mode: LightweightCharts.CrosshairMode.Normal,
    },
    timeScale: {
        borderColor: 'rgba(197, 203, 206, 1)',
    },
    handleScroll: {
        vertTouchDrag: false,
    },
    layout: {
        backgroundColor: '#2B2B43',
        lineColor: '#2B2B43',
        textColor: '#D9D9D9',
    }
});

chart.applyOptions({
    timeScale: {
        rightOffset: 12,
        barSpacing: 3,
        fixLeftEdge: false,
        rightBarStaysOnScroll: false,
        borderVisible: false,
        borderColor: '#fff000',
        visible: true,
        timeVisible: true,
        secondsVisible: false        }
    }
);
4

2 回答 2

1

如果您尝试使用developmentbuild 而不是productionone(只需替换独立包路径中的字符串),您将收到一个错误:Error: Assertion failed: data must be asc ordered by time, index=1, time=1643907722, prev time=1643911322这意味着您的 line 系列的数据未按应有的顺序排序。

如果您最初对数据进行排序或添加.sort((a, b) => a.time - b.time)到行数据数组旁边,它将按预期工作。

https://jsfiddle.net/Lfegob51/

于 2022-02-04T09:40:55.437 回答
0

通过以下方式解决:

chart.priceScale('right').applyOptions({
    scaleMargins: {
        top: 0.96,
        bottom: 0,
    },
});

我不知道它是如何工作的。文档没有适当的描述。 https://tradingview.github.io/lightweight-charts/docs/api/interfaces/PriceScaleOptions

于 2022-02-03T22:00:24.683 回答