经过一番摆弄后,我在 Highcharts 中破解了自己的方法以获得所需的效果。
这是我的小提琴:http://jsbin.com/upUFIbO/1/。
我所做的是,为load 和redraw 事件添加以下回调:
/**
* Helper that extends area and lines to the left and right plot edges.
*
* Has to be invoked with .call(), giving Highchart as the this reference
* and Highchart event as the second parameter.
*
* @return void
*/
var edgeExtend = function(e)
{
for (var l = this.series.length, i = 0; i< l; i++)
{
// Get current series.
var series = this.series[i];
// Get inner-chart box.
var box = this.plotBox;
// Take areas path.
var areaPath = series.areaPath;
// Add start point.
// Right after the first element (M).
areaPath.splice(1, 0, 0, areaPath[2], 'L');
// Add Last points upper area end.
// Remove penultimate point.
// Replace it with a new point reaching to the width of chart and growing to the height of last element.
// And add the bottom-right corner.
areaPath.splice(-6, 3, 'L', box.width, areaPath[areaPath.length - 7], 'L', box.width, box.height);
// Make the last points X be zero - that will result in bottom left corner.
areaPath[areaPath.length - 2] = 0;
// Replace value (redraw).
series.area.element.attributes.d.value = areaPath.join(' ');
var graphPath = series.graphPath;
// Add start point.
// Right after the first element (M).
graphPath.splice(1, 0, 0, graphPath[2], 'L');
// Add end point.
graphPath.push('L', box.width, graphPath[graphPath.length - 1]);
series.graph.element.attributes.d.value = graphPath.join(' ');
}
};
这可能不是最好的方法,但是,嘿,直接矢量路径操作不会出错。
如果有人对这个问题有更“用户友好”的解决方案,我很想看看。