Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Javascript中的Tradingview轻量级图表为单行系列提供多种颜色?_Javascript_Charts_Tradingview Api_Lightweight Charts - Fatal编程技术网

如何使用Javascript中的Tradingview轻量级图表为单行系列提供多种颜色?

如何使用Javascript中的Tradingview轻量级图表为单行系列提供多种颜色?,javascript,charts,tradingview-api,lightweight-charts,Javascript,Charts,Tradingview Api,Lightweight Charts,下面这张图片就是我现在看到的。 下面这张图片就是我想要的。第一张图片来自我的代码,第二张来自tradingview。 要明确的是:我想要一条线有多种颜色。就我的情况而言,我只需要两种颜色。我需要我创造的每一条新的线都可以改变颜色。如果右边的价格标签也改变了图表右边的线的颜色,那就很好了 这是我的代码: var chart = LightweightCharts.createChart(document.getElementById("Chart"), {width: 1500, height:

下面这张图片就是我现在看到的。 下面这张图片就是我想要的。第一张图片来自我的代码,第二张来自tradingview。

要明确的是:我想要一条线有多种颜色。就我的情况而言,我只需要两种颜色。我需要我创造的每一条新的线都可以改变颜色。如果右边的价格标签也改变了图表右边的线的颜色,那就很好了

这是我的代码:

var chart = LightweightCharts.createChart(document.getElementById("Chart"), {width: 1500, height: 700});

/**
 * Creates startline and adds extra options to the lineSeries.
 */
function initChartSettings() {
    // Init lines
    priceArea = chart.addAreaSeries();
    buySellLine = chart.addLineSeries();   //LINE THAT NEEDS TWO COLORS

    // Set start position of lines
    priceArea.setData([{time: '2019-04-11', value: startPrice}]);
    buySellLine.setData([{time: '2019-04-11', value: startPrice}]);

    // Visualization edits
    priceArea.applyOptions({
        topColor: 'rgba(70, 130, 180, 0.5)',
        bottomColor: 'rgba(70, 130, 180, 0.1)',
        lineColor: '#4682B4'
    });

    // Buy sell line
    buySellLine.applyOptions({
        color: '#42f54b',               //CHANGES COLOR OF THE COMPLETE LINE, FROM BEGIN TO END.
        priceLineVisible: true,
        lastValueVisible: true
    });

    updateChartStatic();
}


/**
 * Updates the chart its lines.
 */
function updateChartStatic() {
    setTimeout(() => {
        priceArea.update({
            time: yearMonthDay,   //How this works should not matter for question
            value: newPrice,      //Same as above
        });

        // Updates the price line of the chart.
        buySellLine.update({
            time: yearMonthDay,
            value: currentMovingAverage       //Even though it would be nice to do the below commented thing...
            // color: 'red or green (example)'
        });

        buySellLine.applyOptions({
            color: changeLineColor(currentMovingAverage, lastMovingAverage)  // CHANGES COMPLETE LINE :(
        });
    }, 1);
}

changeLineColor函数正在执行if语句,该语句与将颜色设置为线条无关。

现在不可能,但此功能存在问题。您可以订阅它,以便在它被修复时收到通知,甚至可以提出建议和/或提供带有更改的PR。

现在不可能,但此功能存在问题。您可以订阅它,以便在它被修复时收到通知,甚至可以提出建议和/或提供带有更改的PR