Javascript 如何在特定数据点对图表进行注释

Javascript 如何在特定数据点对图表进行注释,javascript,protovis,Javascript,Protovis,使用Protovis,我生成了一个类似于以下内容的烛台图表:。我需要为一个特定的烛台标注图表。例如,我可以在12:00烛台的位置画三角形。如何找到特定烛台的位置(左侧和底部)?我认为标准的protovis方法是将注释标记作为您感兴趣的数据点的子标记,然后将其visible属性设置为仅显示您感兴趣的数据点。对于烛台示例,它可能如下所示: // the thin line of the candlestick var candlestick = vis.add(pv.Rule) .data(

使用Protovis,我生成了一个类似于以下内容的烛台图表:。我需要为一个特定的烛台标注图表。例如,我可以在12:00烛台的位置画三角形。如何找到特定烛台的位置(左侧和底部)?

我认为标准的protovis方法是将注释标记作为您感兴趣的数据点的子标记,然后将其
visible
属性设置为仅显示您感兴趣的数据点。对于烛台示例,它可能如下所示:

// the thin line of the candlestick
var candlestick = vis.add(pv.Rule)
    .data(vix)
    .left(function(d) x(d.date))
    .bottom(function(d) y(Math.min(d.high, d.low)))
    .height(function(d) Math.abs(y(d.high) - y(d.low)))
    .strokeStyle(function(d) d.open < d.close ? "#ae1325" : "#06982d");

// the thick line of the candlestick
candlestick.add(pv.Rule)
    .bottom(function(d) y(Math.min(d.open, d.close)))
    .height(function(d) Math.abs(y(d.open) - y(d.close)))
    .lineWidth(10);

// the annotation mark
candlestick.add(pv.Dot)
    .size(40)
    .shape("triangle")
    .left(function() {
        // candlestick here refers to the parent instance
        return candlestick.left()
    })
    .top(function() {
        // candlestick here refers to the parent instance
        // this is 10px from the top of the candlestick
        return h - candlestick.bottom() - candlestick.height() - 10;
    })
    .visible(function(d) {
        // only show the mark for the data we care about - here, June 12
        // (month is 0-based)
        return d.date.getUTCMonth() == 5 && d.date.getUTCDate() == 12;
    });
//烛台的细线
var烛台=可视添加(pv.规则)
.数据(vix)
.左(功能(d)x(d.日期))
.bottom(函数(d)y(数学最小值(d.high,d.low)))
.高度(函数(d)数学abs(y(d.高)-y(d.低)))
.strokeStyle(功能(d)d.open

另一个选项是,如果您需要获取protovis上下文之外的数据(例如,您希望在那里用HTML文本显示
div
),则在定义数据时(例如,在
底部
高度
烛台
定义的属性函数中)获取数据并将其存储在全局变量中。但是这很难看。

我认为标准的protovis方法是将注释标记作为您感兴趣的数据点的子标记,然后将其
visible
属性设置为仅显示您感兴趣的数据点。对于烛台示例,它可能如下所示:

// the thin line of the candlestick
var candlestick = vis.add(pv.Rule)
    .data(vix)
    .left(function(d) x(d.date))
    .bottom(function(d) y(Math.min(d.high, d.low)))
    .height(function(d) Math.abs(y(d.high) - y(d.low)))
    .strokeStyle(function(d) d.open < d.close ? "#ae1325" : "#06982d");

// the thick line of the candlestick
candlestick.add(pv.Rule)
    .bottom(function(d) y(Math.min(d.open, d.close)))
    .height(function(d) Math.abs(y(d.open) - y(d.close)))
    .lineWidth(10);

// the annotation mark
candlestick.add(pv.Dot)
    .size(40)
    .shape("triangle")
    .left(function() {
        // candlestick here refers to the parent instance
        return candlestick.left()
    })
    .top(function() {
        // candlestick here refers to the parent instance
        // this is 10px from the top of the candlestick
        return h - candlestick.bottom() - candlestick.height() - 10;
    })
    .visible(function(d) {
        // only show the mark for the data we care about - here, June 12
        // (month is 0-based)
        return d.date.getUTCMonth() == 5 && d.date.getUTCDate() == 12;
    });
//烛台的细线
var烛台=可视添加(pv.规则)
.数据(vix)
.左(功能(d)x(d.日期))
.bottom(函数(d)y(数学最小值(d.high,d.low)))
.高度(函数(d)数学abs(y(d.高)-y(d.低)))
.strokeStyle(功能(d)d.open
另一个选项是,如果您需要获取protovis上下文之外的数据(例如,您希望在那里用HTML文本显示
div
),则在定义数据时(例如,在
底部
高度
烛台
定义的属性函数中)获取数据并将其存储在全局变量中。不过这很难看