Drawing a dashed line across the tops of Flex Column Chart - apache-flex

Please find the below code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
[Bindable]
public var testAC:Array = [
{date:"without", close:50},
{date:"with", close:45}
];
]]>
</mx:Script>
<mx:ColumnChart id="myChart" dataProvider="{testAC}">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="date"/>
</mx:horizontalAxis>
<mx:verticalAxis>
<mx:CategoryAxis categoryField="close"/>
</mx:verticalAxis>
<mx:series>
<mx:ColumnSeries dataProvider="{testAC}" xField="date" yField="close"/>
<mx:LineSeries dataProvider="{testAC}" xField="date" yField="close"/>
</mx:series>
</mx:ColumnChart>
</mx:Application>
This code is drawing a colum chart with two columns and drawing a line across the top of both columns. I have two requirements :
the line need to be dashed
as of now the line starts from top right corner of the first column to the same corner of the second column. How can i shift the line to the left, so that it starts from center of first column to center of second column.
Regards, PK

You can draw a line between two values on your Cartesian Chart with
<mx:Script><![CDATA[
private function connectTwoPoints(
month1:String, value1:Number,
month2:String, value2:Number):void
{
// Draw Line
canvas.clear();
canvas.lineStyle(4,
0xCCCCCC,
.75,
true,
LineScaleMode.NORMAL,
CapsStyle.ROUND,
JointStyle.MITER,
2);
canvas.moveTo(month1, value1);
canvas.lineTo(month2, value2);
}
]]></mx:Script>
<mx:annotationElements>
<mx:CartesianDataCanvas id="canvas" includeInRanges="true"/>
</mx:annotationElements>
The line that you draw will be an "Annotation Element" using the "Cartesian Data Canvas". Annotation Elements are drawn in the foreground. Perfect Example:
http://livedocs.adobe.com/flex/3/html/help.html?content=charts_eventsandeffects_13.html

For many of my charts with complex skinning I've been using Axiis. It's very Degrafa-like and would allow you to take a degrafa stroke and put it wherever you'd like on your 'dataCanvas'.
Here's an example that is pretty straight fwd:
http://axiis.org/examples/HClusterStackExample.html
'Tisn't the best answer in the land, but using axiis is so simple, and yet it allows for complex fills and strokes that aren't allowed via mxml with plain-ol' flex charting.
Best of luck,
Jeremy

after a long research i finally completed drawing dashed line chart. I used DashedGraphicUtilities provided by Adobe itself to draw the dashed line. I extender the LineSeries and used this DashedGraphicUtilities to draw the dashed line. That solved my first and mail problem. I will update this whenever i get the solution for the second.
And i got the solution for second problem also. The line chart was displaying perfectly as i needed, when i changed the graph type from ColumnChart to CartesianChart. I used column series and line series inside that and the line and columns were coming perfectly.
Regards,
Anoop

Related

Flex charts increase label size for category axis

I am using a column chart which has a horizontal axis for displaying dates.
Problem is when there are large data points then it shrinks the size of the label for the x-axis and i don't want this to happen.
I am displaying dates in batches but still the label don't occupy the available space. The size of the label shrinks and the text is hardly readable.
Any suggestion on how i could increase the label size irrespective of the number of ticks.
Here is a snippet of my code.
Thank You.
<mx:ColumnChart id = "areaChart"
height = "100%"
width = "100%"
seriesFilters="[]"
showDataTips="false"
type="overlaid"
columnWidthRatio="0.40"
mouseMove="showData(event)"
mouseSensitivity="600"
change="{callLater(showDefaultData)}">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField = "date"
id = "hax"
ticksBetweenLabels="true"
labelFunction="chartsLabel"/>
</mx:horizontalAxis>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer id="har"
axis="{hax}"
textAlign="left"
tickPlacement="none"
placement="bottom"
axisStroke="{Stroke}"/>
</mx:horizontalAxisRenderers>
Define a style for the AxisRenderer and use it in your definition:
Style:
<mx:Style>
.axisStyle {
fontSize:10;
color:blue;
}
</mx:Style>
Usage:
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis="{axisName}" styleName="axisStyle"/>
</mx:horizontalAxisRenderers>
<mx:horizontalAxis>
<mx:CategoryAxis id="axisName" dataProvider="{dataProvider}"
categoryField="someCategory"/>
</mx:horizontalAxis>
You shall set
canDropLabels="true|false"
canStagger="true|false"
styles for chart's axisrenderer: it shall know what to do if there are too much text.
You can also set scaleX and scaleY properties for axisrenderer if you want to force removal of scaling. But you'll not need it unless you do something tricky.
You can also set gutters for chart and axisrenderer to provide extra space for drawing labels, but again, normally you will not need it.
Unfortunately, teh CategoryAxis doesn't seem to have a renderer and therefore canDropLabels and canStagger cannot be set for it.

Is it possible to stop my labels disappearing on my flex pie chart between segment selections whilst interpolating?

