我在 Adobe Flex 折线图中有一个图表,其中 DateTime 轴作为我的水平线,而我的垂直线有一个线性轴。我想使用笛卡尔数据画布作为背景元素并绘制自定义背景图形集,主要是矩形。当我有多个数据点时,图形工作得很好,因为它们应该跨越整个图表的宽度。
但是,当我只有一个数据点时,我似乎无法绘制矩形。因为我希望我的矩形跨越图表的整个宽度,所以我想我可以从我的轴上获取 x 坐标,但这不起作用。
var canvasWidth:Number = chtCanvas.width;
var canvasHeight:Number = chtCanvas.height;
var minPt:Array;
var maxPt:Array;
var minPtDate:Date;
var maxPtDate:Date;
var minPtComplete:Point;
var maxPtComplete:Point;
// This works fine when there is more than 1 data point
minPt = chtCanvas.localToData(new Point(0, 0));
maxPt = chtCanvas.localToData(new Point(canvasWidth,canvasHeight));
//This does return a date object, but wont draw below
minPtDate = axisDate.minimum;
maxPtDate = axisDate.maximum;
//This returns NaN for the x
minPtComplete = chtCanvas.dataToLocal(minPtDate, axisSalary.minimum);
maxPtComplete = chtCanvas.dataToLocal(maxPtDate, axisSalary.maximum);
// Also tried this. Also returns NaN for the x value
//minPtComplete = chtCanvas.dataToLocal(axisDate.minimum, axisSalary.minumum);
//maxPtComplete = chtCanvas.dataToLocal(axisDate.maximum, axisSalary.maximum);
我的实际绘图方法如下:
// Tried this, works with points >2, does not draw with single data point
chtCanvas.drawRect(minPt[0], detail[i].MaxValue, maxPt[0], detail[i].MinValue);
//tried this, no effect with single point
//chtCanvas.drawRect(minPtDate, detail[i].MaxValue, maxPtDate, detail[i].MinValue);
// Tried this, no effect with single point
//chtCanvas.drawRect(minPtDate, minPt[1], maxPtDate, detail[i].MinValue);
// Tried this also
//chtCanvas.drawRect(minPtComplete.x, detail[i].MaxValue, maxPtComplete.x, detail[i].MinValue);
在此示例中,detail 是工资值的数组集合,Im 使用数组中的数据值来确定矩形的垂直边界。
我需要在图表的整个宽度上绘制矩形(即使只有一个数据点)。谢谢