Flex: Create custom stroke on LineSeries?

Posted by John Isaacks on Stack Overflow See other posts from Stack Overflow or by John Isaacks
Published on 2010-01-15T21:38:48Z Indexed on 2010/03/26 14:03 UTC
Read the original article Hit count: 457

Filed under:
|
|
|
|

You can easily set a stroke on a line series like this:

<mx:LineSeries yField="apple">
    <mx:lineStroke>
        <mx:Stroke 
                    color="0x6699FF" 
                    weight="4" 
                    alpha=".8"
        />
    </mx:lineStroke>
</mx:LineSeries>

This will set alpha for the entire stroke to .8

But I want to be able to set a different alpha on the stoke for each plot based on something in the dataProvider.

For example the yField in the lineSeries is "Apple" which is how it knows where to plot for the lineSeries. I want to be able to add something like alphaField which tells it what to set the stroke alpha for each plot.

so if my dataProvider was:

<result month="Jan-04">
    <apple>81768</apple>
    <alpha>1</alpha>
</result>
<result month="Feb-04">
    <apple>51156</apple>
    <alpha>1</alpha>
</result>
<result month="Mar-04">
    <apple>51156</apple>
    <alpha>.5</alpha>
</result>

And I set alphaField="alpha" then I would have a solid stroke from plot 0 to plot 1 and then a 50% alpha stroke from plot 1 to plot 2.

How can I do this??? I am looking in the commitProperties() and updateDisplayList() methods of LineSeries and have no idea what would need to be added/changed to make this?

I am pretty sure, this class has to use Graphics.lineTo() to draw each plot, so basically it would need to "get" the current alphaField value somehow, and apply a Graphics.lineStyle() with the correct alpha before drawing each line.

Thanks!!


UPDATE

I have gotten much closer to my answer.

When I extend LineRenderer I override updateDisplayList() which calls GraphicsUtilities.drawPolyLine()

I extend GraphicsUtilities and override the method drawPolyLine() as this is where the line is actually drawn.

I can call lineStyle() in here and change the alpha of the line...

I still have 1 thing I cannot figure out, from within the drawPolyLine() method how can I access that data that dictates what the alpha should be?

Thanks!!!!

© Stack Overflow or respective owner

Related posts about flex

Related posts about stroke