0

我正在使用带导航器的面积图,我想做的是突出显示当前可见图表中的高点和低点标记(只有两个点),并且在这些标记之上我想显示显示点信息的固定工具提示。

当用户通过导航器导航时,这些点标记应该被重新计算并且工具提示应该跟随它们。

[这就是我想要完成的][1] 到目前为止,我已经能够计算高点和低点并突出显示图表中的相应标记,并且我还能够显示两个工具提示,但它们并没有准确定位带点标记。

![至此已经完成][2]

这是我的代码:

function customTooltip(point) {
  console.log(chart);
  var text = chart.renderer.text(
  'Max',
  point.plotX + chart.plotLeft + 10,
  point.plotY + chart.plotTop - 10
).attr({
  zIndex: 5
}).add();

var box = text.getBBox();
chart.renderer.rect(box.x - 5, box.y - 5, box.width + 10, box.height + 10, 5)
  .attr({
  fill: '#FFFFEF',
  stroke: 'gray',
  'stroke-width': 1,
  zIndex: 4
  })
    .add();

}

var labelArr = [], // keeps Tooltips for High and Low
  chart = $('#container').highcharts('StockChart', {
    chart: {
        type: 'line',
        width: 900
    },
    scrollbar: {
        enabled: false
    },
    navigator: {
        top: -1,
        height: 25,
        handles: {
            backgroundColor: 'transparent',
            borderColor: 'transparent'
        }
    },
    rangeSelector: {
        inputPosition: {
            align: 'left',
            x: 10,
            y: 30
        },
        buttons: [{
            type: 'year',
            count: 1,
            text: ''
        }],
        buttonTheme: { // styles for the buttons
            fill: 'none',
            stroke: 'none',
            'stroke-width': 0,
            states: {
                hover: {
                    fill: 'none'
                },
                select: {
                    fill: 'none'
                }
            }
        },
        inputDateFormat: '%m-%d-%Y',
        inputStyle: {
            fontSize: '14px',
            borderColor: '#FFF'
        },
        selected: 0
    },
    yAxis: {
        labels: {
            align: 'right',
            x: -5,
            formatter: function () {
                return "$" + this.value;
            }
        }
    },
    xAxis: {
        type: 'datetime',
        tickWidth: 0,
        labels: {
            y: 20
        },
        dateTimeLabelFormats: {
            month: '%B'
        },
        events: {
            setExtremes: function () {
                var pointMax, pointMin, labelLength = labelArr.length;


                // Flush out Old Tooltips for High and Low
                if (labelLength > 0) {
                    for (var i = 0; i < labelLength; i++) {
                        var popVal = labelArr.pop();
                        this.chart.container.firstChild.removeChild(popVal);
                    }
                }

                $.each(this.series[0].points, function (i, point) {

                    if (!pointMax && !pointMin) pointMax = pointMin = point;
                    // If marker is enabled for any point, disable it
                    if (typeof point.marker != 'undefined') point.marker.enabled =   false;
                    // Calculate Highest point 
                    if (pointMax.y < point.y) pointMax = point;
                    // Calculate Lowest point
                    if (pointMin.y > point.y) pointMin = point;
                });

                pointMax.update({
                    marker: {
                        enabled: true
                    }
                }, false, false);

                //customTooltip( pointMax );

                pointMin.update({
                    marker: {
                        enabled: true
                    }
                }, false, false);

                //customTooltip( pointMin );
            }
        }
    },
    tooltip: {
        crosshairs: false
        /*useHTML: true,
            borderRadius: 0,
            backgroundColor: '#000',
            shadow: false,
            borderWidth: 0,
            enabled: true,
            formatter: function(){
            /* Temp Disable Custom tool-Tip
                var arr = [];
                $.each(this.points, function(k, obj){
                    arr.push( "<span style='color:#FFF'>Low price w/o sales charge</span>" );
                    arr.push( "<br>" );
                    arr.push( "<span style='font-weight:bold;color:#FFF'>$" + obj.y + "</span>" );
                    arr.push( "<br>" );
                });
                return arr.join(' '); 
            } */
    },
    plotOptions: {
        area: {
            marker: {
                fillColor: '#f7941e',
                states: {
                    hover: {
                        enabled: false
                    }
                }
            }
        },
        series: {
            point: {
                events: {
                    update: function (event) {
                        event.target.series.chart.tooltip.refresh([event.target]);
                        var cloneToolTip = event.target.series.chart.tooltip.label.element.cloneNode(true);
                        event.target.series.chart.container.firstChild.appendChild(cloneToolTip);
                        labelArr.push(cloneToolTip);
                    }
                }
            }
        }
    },
    series: [{
        name: 'Quarterly Returns w/o sales charge',
        data: [

            [1149120000000, 62.17],
            [1149206400000, 61.66],
            [1369699200000, 441.44],
            [1369785600000, 444.95]
        ]
        //  pointWidth: 14,
    }]
}).highcharts();

});

你能指导我如何从这里开始吗?

4

0 回答 0