之前谈到过用MSChart可以比较直观方便的实现对多维数据集的展示,做得比较粗略。这次详细介绍下我的经验,并提供主要的试验代码段。
有必要强调一下,对多维数据集的展示,层次性是非常必要的。多维数据集本身就是带有层次结构的,如何直观而又不产生歧义的正确展示出其原本的数据集合结构,成为众多据仓库展示工具软件开发商关心的问题。在选型方面,目前市场上已经有比较多的选择,相当多的第三方图形控件就已经直接支持多维数据集的展示,即直接把CellSet结果赋给该控件的DataSource即可。但是这些目前毕竟是市场化的东西,作为个人开发学习没有必要去购买---试用版的由于其种种限制,给人感觉很不舒服。
拿FoodMart 2000做例子,比如要分析第一季度(Q1)、第二季度(Q2)的食品(Food)、饮料(Drink)在加利福尼亚州(CA)、俄勒冈州(OR)、华盛顿(WA)的Store cost 和 Store sales 的情况,使用如下的MDX语句分析:
SELECT
{ { { [Customers].[State Province].&[CA], [Customers].[State Province].&[OR], [Customers].[State Province].&[WA] } * { [Measures].[Store Cost], [Measures].[Store Sales] } } } ON COLUMNS ,
{ { { [Product].[Product Family].&[Drink], [Product].[Product Family].&[Food] } * { [Time].&[1997].&[Q1], [Time].&[1997].&[Q2] } } } ON ROWS
FROM [Sales]
先看在FlexGrid的展示结果:
能够非常清晰的产看各个区域的对应的值。
如果只是想要看一下趋势,这个时候用图形分析就显得更加直观:
而且图形展示可以任意行列切换:
图形展示的缺点是不能察看所有具体的值(全都在图形上展示出来也可以,但是会显得很拥挤),这个没有关系,我们可以在选择某个系列的时候显示实该系列的所有值:
由于某些客观因素,仅提供我的测试代码,也就没有用到CellSet:
1. 首先设置行列标签数和行列数
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2. 接下来就可以给MSChart赋值,赋值由两种方式:
1) 各个单元分别赋值:
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
4
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
6
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![ExpandedSubBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
9
![ExpandedBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
2) 直接赋一个二维的数组值:
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
这里有一点要注意,如果使用这种方式,必须先填充数据,再填充标签,否则所填标签会失效。
3. 填充标签,如何体现多维数据集的层次结构,这是关键的一步。具体填充标签的时候,可以先对各个级别的标签进行分析,合并连续重复的文字标签,进行金字塔式的填充。在我的试验中没有标签分析的函数,而是在知道层次结构的情况下进行的填充,代码都比较简单。
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![ExpandedSubBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
4. 试验的图片保存效果是这样的:
3D效果: