|
|
|||
|
|||
|
先来看一下目标chart,从用户那里拿到的是这样一张样图,见附件age pyramid-origin.jpg,这是一种较为常见的chart,所以birt应该也能实现它。乍看之下是金字塔形的,其实是用 stacked bar chart做的。
做chart,数据很重要。我从网上搜了一大圈,可是没有找到可用的数据,只能自己造了。观察了一下样图,于是我做了一个flat file,其中包含了三列(Age, Male, Female),分别表示年龄段,男性数量,女性数量。不过我想真实的数据应该不是这样的,有待讨论。 另外,我发现这个chart的横轴是对称的,这种情况以前没有遇到过。我试了一下设置了轴的origin,但是只有轴的位置移动了,但是bar的起始点并没有跟着移动,这并不是我想要得效果。于是我想了一个方法,就是对数据做一个处理,使得一边的数据变成负值,这样就达到了bar的起始点移动的目的。但还有一个问题就是横轴的label将显示为负值,这个可以用script来修改。 主要的问题解决了,下面我把制作的详细步骤写一下,有兴趣的同学可以跟着做一下: ![]() 1.New a dataset with the flat file. 2. Insert a chart in layout. On Select Chart Type tab, select chart type as bar chart, select Subtype as stacked bar. Tick the Flip Axis option. 3. Switch to Select Data tab, Use Data from the dataset, select "Age" column as Category Series, select "Male" column as Series1. New a Series2, select "Female" column as series2. Modify the expression of Series1 as "row["Male"]*(-1)". (到这里呢,age pyramid 已经初具模型了,加油!) ![]() 4. Switch to Format Chart tab, select Series node, edit Title of Series1 as "male", Title of Series2 as "female".Select Chart Area -> Title node and edit Chart Title as "age pyramid". 5. Select Chart Area->Axis->Y-Axis node, click the scale button. In Axis Scale dialog, input Min as "-70000", Max as "70000", tick Steps Size and input "20000". Click Finish in chart builder. 6. Select the chart in layout and select Script tab, select function beforeDrawAxisLabel and input the following script: if(!axis.isCategoryAxis()&&label.getCaption().getValue()<0) label.getCaption().setValue(label.getCaption().getValue()*(-1)); 好了,大功告成了。Preview 看看吧。效果图见age pyramid.jpg. 最后,关于前面讨论的数据的问题。真实的数据可能并不是这么理想的。猜想真实的人口数据可能只包括了(出生年月,性别),这就要求我们在原始数据上加以处理来得到我们想要的数据,这个可以通过sql语句或者chart本身的数据处理功能。个人觉得chart本身处理数据的能力还是比较弱的,还有很多有待改进的地方,所以也欢迎大家多提宝贵的意见。 此帖于 2008-6-20 04:55 PM 被 Maggie Shen 编辑. |
|
||||
|
Maggie同学,能把你的flatfile贴上来吗?
![]()
__________________
Actuate China |
|
|||
|
附中文步骤:
1. 使用附件agedata新建一个数据集。 2. 在布局区插入一个图表,在选择图表类型页上,选择类型为条形图,选择子类型为堆积图表图,选中翻转坐标轴选项。 3. 切换至选择数据页,将数据集作为数据来源,选择’Age’列作为类别系列,选择’Male’列作为系列1。新建一个系列2,选择’Female’列作为系列2。修改系列1的表达式为’ row["Male"]*(-1)’。 4. 切换至图表格式页,选择系列结点,编辑系列1和系列2的标题分别为’male’和’female’。选择图表区域-〉标题结点,编辑图表标题为’age pyramid’. 5. 选择图表区域-〉坐标轴-〉Y轴结点,点击缩放比例按钮。在轴比例对话框中,输入最大值为’70000’,最小值为’-70000’,步长为’20000’。点击编辑图表对话框的完成按钮。 6. 在布局区中选中图表,切换至脚本页,选择函数事件eforeDrawAxisLabel 并输入如下脚本: if(!axis.isCategoryAxis()&&label.getCaption().getValue()<0) label.getCaption().setValue(label.getCaption().getValue()*(-1)); |
|
|||
|
新手上路,很好奇地尝试了一下搂主的demo,我碰到了些问题。
在第三步中,我把row["Female"]作为系列2的值,结果提示“数据类型不兼容”这样的信息呢?很奇怪,row["male"]也是int形的,竟然不出错。 后来我在Chart Builder点“完成”,它提示“A data definition entry for Y Series is undefined.”,不知道是不是因为刚才row["Female"]没有成功apply. 因为有以上的问题,最后preview也出错了。 我用的是最新的版本。是不是搂主遗漏了哪些步骤,还是我这儿的问题? ![]()
__________________
听琴论剑山水间 |
|
|||
|
问题出在我这边,谢谢Maggie同学。
__________________
听琴论剑山水间 |
|
|||
|
引用:
请楼主 执教 代码:
CREATE_EXTENSION_FAIL ( 1 time(s) ) detail : org.eclipse.birt.chart.exception.ChartException: CREATE_EXTENSION_FAIL at org.eclipse.birt.chart.factory.Generator.build(Generator.java:993) at org.eclipse.birt.chart.reportitem.ChartReportItemPresentationImpl.onRowSets(ChartReportItemPresentationImpl.java:499) at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.processExtendedContent(LocalizedContentVisitor.java:678) at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.visitForeign(LocalizedContentVisitor.java:368) at org.eclipse.birt.report.engine.content.impl.ForeignContent.accept(ForeignContent.java:59) at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.localize(LocalizedContentVisitor.java:102) at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:36) at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layoutChildren(HTMLPageLM.java:126) |
|
|||
|
这个问题和下面主题的问题是一样的,请参见。
http://www.actuatechina.com/thread126.html |
![]() |
| 主题工具 | 搜索本主题 |
| 显示模式 | |
|
|