So I have extended the PlotChart that comes with Flex to have the ability to draw trend-lines. To do this, I have to get pixel positions. How can I convert (100px,100px) in pixels to a point on the graph, such as (0.7,1.0)?
You can draw on charts using the CartesianChartCanvas, here is the link to the LiveDoc: Drawing on Chart Controls
To answer your question more specifically, CartesianChartCanvas supports drawing by pixels.
You probably want to create a subclass of ChartElement, and add it to annotationElements for your chart. The docs for Flex 2 show an example: Livedocs
PlotSeries::dataToLocal(...) ended up working fine.
Related
I'm trying to create a custom container widget at the moment using QGroupBox as a base and drawing the new frame in the paint event, which is all working fine using drawPolyLine to create it, but I'd like to draw the frame with rounded corners. Has anyone come across a way to do it with drawPolyLine or would I need to rewrite my code to implement them?
When it comes to custom flexible shapes, QPainterPath is the most powerful class of them all. You could for example use QPainterPath::arcTo() in order to draw single rounded corners, though painting the full shape might require some math.
Another possibility is defining single shapes and merging them using intersected() or subtracted(), as already suggested by cbamber85 in the comments.
QPen has a "Cap Style" option of Qt::RoundCap which could result in rounded corners depending on pen width.
I want to know how Qt does a border when using QPainter's drawRect. The reason for this is I am trying to draw three rectangles next to each other, but I'm having trouble getting them to touch perfectly at all pen sizes.
QPainter's documentation for drawRect says:
A stroked rectangle has a size of [the input rectangle] plus the pen width.
So it goes like this:
I just wanted to add to the answer and address the question about truncation.
Truncation might be happening because you are using the QRect and not QRectF. QRectF gives you floating point precision. Similarly, you can use QPen::setWidthF(qreal width) to ensure your border is not getting truncated either.
I've created a line chart in flex and it works like expected. Now, I would like to add shading to the background for specific information. For example, this chart - http://research.stlouisfed.org/fred2/graph/?id=TOTALSL,TOTALNS, - shows a shaded background for recessions. How would I mimic this shading in a Flex linechart?
Thanks
You could draw it in the background of the chart using the drawing api.
edit:
I dont know of any code examples on the web, I've only done it in production code (aka I cant share it, sorry :( )
you will want to create a container and put it into the charts
<mx:backgroundElements>
You should pass into this container the min and max for the x-axis probably as separate properties and a dataprovider that describes when to show a highlighted section. You might have to compute the min and max based on the dataprovider you pass into the chart.
If you just want to show the highlighted area you will just use the drawing api and compute where to put on the x-axis based on your min, max, width of container, and data point (start and end values) from your dataprovider. It will look something like this in your updateDisplayList:
// code is not tested but a good start
var shadeStartX:Number = (max-min)/startPoint;
var shadeEndX:Number = (max-min)/endPoint;
var shadeWidth:Number = shadeEndX - shadeStartX;
...
this.graphics.drawRect(shadeStartX, 0, shadeWidth, unscaledHeight);
but if you want to have things like hover states and all that goodness I would suggest creating a display object that you pass the width in and adding that to the container at the computed x-axis to set it at.
Hi I feel that drawing something yourself is not the right way to go.
You should ideally use a PlotSeries inside the LineChart, and create a custom item renderer for each element in the series.
PlotSeries allows you to give your own custom image/object to draw at a specific date/point in the chart.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/series/PlotSeries.html
http://livedocs.adobe.com/flex/3/html/help.html?content=charts_types_10.html
All the examples show the plotSeries with smaller objects but you can create an object which covers the chart vertically and has a constant width.
I am using the standard Flex 3 BubbleChart component and I would like to customize a couple of the grid lines separately from the rest.
I would like to highlight a gridline in the X-direction as well as in the Y-direction to show a quadrant.
Is there any way to customize the look and feel of a subset of gridlines within a Flex chart (i.e. bubble chart)?
Any ideas or suggestions would be appreciated.
Thanks!
Check out this two nice articles:
Using chart grid lines
Drawing on chart controls
I have a Flex3 LineChart component using an CircleItemRenderer and the datapoints are being cut off because they are too close to the edge. Here's what it looks like:
http://img29.imageshack.us/img29/3850/chartx.png
As you can see, the circles on the left and right sides are being cut off.
How can I make the LineSeries area, plus the horizontal labels, narrower so it fits in the chart area?
Thanks!
I had the same issue and was able to resolve it by setting the clipContent attribute in the chart tag to false. I found this solution on Amy's Flex Diary.
You might want to set the maximum and minimum values in your LinearAxis in the horizontalAxis object. Check the API for more information: http://livedocs.adobe.com/flex/3/langref/mx/charts/LinearAxis.html
The Line Chart determines automatically these values to fill all the elements in the screen. You might want to change these values so the graph has some space at the sides.
You can set the padding property on the horizontalAxis and verticalAxis child objects as well...
Adjust the mask on the chart component.
I got this to work by changing the type from LineChart to ColumnChart. I still had all of the same axis definitions including Line Series. The results are the same Line graph, but more centered on the graph instead of touching the edges. None of the other padding or gutters were what I was looking for.
I got d solution.
create creationComplete event in LineChart
edit horizontalAxis's padding you want
e.target.horizontalAxis.padding = 0.2;