How write inline if condition inside pie series in pie chart? - actionscript-3

Im trying to change colour according to Label value in pie series.Im trying to write a inline if condition inside pie series like this
<mx:PieSeries
id="s1"
field="Value"
nameField="Label"
color="{'Value'='Other'?0xd8d8d8:colorArr}">
</mx:PieSeries>
this is my data source to pie chart.data source length is not fixed. it will change dynamically.so i cant passs colour array by hard coding particular colour to other label field.Thats why im tying to write if condition inside pie series.
This is a sample data source
var expenses:ArrayCollection = new ArrayCollection([
{Label:"Taxes", Value:1001},
{Label:"Rent", Value:1005},
{Label:"Bills", Value:1008},
{Label:"Car", Value:1009},
{Label:"Gas", Value:1020},
{Label:"Food", Value:1015},
{Label:"Other", Value:1080}
]);
This is my colour array
private var colorArr:Array = new Array(
"0x1ad6ef",
"0xee816d",
"0xfdd849",
"0xff9e5d",
"0xa4c286",
"0xca6353",
"0xd69b99",
"0xe67976",
"0xfe9ae3",
"0x6965b8",
"0xfebf9a",
"0xfeb548"
);
Is this possible guys ?

Can you try this:
color="{'Value'=='Other'?0xd8d8d8:0xffffff}"

Related

Add in a where clause

I have this foreach function, but I need to add a where clause.
I have added a checkboxlist in Umbraco called "show"
Values if this is
"EN"
"SP"
"US"
...
Let us say I have checked EN and SP.
I only want a slide to be visible if the slide is Visible as now, and if the field show are "EN" is checked and true. How can i add this in my code?
#foreach (var Slider in Umbraco.ContentSingleAtXPath("//HomePage/SliderArea").Children.Where("Visible").OrderBy("CreateDate
desc").Take(4))
The code you have is using Dynamics and therefore you're restricted to using the pseudo-Linq extensions like .Where("Visible"). You'll find it much easier to manipulate the list of items if you use the Typed objects instead.
Change this:
// Returns IPublishedContent as dynamic
Umbraco.ContentSingleAtXPath("//HomePage/SliderArea")
to this:
// Returns fully typed IPublishedContent
Umbraco.TypedContentSingleAtXPath("//HomePage/SliderArea")
Then you'll be able to use the full power of Linq to do this:
var area = Umbraco.TypedContentSingleAtXPath("//HomePage/SliderArea");
// returns a filtered IEnumerable<IPublishedContent>
var sliders = area.Children.Where(c => c.IsVisible() && c.GetPropertyValue<string>("show") == "EN");
#foreach (IPublishedContent slider in sliders.OrderByDescending(c => c.CreateDate).Take(4))
{
// You can get the dynamic equivalent of the IPublishedContent like this if you wish:
dynamic dSlider = slider.AsDynamic();
// ...
}

Masked images not displaying in AS3

I am trying to mask an image on another so that I only view the specific portion of the unmasked image through the masked one. My problem is that I cannot see anything on the screen.. no Image, no effect at all
cardMask = new Image(Root.assets.getTexture("card_mask"));
cardMask.y = Constants.STAGE_HEIGHT*0.40;
cardMask.x = Constants.STAGE_WIDTH *0.48;
trace("it's add mask");
cardLight = new Image(Root.assets.getTexture("card_light_mask"));
cardLight.y = Constants.STAGE_HEIGHT*0.46;
cardLight.x = Constants.STAGE_WIDTH *0.48;
cardLight.mask=cardMask;
maskedDisplayObject = new PixelMaskDisplayObject(-1,false);
maskedDisplayObject.addChild(cardLight);
maskedDisplayObject.x=cardLight.x;
maskedDisplayObject.y=cardLight.y;
maskedDisplayObject.mask=cardMask;
maskedDisplayObject.blendMode = BlendMode.SCREEN;
addChild(maskedDisplayObject);
First, for masking an object the mask object should also be added to the display list. Your code does not add cardMask to display list anywhere. Second, if your maskedDisplayObject should be visible at all times, the mask should be assigned not to it, but to some other object which displayed part you desire to control. And third, it is also possible that this.stage is null, therefore the entire tree (this -> maskedDisplayObject -> cardLight) is plain not rendered. You need to check all three of these conditions to get something displayed.
Also, if you desire cardLight as an object to move independently of maskedDisplayObject, you should add it to this instead, and check that it's displayed on top of maskedDisplayObject (call addChild(cardLight) after addChild(maskedDisplayObject)).
This all totals to this code:
trace("Stage is null:", (this.stage==null)); // if this outputs true, you're out of display
cardMask = new Image(Root.assets.getTexture("card_mask"));
cardMask.y = Constants.STAGE_HEIGHT*0.40;
cardMask.x = Constants.STAGE_WIDTH *0.48; // mask creation unaltered
trace("it's add mask");
cardLight = new Image(Root.assets.getTexture("card_light_mask"));
cardLight.y = Constants.STAGE_HEIGHT*0.46;
cardLight.x = Constants.STAGE_WIDTH *0.48;
cardLight.mask=cardMask; // this is right
maskedDisplayObject = new PixelMaskDisplayObject(-1,false);
// maskedDisplayObject.addChild(cardLight); this is moved to main part of display list
maskedDisplayObject.x=cardLight.x;
maskedDisplayObject.y=cardLight.y;
// maskedDisplayObject.mask=cardMask; NO masking of this, you're only masking cardLight
cardLight.blendMode = BlendMode.SCREEN; // display mode is also changed
addChild(maskedDisplayObject);
addChild(cardLight);