I have a flex pie chart:
<mx:PieChart alpha="0.9" fontSize="{QPieSeries_font}" width="100%" top="20" height="320" id="QPieChart"
dataProvider="{dataObj}" horizontalCenter="0" color="0xFFFFFF" fontFamily="MyriadWebPro"
showDataTips="true" dataTipFunction="QdataTipFunction"
dataTipItemsSet="true" itemClick="QPieChart_itemClickHandler(event)">
<mx:series>
<mx:PieSeries id="QPieSeries" labelField="Answer" field="Value" labelPosition="callout"
showDataEffect="QSeriesInterpolate" alpha="1"
reserveExplodeRadius="0.05"/>
</mx:series>
</mx:PieChart>
where the QSeriesInterpolate is a simple interpolation given in the declaration:
<fx:Declarations>
<mx:SeriesInterpolate id="QSeriesInterpolate" duration="500" />
</fx:Declarations>
and the item click event looks like:
protected function QPieChart_itemClickHandler(event:ChartItemEvent):void
{
var ExAr:Array = [];
ExAr[event.hitData.chartItem.index] = 0.05;
QPieSeries.perWedgeExplodeRadius = ExAr;
}
Basically, what annoys me is that when I click a segment to activate the interpolated event, the datatips disappear for it's duration. Whilst this is only half a second, it still detracts from user experience. Is there anything I can do to avoid it??
ALSO! Another thing: Is it obvious to anyone why my dataTipFunction doesnt work? It looks as follows:
public function QdataTipFunction(hitData:HitData):String
{
var a:String = "abc"
return a;
}
Yes it's simple but I was just trying to persuade it to work... to no avail. I think it might be some sort of font issue?
Thanks!
Josh
You might consider looking into Axiis. It is a flex data visualization framework, and has some awesome example charts. The main deal though is you have full control over EVERTHING! Probably overkill for what you are doing, but it really is awesome.
http://www.axiis.org/examples.html

sequencing through several images

I'm using flex and have a few images that I need to sequence through. I may add some text under each image. What I'm trying to do is automatically sequence through these images such that a black fading effect appears briefly between each image and the next - sure you've seen that sort of thing before.
My questions are this:
should these images be considered as states of a component or what? I was going to go that way, but corrections are welcome
how to get that black fading effect between the images and the next. Any clues please
Update: found an example of it. This example has more elements, but the idea is the same, an images fades and another images loads.
http://www.lifeblue.com/flash/lb_banner.swf
You can try using a ViewStack and a Timer to iterate through its children. Just add a fade in/fade out effect on them and you'll get what you're looking for.
Something like that :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="black" creationComplete="creationCompleteHandler">
<mx:Script>
<![CDATA[
private var timer:Timer;
private function creationCompleteHandler():void
{
timer = new Timer( 2000 );
timer.addEventListener( TimerEvent.TIMER, timerHandler );
timer.start();
}
private function timerHandler( e:TimerEvent ):void
{
if( vs.selectedIndex == vs.getChildren().length - 1 )
vs.selectedIndex = 0;
else
vs.selectedIndex++;
}
]]>
</mx:Script>
<mx:Fade id="fadeIn" alphaFrom="0" alphaTo="1" duration="500" effectEnd="timer.start();"/>
<mx:Fade id="fadeOut" alphaFrom="1" alphaTo="0" duration="500" effectEnd="timer.stop();"/>
<mx:ViewStack id="vs">
<mx:Canvas showEffect="fadeIn" hideEffect="fadeOut">
<mx:Image source="picture1.jpg"/>
</mx:Canvas>
<mx:Canvas showEffect="fadeIn" hideEffect="fadeOut">
<mx:Image source="picture2.jpg"/>
</mx:Canvas>
<mx:Canvas showEffect="fadeIn" hideEffect="fadeOut">
<mx:Image source="picture3.jpg"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Application>
Note that this code isn't the most optimized one. The best would be to create a custom component with a black background and 2 Image components.
Set the alpha property of both of
them to 0
Load a picture in the first one, then
play your fade in effect
Begin to load the following picture
in the second Image component
Fade out the first one, fade in the
second, and load the following
picture in the first Image, etc.
This way you only got one Container (instead of one per picture plus the ViewStack) and 2 Images.
It will also be easier to clean them from memory if you need to.

How to set the border color of a CircleItemRenderer

I have a linechart and dots showing the places where a datatip pops up. I can change the line to any color I want and I can set the inside color of the dot. But the border color still stays orange (from the default color). Someone knows how I can set this property easy?
this is the code:
<mx:LineSeries id="dayEnergieLineSeries"
yField="number"
showDataEffect="{slideIn}" hideDataEffect="{slideOut}">
<mx:lineStroke>
<mx:Stroke color="#d3ce01" />
</mx:lineStroke>
<mx:itemRenderer>
<mx:Component>
<mx:CircleItemRenderer />
</mx:Component>
</mx:itemRenderer>
</mx:LineSeries>
From the docs:
It renders its area on screen using the fill and stroke styles of its associated series.
So you'll have to assign a stroke to the dayEnergieLineSeries series.
[Bindable] private var _stroke:Stroke = new Stroke(...);
<mx:LineSeries id="dayEnergieLineSeries" stroke="{_stroke}"/>
or if you don't need the data binding, just set it as a style.
PS: There is a good chart explorer available here: http://demo.quietlyscheming.com/ChartSampler/app.html

flex chart grid lines dotted

Using the LineChart component of Flex: How do I make the horizontal grid lines (background within the chart) dotted? With the mx:Stroke within the mx:horizontalStroke, I can only set properties like weight, color and alpha. I'd like to make the line dotted...
This is what I have now:
<mx:LineChart id="linechartDays" width="100%" height="100%" dataProvider="{dayData}" showDataTips="true">
<mx:backgroundElements>
<mx:GridLines horizontalChangeCount="1" direction="horizontal">
<mx:horizontalStroke>
<mx:Stroke weight="1" color="0xcccccc"/>
</mx:horizontalStroke>
</mx:GridLines>
</mx:backgroundElements>
</mx:LineChart>
use DottedLine.as class file for the following path http://www.warmforestflash.com/blog/2009/01/as3-dotted-line-class/
and use this function to main.mxml file
private function drawline(argStr:String):void
{
var s:Shape= new DottedLine(1.5,Chart.height,0xff0000,1,5,4);
uil=new UIComponent();
uil.addChild(s);
uil.height= Chart.height;
canChart.addDataChild(uil,argStr,null,null,null,argStr,50);
}

Resources