数据源

准备原始数据

2份原始模拟数据源的链接可在此下载:点我点我点我 使用sqliteBrower打开db.

元数据:

dataSetId :ee58500e-3468-42a6-84cc-037c75d6c27c

截图1

各列字段代表的意义:

COL_0_0:城市 COL_0_1: PM值 COL_0_2:污染情况 COL_0_3:年 COL_0_4:月 COL_0_5:日

dataSetId :707ff652-263f-4977-8f19-6a329f94ab25

截图2

各列字段代表的意义:

COL_0_1:年 COL_0_2:月 COL_0_3:日 COL_0_4:AQI COL_0_5:污染情况 COL_0_6:城市

dataSetId :3946ed0d-a3b5-43c6-9b56-97b5966879de 截图2

定义多维结构

将多维数据源的结构以json定义:


[
    {
        "dataSetId": "707ff652-263f-4977-8f19-6a329f94ab25",
        "dimensions": [
            {
                "granularities": [
                    {
                        "key": "COL_0",
                        "title": "城市"
                    }
                ],
                "key": "Dimension_1",
                "title": "区域"
            },
            {
                "granularities": [
                    {
                        "key": "COL_3",
                        "linkMatchKey": "yearOfKey",
                        "selectionValue": "2015",
                        "title": "年"
                    },
                    {
                        "dateFormat": {
                            "xDataSourceDateFormatString": "MM",
                            "xDataSourceDateLocale": "zh",
                            "xDisplayDateFormatString": "MMM",
                            "xDisplayDateLocale": "zh"
                        },
                        "drillTo": true,
                        "key": "COL_4",
                        "linkMatchKey": "monthKey",
                        "title": "月"
                    },
                    {
                        "key": "COL_5",
                        "linkMatchKey": "dayOfKey",
                        "title": "日"
                    }
                ],
                "key": "Dimension_3",
                "title": "时间"
            },
            {
                "granularities": [
                    {
                        "key": "COL_2",
                        "title": "污染情况"
                    }
                ],
                "key": "Dimension_2",
                "title": "空气质量情况"
            }
        ],
        "measures": [
            {
                "aggregator": "count",
                "aggregatorGroupByLastGran": true,
                "aggregatorSubGranKey": "COL_5",
                "key": "COL_1",
                "title": "次数"
            }
        ]
    },
    {
        "dataSetId": "3946ed0d-a3b5-43c6-9b56-97b5966879de",
        "dimensions": [
            {
                "granularities": [
                    {
                        "key": "COL_0_0",
                        "linkMatchKey": "yearOfKey",
                        "selectionValue": "2015",
                        "title": "年"
                    },
                    {
                        "drillTo": true,
                        "key": "COL_0_1",
                        "linkMatchKey": "monthKey",
                        "regularExpression": "(.*)月$",
                        "sort": "NXSortOperationAsc",
                        "sortLanguage": "NXSortRegularExpressNum",
                        "title": "月"
                    },
                    {
                        "key": "COL_0_2",
                        "linkMatchKey": "dayOfKey",
                        "title": "日"
                    },
                    {
                        "key": "COL_0_3",
                        "title": "时刻"
                    }
                ],
                "key": "Dimension_1",
                "title": "时间"
            },
            {
                "granularities": [
                    {
                        "key": "COL_0_4",
                        "title": "交通类型"
                    },
                    {
                        "key": "COL_0_5",
                        "title": "站点"
                    }
                ],
                "key": "Dimension_2",
                "title": "交通方式"
            }
        ],
        "measures": [
            {
                "key": "COL_0_6",
                "title": "交易量"
            }
        ]
    },
    {
        "dataSetId": "ee58500e-3468-42a6-84cc-037c75d6c27c",
        "dimensions": [
            {
                "granularities": [
                    {
                        "key": "COL_6",
                        "title": "城市"
                    }
                ],
                "key": "Dimension_3",
                "title": "区域"
            },
            {
                "granularities": [
                    {
                        "key": "COL_1",
                        "linkMatchKey": "yearOfKey",
                        "selectionValue": "2015",
                        "title": "年"
                    },
                    {
                        "dateFormat": {
                            "xDataSourceDateFormatString": "MM",
                            "xDataSourceDateLocale": "zh",
                            "xDisplayDateFormatString": "MMM",
                            "xDisplayDateLocale": "zh"
                        },
                        "drillTo": true,
                        "key": "COL_2",
                        "linkMatchKey": "monthKey",
                        "title": "月"
                    },
                    {
                        "key": "COL_3",
                        "linkMatchKey": "dayOfKey",
                        "title": "日"
                    }
                ],
                "key": "Dimension_1",
                "title": "时间"
            },
            {
                "granularities": [
                    {
                        "key": "COL_5",
                        "title": "污染情况"
                    }
                ],
                "key": "Dimension_2",
                "title": "空气质量情况"
            }
        ],
        "measures": [
            {
                "aggregator": "count",
                "aggregatorGroupByLastGran": true,
                "aggregatorSubGranKey": "COL_3",
                "key": "COL_4",
                "title": "次数"
            }
        ]
    }
]

维粒度设定解析 不同数据源间的数据源联动需指定linkMatchKey,比如ee58500e-3468-42a6-84cc-037c75d6c27c中的COL_2代表月,3946ed0d-a3b5-43c6-9b56-97b5966879de中的COL_1也代表月,当他们值相同时如果想让它们进行联动,指定它们的 linkMatchKey为相同的值即可。

drillTo在月上设定表明时间维度默认钻取到月,而对月以下的日进行了隐藏。 dateFormat.xDataSourceDateFormatString表示该日期从db读过来的格式,与JAVA的SimpleDateFormat用法一致,xDataSourceDateLocale表示是中文的日期.xDisplayDateFormatString是输出时显示的格式,xDisplayDateLocale是输出显示的语言,如果设置成"en",那么将会显示Jan,Feb,"zh"显示的是一月,二月。。。

selectionValue设定了默认应该选中的值。

度量解析

{
    "aggregator": "count",
    "aggregatorGroupByLastGran": true,
    "aggregatorSubGranKey": "COL_3",
    "key": "COL_4",
    "title": "次数"
}

这个度量的配置是为了表示「当前时间层级」默认钻取到月,也就是:一个月内的天数按污染情况进行天数统计 aggregator是表示算其次数 aggregatorSubGranKey是为了表示按天按次数 aggregatorGranKey此处未指定,未指定时会动态去取aggregatorSubGranKey所在维度最低层级的粒度,即时间维度的月,如果时间维度上钻到年,此时会变成一年内的天数按污染情况进行天数统计。aggregatorGranKey若指定死了,当时间层级被上钻到年时,依然是按月统计。 aggregatorGroupByLastGran指定true表示以「图形粒度:卡片中的最后一个粒度」分类统计。

使用服务器生成多维数据db

将上面的json转化为NXCubeStructure,并生成多层级的sqlitedb.此处源数据从sqlite里读的,因此使用NXProducerSQLiteDataSource. 若源数据从mysql,oracle读的,使用相应的NXProducerMysqlDataSource,NXProducerOracleDataSource。

NXCubeStructure cube=NXCubeStructure.fill("json structure string abrove"); NXProducerSQLiteDataSource productor = new NXProducerSQLiteDataSource(){ @Override public String getTargetDatabaseFolderPath() { return "db file generate path folder"; } }; productor.createCube("datasetid", cube.getDataSetId(), cube.getDimensions(), cube.getMeasures(), cube.getEncrypt());

接下来需要定义图表配置文件。 点我跳转

results matching ""

    No results matching ""