小编tim*_*cov的帖子

如何创建响应式 Tradingview 轻量级图表?

我是 Tradingview 图表库的新手,我想创建类似的响应式图表。

问题是,交易视图图表库需要指定宽度和高度。这是代码。

const chart = LightweightCharts.createChart(e, {
      width: e.offsetWidth,
      height: e.offsetHeight,
      layout: {
        backgroundColor: 'rgb(17, 17, 39)',
        textColor: 'rgba(255, 255, 255, 0.9)',
      },
      grid: {
        vertLines: {
          color: 'rgb(41, 44, 58)',
        },
        horzLines: {
          color: 'rgb(41, 44, 58)',
        },
      },
      crosshair: {
        mode: LightweightCharts.CrosshairMode.Normal,
      },
      priceScale: {
        borderColor: 'rgba(197, 203, 206, 0.8)',
      },
      timeScale: {
        borderColor: 'rgba(197, 203, 206, 0.8)',
      },
    });
Run Code Online (Sandbox Code Playgroud)

javascript tradingview-api lightweight-charts

7
推荐指数
3
解决办法
1万
查看次数

如何在 Javascript 中使用 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 …
Run Code Online (Sandbox Code Playgroud)

javascript charts tradingview-api lightweight-charts

2
推荐指数
1
解决办法
3896
查看次数