Flex 4 中的 Adob​​e Flex 图表:带有类别轴的笛卡尔数据画布?

发布于 2024-10-10 15:07:00 字数 2060 浏览 4 评论 0原文

我正在最终确定一个新图表,该图表使用类别轴作为水平轴,使用线性轴作为垂直轴。点被正确绘制,我有一个笛卡尔数据画布作为背景元素,我希望使用画布来绘制一些填充整个图表的水平矩形“带”(但不是标准的网格线带)。我需要在运行时根据数据并独立于刻度线轴绘制完整(和动态)矩形。

我已经验证我的笛卡尔数据画布已作为子元素添加,但是,所有使用绘图 API 实际绘图的尝试均未成功。我在另一个网站上找到了一篇文章,并广泛阅读并重新阅读了 asdocs,试图找出我缺少的内容(请不要回复“用一条线连接两列”帖子的链接)。

作为测试,我尝试让笛卡尔数据画布仅绘制一个基本矩形,但是我在屏幕上没有看到任何内容。这是那个小练习的代码:

protected function drawChartCanvas():void
{

  chtCanvas.clear(); 
  chtCanvas.beginFill(0x000000);

  var canvasWidth:Number = chtCanvas.width;
  var canvasHeight:Number = chtCanvas.height;

  var minPt:Array = chtCanvas.localToData(new Point(0, 0)); //
  var maxPt:Array = chtCanvas.localToData(new Point(canvasWidth,canvasHeight));


  // Tried this
  chtCanvas.drawRect(minPt[0]-1, maxPt[1], maxPt[0]-1, minPt[1]);

  // Tried using data coordinates
  //chtCanvas.drawRect(0, someChartData, chart.width, 0);

  // Tried something random like this
  // chtCanvas.drawRect(0,10000, 10000, 0);

  chtCanvas.endFill(); 
}

但我在屏幕上没有看到任何内容。我想知道在使用类别轴时,我与笛卡尔数据画布一起使用的坐标是否可以工作/转换?我的绘图图表轴和背景元素属性:

<mx:backgroundElements>
 <mx:CartesianDataCanvas id="chtCanvas" includeInRanges="true" includeInLayout="true" visible="true"/>
 <mx:GridLines gridDirection="horizontal"/>
</mx:backgroundElements>


<mx:verticalAxis>
 <mx:LinearAxis id="axisSalary" baseAtZero="true" autoAdjust="true" title="Salary"/>
</mx:verticalAxis>
<mx:horizontalAxis>
 <mx:CategoryAxis id="axisDate" categoryField="Date" title="Date" dataFunction="formatChartDates"/>
</mx:horizontalAxis>

我认为笛卡尔数据画布能够将垂直轴的点(此处为工资值)作为一个点,然后传递图表宽度来完成我的“条带”,但我无法在画布上绘制任何内容。我认为由于画布使用数据点而不是屏幕坐标,我仍然应该能够使用我的薪水来确定背景元素的高度,但仍然使用图表宽度来确保矩形一直穿过屏幕。任何帮助将不胜感激。

更新:附加信息

所以我想我发现了问题所在,它与数据坐标有关。我能够绘制矩形。最初,我想使用带有折线系列的绘图图表,以便将我的值布置在图表的中心,而不是从原点开始。我将其修改为带有线系列的折线图,并使用笛卡尔数据画布来渲染我的条带,但现在的问题是并不总是有多个数据值拉伸图表的整个宽度。

现在的问题是,当给定点没有实际数据值时,如何在数据坐标中获取图表的原点?例如,使用带有线系列的绘图图将所有数据值,但为了绘图,我需要弄清楚当没有数据值与之关联时如何表示图形原点的 x 坐标。

谢谢!

I'm finalizing a new chart that uses a Category Axis as my horizontal, and a Linear Axis as my vertical. Points are being plotted correctly and I have a Cartesian Data Canvas as a background element and I want the Canvas to be used to draw some horizontal rectangular "bands" that fill the entire chart (but not the standard GridLines banding). I need to draw full (and dynamic) rectangles at runtime based upon the data and independent of the tick mark axis.

I have verified that my Cartesian Data Canvas is being added as a child element, however, all attempts to actually draw on this using the drawing API have been unsuccessful. I found a post on another site and have read and re-read the asdocs extensively trying to figure out what I'm missing (please dont respond with links to the "connecting two columns with a line" post).

As a test, I tried just getting the Cartesian Data Canvas to draw just a basic rectangle, however I'm not getting anything on screen. This is the code for that little exercise:

protected function drawChartCanvas():void
{

  chtCanvas.clear(); 
  chtCanvas.beginFill(0x000000);

  var canvasWidth:Number = chtCanvas.width;
  var canvasHeight:Number = chtCanvas.height;

  var minPt:Array = chtCanvas.localToData(new Point(0, 0)); //
  var maxPt:Array = chtCanvas.localToData(new Point(canvasWidth,canvasHeight));


  // Tried this
  chtCanvas.drawRect(minPt[0]-1, maxPt[1], maxPt[0]-1, minPt[1]);

  // Tried using data coordinates
  //chtCanvas.drawRect(0, someChartData, chart.width, 0);

  // Tried something random like this
  // chtCanvas.drawRect(0,10000, 10000, 0);

  chtCanvas.endFill(); 
}

But Im not seeing anything on screen. I'm wondering if the coordinates I'm using with the Cartesian Data Canvas work/translate when using a Category Axis? My Plot Chart axis and background elements properties:

<mx:backgroundElements>
 <mx:CartesianDataCanvas id="chtCanvas" includeInRanges="true" includeInLayout="true" visible="true"/>
 <mx:GridLines gridDirection="horizontal"/>
</mx:backgroundElements>


<mx:verticalAxis>
 <mx:LinearAxis id="axisSalary" baseAtZero="true" autoAdjust="true" title="Salary"/>
</mx:verticalAxis>
<mx:horizontalAxis>
 <mx:CategoryAxis id="axisDate" categoryField="Date" title="Date" dataFunction="formatChartDates"/>
</mx:horizontalAxis>

I would think the Cartesian Data Canvas would be able to take the point of the vertical axis (here salary value) as a point and then pass the chart width to complete my "banding," but I can't get ANYTHING to draw on the canvas. I would think since the canvas uses data points and not screen coordinates that I should still be able to use my salary to determine the height of the background element, but still use the chart width to make sure the rectangle goes all the way cross screen. Any help would be greatly appreciated.

UPDATE: Additional information

So I think I discovered what the issue is here and it has to do with data coordinates. I was able to get the rectangle to draw. Originally, I wanted to use a Plot Chart with a Line Series so that my values would be laid out in the center of the chart rather than starting at the origin. I modified this to a Line Chart with a Line Series and got my Cartesian Data Canvas to render my bandings, but now the problem is that there arent always multiple data values that stretch the entire width of the chart.

So this question is now how do I get the origin of the chart in data coordinates when there is no actual data value at a given point? For example, using a Plot Chart with a Line Series centers all of the data values, but in order to draw, I need to figure out how to represent the x-coordinate of the graph origin when there is no data value associates with it.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

征棹 2024-10-17 15:07:00

所以我最终不得不重新思考这个问题的实际问题,并最终找到了解决方法。这篇文章 Flex 图表:您可以使用笛卡尔数据画布的 IAxis 的最小/最大点来绘制图表的整个宽度吗? 回答了这个问题。

So I ended up having to re-think the actual problem for this question and ended up figuring a way around it. this post Flex Charts: Can you use a minimum/maximum point from an IAxis for Cartesian Data Canvas to draw the entire width of the chart? answers this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文