I want to use an AreaSeries to display the content of an arrayCollection (the cell values are displayed on the y axis).
The Array collection is dataManager.tagViewTimelineModel.summedPopularity
<mx:AreaSeries id="timeArea" styleName="timeArea" name="A" dataProvider="dataManager.tagViewTimelineModel.summedPopularity" areaStroke="{new Stroke(0x0033CC, 2)}" areaFill="{new SolidColor(0x0033CC, 0.5)}" />
But it doesn't work, the graph is empty....
Am I doing something wrong ?
This is the full code for completeness.
mx:CartesianChart id="AllChart" dataProvider="{dataManager.tagViewTimelineModel.tags}" width="100%" height="100">
<mx:horizontalAxis><mx:CategoryAxis id="horiz1" dataProvider="['1','2','3','4','5','6','7','8','9','10','11','23','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']"/></mx:horizontalAxis>
<mx:horizontalAxisRenderers><mx:AxisRenderer axis="{horiz1}"/></mx:horizontalAxisRenderers>
<mx:verticalAxis><mx:LinearAxis id="vert1" /></mx:verticalAxis>
<mx:verticalAxisRenderers><mx:AxisRenderer axis="{vert1}"/></mx:verticalAxisRenderers>
<mx:series>
<mx:AreaSeries id="timeArea" styleName="timeArea" name="A" dataProvider="dataManager.tagViewTimelineModel.summedPopularity" areaStroke="{new Stroke(0x0033CC, 2)}" areaFill="{new SolidColor(0x0033CC, 0.5)}" />
</mx:series>
</mx:CartesianChart>
thanks
I think you might need { } around your dataProvider for your AreaSeries declaration. You have it on top for your chart but you probably overrode it below.
Related
thank you for your time.
I have 2 labels with numerical values i would like to add together.
<s:Label id="cost_1" x="261" y="138" text="150" />
<s:Label id="cost_2" x="280" y="138" text="220"/>
<s:Label id="totals" x="291" y="138" text=""/>
I need to the third label (id="totals") to visually display the sum of first two labels. (150+220=totals.text)
Thank you!
Lots of ways to do this; but given your code the simplest way would be something like this:
<s:Label id="totals" x="291" y="138" text="{int(cost_1.text) + int(cost_2.text)}" />
Although the labels may display numeric values; they are actually string values; so this code casts them to ints. From there, it's just a simple arithmetic operation.
I am using a DividedBox in Flex which contains only a datagrid at first. When I click on an Item on the Datagrid, a second element with a width of 0% (Spark Group) is added to the divided box to display an image.
The thing is, when the second element is added to the DividedBox, the image is partially displayed outside the DividedBox, and I don't want to have this behavior.
Here is the interesting code :
<mx:DividedBox direction="horizontal" id="divider" borderColor="red" borderStyle="solid" borderVisible="true" right="10" left="10" top="10" bottom="10">
<s:Group width="100%" height="100%">
<!--datagrid-->
</s:Group>
</mx:DividedBox>
And here is the piece of code that adds the second child of the dividedBox (simplified code) :
private var _pdf_preview:Group = new Group();
[Bindable]
[Embed(source="assets/image/llama.jpg")]
private var imgClass:Class;
protected function itemOnClickHandler(event:MouseEvent):void
{
_pdf_preview = new Group();
var img:Image = new Image();
img.source = imgClass;
_pdf_preview.addElement(img);
_pdf_preview.percentWidth = 0;
divider.addElement(_pdf_preview);
}
And here is a screen of the problem (Btw, don't notice my skills on Gimp :) ). As a new user I can't bind images to my post : screen showing my problem the red border show the limits of the dividedBox
Thank you.
I hope there are not too much fault, english is not my native language. Sorry for any english mistakes.
PS : I couldn't add the "DividedBox" tags because it was not existing before, and I'm a "new user" so I can't create new tags.
You can use the clipContent property to cut off the image at the edge of the DividedBox:
<mx:DividedBox clipContent="true" />
When using Spark containers, clipAndEnableScrolling is the property you need to achieve the same goal.
I would also like to note that you usually don't require to dynamically add components through ActionScript. You can use 'states' instead. For example:
<s:states>
<s:State name="normal" />
<s:State name="image" />
</s:states>
<mx:DividedBox clipContent="true">
<s:DataGrid />
<s:Image includeIn="image" />
</mx:DividedBox>
Now all you need to do to show the Image, is set the currentState to image.
I'm attempting to rotate the category labels on my flex chart, but the labelRotation property seems to not work. Based on examples and the livedocs, I can't seem to figure out what I'm doing wrong.
<mx:BarChart id="barchartX" left="40" right="40" bottom="40" paddingBottom="40"
dataProvider="{chartDataObj.series}" showDataTips="false"
itemClick="editItem_clickHandler(event)" includeIn="BAR" visible="true">
<mx:verticalAxis>
<mx:CategoryAxis id="vaxis" categoryField="title"
title="click here to rename this axis" />
</mx:verticalAxis>
<mx:verticalAxisRenderers>
<mx:AxisRenderer axis="{vaxis}" labelRotation="45"
click="axis_clickHandler(event)"/>
</mx:verticalAxisRenderers>
<mx:horizontalAxis>
<mx:LinearAxis id="haxis" title="click here to rename this axis" />
</mx:horizontalAxis>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis="{haxis}" labelRotation="0"
click="axis_clickHandler(event)"/>
</mx:horizontalAxisRenderers>
<mx:series>
<mx:BarSeries labelPosition="none" yField="title" xField="value"
fills="{chartDataObj.colors}"/>
</mx:series>
I am including my answer to a similar question, https://stackoverflow.com/a/9129992/892191
The key to making the labelRotation work is embedding of fonts.
There is a good article on Flex 4.6 here
A simple code example would be to add a style to the mxml file,
<fx:Style>
#namespace mx "library://ns.adobe.com/flex/mx";
#font-face{
src: local("Arial");
fontFamily: Arial;
embedAsCFF: false;
}
mx|ColumnChart {
fontFamily: Arial;
fontSize: 10;
}
</fx:Style>
Okay, after searching through the actual code of the AxisRenderer I came up with this:
<fx:Script>
[Embed(source='../assets/verdana.ttf',
fontName='verdanaFontMX',
mimeType='application/x-font',
embedAsCFF='false')]
private var font2:Class;
</fx:Script>
<mx:verticalAxisRenderers>
<mx:AxisRenderer axis="{vaxis}" labelRotation="90"
labelClass="mx.controls.Label"
fontFamily="verdanaFontMX" canStagger="false"
click="axis_clickHandler(event)"/>
</mx:verticalAxisRenderers>
When using a CategoryAxis for an MX chart in a mobile project, the category labels are rendered as Spark Labels, but the rest of the axis labels are rendered as MX Labels. The label rotation works, but a warning is thrown and the category is rendered using the device font instead. To fix this, use the MX Label class instead (labelClass="mx.controls.Label"). I know it doesn't render quickly as the Spark label, but it will render in the font you want.
Next, if you have a category label that's very long, somehow there is division by zero and the whole thing crashes. To avoid this, set canStagger="false" or canDropLabels="true". This avoids whatever measurement errors were happening. However, if the fontSize is set, and the label ends up being too large, the automatic sizing crashes again. So, I guess the easiest solution would be to keep the category labels short.
There is also the possibility of truncating the text as found here: http://help.adobe.com/en_US/flex/using/WS02f7d8d4857b1677355f601a126b41ed60e-8000.html
or, using a custom labelRenderer, but this can get very involved and can have diminishing returns on the amount of work versus the benefit to the look.
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
the LineSeries is not dynamically added to my CartesianChart...
What's wrong in this code:
...
private function chartComplete():void {
var ls:LineSeries = new LineSeries();
ls.styleName = 'timeline';
ls.dataProvider = "{dataManager.tagViewTimelineModel.tags.getItemAt(0).yearPopularity}";
ls.yField = 'popularity';
//ls.s = "{new Stroke(0xCC33CC, 2)}";
AllChart.series[0] = ls;
}
...
<mx:CartesianChart id="AllChart" width="100%" height="100" creationComplete="chartComplete();">
<mx:horizontalAxis><mx:CategoryAxis id="horiz1" dataProvider="['1','2','3','4','5','6','7','8','9','10','11','23','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']"/></mx:horizontalAxis>
<mx:horizontalAxisRenderers><mx:AxisRenderer axis="{horiz1}"/></mx:horizontalAxisRenderers>
<mx:verticalAxis><mx:LinearAxis id="vert1" /></mx:verticalAxis>
<mx:verticalAxisRenderers><mx:AxisRenderer axis="{vert1}"/></mx:verticalAxisRenderers>
<mx:series>
<mx:AreaSeries id="timeArea" styleName="timeArea" name="A" dataProvider="{dataManager.tagViewTimelineModel.tags.getItemAt(2).yearPopularity}" areaStroke="{new Stroke(0x0033CC, 2)}" areaFill="{new SolidColor(0x0033CC, 0.5)}" />
</mx:series>
</mx:CartesianChart>
I can only see the TimeLine if I added it with MXML:
<mx:LineSeries styleName="timeLine" dataProvider="{dataManager.tagViewTimelineModel.tags.getItemAt(0).yearPopularity}" yField="popularity" stroke="{new Stroke(0xCC33CC, 2)}" />
But I need to update the view, and add N lines so I cannot do it with MXML.
thanks
You can set the series property for the chart. Just add a new Series object to that array.