flex stacked column graph
Flex: Stacked column chart – programmatically in actionscript
By bishopondevelopment
I was looking for ages for an example of a dynamically generated stacked column chart in Flex, but most of the examples were incorporating some MXML, or contained hard-coded series objects.
The example below is based on Adobe Livedocs, but I show how to generate the series arrays programatically in as3, with no use of mxml code, and apply these series to a column chart (added topanelActionscript as seen in the code below). Also, this could be easily adapted to a barchart.
If youve got any suggestions, let me know.
Flex Stacked Chart
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="initApp()" width="622" height="660">
<mx:Script>
import mx.charts.ColumnChart;
import mx.charts.series.ColumnSet;
import mx.charts.Legend;
import mx.charts.BarChart;
import mx.charts.series.BarSet;
import mx.charts.series.BarSeries;
import mx.collections.ArrayCollection;
[Bindable]
private var yearlyData:ArrayCollection = new ArrayCollection([
{month:"January", revenue:120, costs:45, overhead:102, oneTime:23},
{month:"February", revenue:108, costs:42, overhead:87, oneTime:47},
{month:"March", revenue:150, costs:82, overhead:32, oneTime:21},
{month:"April", revenue:170, costs:44, overhead:68},
{month:"May", revenue:250, costs:57, overhead:77, oneTime:17},
{month:"June", revenue:200, costs:33, overhead:51, oneTime:30},
{month:"July", revenue:145, costs:80, overhead:62, oneTime:18},
{month:"August", revenue:166, costs:87, overhead:48},
{month:"September", revenue:103, costs:56, overhead:42},
{month:"October", revenue:140, costs:91, overhead:45, oneTime:60},
{month:"November", revenue:100, costs:42, overhead:33, oneTime:67},
{month:"December", revenue:182, costs:56, overhead:25, oneTime:48},
{month:"May", revenue:120, costs:57, overhead:30}
]);
private function initApp():void {
// Create a column chart object
stackedColumnChart.dataProvider = yearlyData;
stackedColumnChart.showDataTips = true;
stackedColumnChart.width = 460;
// Set the horizontal axix category
xAxis.categoryField = "month";
stackedColumnChart.horizontalAxis = xAxis;
// ColumnSet.series is an array which contains
// an array of ColumnSeries objects.
columnSet.type = "stacked";
// Each item in seriesDetails becomes a different segment of
// a column in the stacked chart i.e. each item represents a series.
var seriesDetails:ArrayCollection = new ArrayCollection([
{YField:"costs", DisplayName:"Recurring Costs"},
{YField:"overhead", DisplayName:"Overhead Costs"},
{YField:"oneTime", DisplayName:"One-Time Costs"}
]);
// Create a ColumnSeries, and an array to be
// populated with dynamically generated columnSeries objects
var columnSeries:ColumnSeries;
var seriesArray:Array = new Array();
// Generate an array of ColumnSeries objects
// which are then be applied to the ColumnSet series.
for(var i:int = 0; i < seriesDetails.length; i++){
columnSeries = new ColumnSeries();
columnSeries.yField = seriesDetails[i].YField;
columnSeries.displayName = seriesDetails[i].DisplayName;
seriesArray.push(columnSeries);
}
columnSet.series = seriesArray;
// c.series could take an array of column sets
// for displaying mixed charts i.e. c.series = [columnSet1, columnSet2];stackedColumnChart.series = [columnSet];
var legend:Legend = new Legend();
legend.direction = "horizontal";
legend.dataProvider = stackedColumnChart;
panelActionscript.addChild(stackedColumnChart);
panelActionscript.addChild(legend);
}
<mx:Panel title="Stacked chart (dynamically created in ActionScript)"
id="panelActionscript" width="490">
</mx:Panel>
</mx:VBox>
<mx:Panel title="Same chart created solely in MXML" id="panelMxml" width="490">
<mx:ColumnChart id="mxmlColumnChart" dataProvider="{yearlyData}"
showDataTips="true" width="470">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="month"/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSet type="stacked">
<mx:ColumnSeries
yField="costs"
displayName="Recurring Costs"/>
<mx:ColumnSeries
yField="overhead"
displayName="Overhead Costs"/>
<mx:ColumnSeries
yField="oneTime"
displayName="One-Time Costs"/>
</mx:ColumnSet>
</mx:series>
</mx:ColumnChart>
<mx:Legend dataProvider="{mxmlColumnChart}" direction="horizontal"/>
</mx:Panel>
</mx:Application>
flex stacked column graph的更多相关文章
- Hello Stacked Column Chart
<navigation:Page xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/to ...
- [转]VS Code 扩展 Angular 6 Snippets - TypeScript, Html, Angular Material, ngRx, RxJS & Flex Layout
本文转自:https://marketplace.visualstudio.com/items?itemName=Mikael.Angular-BeastCode VSCode Angular Typ ...
- FCC---CSS Flexbox: Apply the flex-direction Property to Create a Column in the Tweet Embed
The tweet embed header and footer used the flex-direction property earlier with a row value. Similar ...
- Flex 布局教程:实例篇
该教程整理自 阮一峰Flexible教程 今天介绍常见布局的Flex写法.你会看到,不管是什么布局,Flex往往都可以几行命令搞定. 我的主要参考资料是Landon Schropp的文章和Solved ...
- CSS布局之div交叉排布与底部对齐--flex实现
最近在用wordpress写页面时,设计师给出了一种网页排布图样,之前从未遇到过,其在电脑上(分辨率大于768px)的效果图如下: 而在手机(分辨率小于等于768px)上要求这样排列: 我想到了两种方 ...
- 在移动端中的flex布局
flex布局介绍: flex布局很灵活, 这种布局我们也可以称之为弹性布局, 弹性布局的主要优势就是元素的宽或者高会自动补全; flex布局实例: 比如有两个div,一个div的宽度为100px, ...
- flex实验总结
1.父元素 .box{ display:flex; flex-direction: column;//铺满垂直排列 flex-direction: column-reverse;//铺满垂直反向排列 ...
- 解决UC浏览器或微信浏览器上flex兼容问题
在UC浏览器上使用display:flex;时会不起作用,要加上兼容性写法,如下 display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */ disp ...
- flex引起height:100%失效
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
随机推荐
- loadrunner测试c/s架构的应用系统
用LoadRunner测试c/s架构的软件,怎样去选择协议,困扰了我很久,看到这篇文章,感觉有点收获,所以特意转了过来,希望对大家有用. 首先,什么是协议?协议无非就是一个约定,关于数据包发送的格式的 ...
- August 22nd 2017 Week 34th Tuesday
Stop trying to find a rewind. It's life, not a movie. 别妄想倒带,这是生活,不是电影. There is no need to go back t ...
- ZT 匿名内存映射
mmap函数使用 分类: Linux/Unix C/C++ 2008-01-22 17:03 6089人阅读 评论(1) 收藏 举报 unix编程null网络 UNIX网络编程第二卷进程间通信对mma ...
- Alpha Scrum7
Alpha Scrum7 牛肉面不要牛肉不要面 Alpha项目冲刺(团队作业5) 各个成员在 Alpha 阶段认领的任务 林志松:项目发布 陈远军.陈彬:播放器各环境的测试 项目的发布说明 本版本的新 ...
- python新建以时间命名的目录
1.新建三级目录,第一级是去年的年份,第二级是去年的月,第三级为去年的日,在日的文件中写入今年的时分秒 import os import time import shutil def create_f ...
- 批量修改文件格式到UTF-8
系统环境: Unbuntu14.10 目标: 多个文件夹加下的大量.java文件,需要由ASCII,转为UTF-8编码格式,文件嵌套较深. 解决方案: 执行Console中,目标目录下执行一下命令: ...
- Java集合源码 -- Collection框架概述
1.概述 collection框架是用于处理各种数据结构的,要根据各种数据结构的特点理解它 它能够保存对象,并提供很多的操作去管理对象,当你面临下面的情况时,也许你应该考虑用集合类 1.容器的长度是不 ...
- Golang测试包
Golang测试包 golang自带了测试包(testing),直接可以进行单元测试.性能分析.输出结果验证等.简单看着官方文档试了试,总结一下: 目录结构和命令 使用golang的测试包,需要遵循简 ...
- 修改Xcode工程名称
概述 有的时候需要在现有的项目上面开发一个新的项目,如果新建工程的话,就比较麻烦了,所以一般是直接现有的工程上面直接修改名字步骤如下: 1.修改工程名字 在这里修改完之后,会弹出一个对话框,点击Ren ...
- 三维偏序 cdq
luogu_3810 就是将逆序对转化到了三维上去 原理等我寒假再补 第一维sort解决 第二维并归排序(cdq)解决 第三维树状数组 // luogu-judger-enable-o2 #inclu ...