首页 文章

Highstock.js问题:如何仅针对当天数据绘制VWAP指标?

提问于
浏览
0

我开发了一个项目,我们使用Highcharts.js / Highstock.js库 . 我使用烛台图表显示VWAP指标(这里是JSFiddle中的示例代码:http://jsfiddle.net/ogorobets/vh3y8195/) .

var ohlc = JSON.parse(ohlcStringified),
    volume = JSON.parse(volumeStringified);

Highcharts.stockChart('container', {
    chart: {
        borderWidth: 1
    },
    title: {
        text: 'Volume Weighted Average Price (VWAP)'
    },
    legend: {
        enabled: true
    },
    yAxis: [{
        height: '60%'
    }, {
        top: '65%',
        height: '35%',
        offset: 0
    }],
    series: [{
        type: 'candlestick',
        id: 'AAPL',
        name: 'AAPL',
        data: ohlc,
        tooltip: {
            valueDecimals: 2
        }
    }, {
        type: 'column',
        id: 'volume',
        name: 'Volume',
        data: volume,
        yAxis: 1
    }, {
        type: 'vwap',
        linkedTo: 'AAPL',
        showInLegend: true
    }]
});

对于此图表,我需要仅显示当天数据的VWAP指标 . 但在官方文档(https://www.highcharts.com/docs/chart-and-series-types/technical-indicator-series)中,我看到我们只能为某个指标设置参数(如EMA指标的'params: {period: 7}'),但我没有找到一个选项来设置我们显示指标的时间段(在我的情况下为VWAP) . 默认行为是显示整个时间轴的指标 . 请告知是否可以设置显示VWAP指标的时间段?

我的意思是我不需要设置可见范围区域,其中指示器用rangeSelector显示为一天 . 但相反,除了当天,我不需要将VWAP指标绘制到其他图表时间轴区域 . 你知道有没有可能用highstock.js开发它?

先感谢您!

1 回答

  • 0

    您的指标库系列包含每分钟的数据 . 为每个基本系列点计算指标点 . 如果您希望每天都有VWAP,则必须提供适当的每日数据 .

    作为一种变通方法,您可以添加另一个包含每日数据的系列,使其不可见,并将其用作指标计算的基本系列 . 检查下面发布的示例 .

    Highcharts.stockChart('container', {
      chart: {
        borderWidth: 1
      },
      title: {
        text: 'Volume Weighted Average Price (VWAP)'
      },
      legend: {
        enabled: true
      },
      yAxis: [{
        height: '60%'
      }, {
        top: '65%',
        height: '35%',
        offset: 0
      }],
      series: [{
        type: 'candlestick',
        id: 'AAPL',
        name: 'AAPL',
        data: ohlc,
        tooltip: {
          valueDecimals: 2
        }
      }, {
        type: 'column',
        id: 'volume',
        name: 'Volume',
        data: volume,
        yAxis: 1
      }, {
        id: 'test',
        visible: true,
        showInLegend: false,
        color: 'rgba(0, 0, 0, 0)',
        enableMouseTracking: false,
        data: [{
          x: 1543482000000,
          y: 181.05
        }, {
          x: 1543482000000 + 24 * 3600000,
          y: 178.51
        }, {
          x: 1543482000000 + 2 * 24 * 3600000,
          y: 177.03
        }, {
          x: 1543482000000 + 3 * 24 * 3600000,
          y: 178.61
        }, {
          x: 1543482000000 + 4 * 24 * 3600000,
          y: 183.03
        }, {
          x: 1543482000000 + 5 * 24 * 3600000,
          y: 180.03
        }, {
          x: 1543482000000 + 6 * 24 * 3600000,
          y: 176.03
        }]
      }, {
        type: 'vwap',
        params: {
          period: 5
        },
        linkedTo: 'test',
        showInLegend: true
      }]
    });
    

    演示:http://jsfiddle.net/BlackLabel/w1vegobn/

相关问题