Item renderer for dynamic DataGrid

I have a problem with dynamic item renderer for data grids elements.
I'm initialiizng columns in my data grid dynamically, like this:
for each (var item in _collection)
{
var i:MyClass= item as MyClass;
var dgc:DataGridColumn = new DataGridColumn(i.Id.toString());
dgc.headerText = i.Name;
cols.push(dgc);
}
_myDataGrid.columns = cols;
To every cell I want to pass integer. When it has -1 value, cell should display specific text but when it's 0 or 1 it should contain checkbox.
Do you know how can I achieve that? I don't any ideas for now, despite I was thinking about this for quite long time. Can you help me with this?
Create itemRenderer with two states. One state with checkbox another with text

Flash Builder: PieChart issue

I am trying to show data in my pieChart. Everything works great if I have multiple fields in my dataprovide (ex: EmployeeA, EmployeeB..etc). The pie will be divided into pieces and have texts shown on each pieces.
However, if my dataprovider only has one field (ex: EmployeeA). The pieChart will show the whole pie with no texts on the pieChart. I was wondering if there are any ways to show the data text inside the pieChart. Thanks a lot.
Code:
<mx:PieChart id="piechart1" x="254" y="321" width="367" height="367"
dataProvider="{getHours.lastResult}">
<mx:series>
<mx:PieSeries id="pieSeries" labelFunction="pieFunction"
explodeRadius="0.05" field="EmployeeOverTime" labelPosition="inside"/>
</mx:series>
</mx:PieChart>
//EmployeeOverTime data will show on each pie pieces if I have multiple
//employees in the department but won't show if the department has only one employee.
It looks like it was a bug in the PieSeries code. I had to monkey patch the charting code in order to get this to work. Here's an fxp file that works.
http://dl.dropbox.com/u/20054635/forever/piechart.fxp
The bug is that on line 3323 there's this code:
var rscale:Number = 1;
// find out how much we would have to scale to get to the next neighbor up
/* var RXScale:Number = Math.abs(ld.labelX - nextNeighbor.labelX)/(ld.labelWidth/2 + nextNeighbor.labelWidth/2);
Then on line 3338 it removes the label based on rscale (which is now zero because there was no nextNeighbor when there is only 1 item in the piechart)
if (rscale * Number(labelFormat.size) < insideLabelSizeLimit)
{
ld.prev.next = ld.next;
ld.next.prev = ld.prev;
removedLabels.push(ld);

I am trying to populate a DOJO pie chart from a json array created by a url

I am trying to populate a dojo pie chart from a json array created by a url.
the url returns an array that looks like this
{"pieItems":[["IPv4 TCP",475919493840],["IPv6 TCP",37443255432],["IPv4 UDP",34595392128],["IPv6 ICMP",14496],["IPv4 ICMP",46560],["IP Other",12385112]]}
I have attempted to redo the format of the array changing it to one that looks like this
{"IPv4 TCP":[475919493840],"IPv6 TCP":[37443255432],"IPv4 UDP":[34595392128],"IPv6 ICMP":[14496],"IPv4 ICMP":[46560],"IP Other":[12385112]} .
the code I used to change the format is:
var len = responseObj.pieItems.length, i, hash = {};
for (i = 0; i < len; i++) {
hash[responseObj.pieItems[i][0]] = responseObj.pieItems[i][1];
}
After changing the format I can only populate the chart with on item by adding the series and specifying the name.
chart1.addSeries("IP Other", hash["IPv6 ICMP"])
This populates the chart with that one item but if i try to add another series for example
chart1.addSeries("IP Other", hash["IPv4 Other"])
It overwrites the chart and shows the data for IP Other instead of adding another slice.
How can I add all the items in the array into the pie chart?
Pie chart supports just one series object by definition. You should add different data points for different slices. A sketch:
chart.addSeries("IP", dojo.map(responseObj, function(p){
return {
y: p[1], // value
text: p[0] // label
};
});