ECharts transform數(shù)據(jù)轉(zhuǎn)換和dataZoom在項目中使用
transform 進行數(shù)據(jù)轉(zhuǎn)換

數(shù)據(jù)轉(zhuǎn)換是這樣一個公式:outData=f(inputData)。F是轉(zhuǎn)換方法,例如filter、sort、region、boxplot、cluster、aggregate(todo)等。有了數(shù)據(jù)轉(zhuǎn)換功能,我們至少可以做到以下幾點: 將數(shù)據(jù)分成多個部分,并在不同的餅圖中顯示它們。 執(zhí)行一些數(shù)據(jù)統(tǒng)計操作并顯示結(jié)果。 使用一些數(shù)據(jù)可視化算法來處理數(shù)據(jù)并顯示結(jié)果。 數(shù)據(jù)排序。 刪除或直接選擇數(shù)據(jù)項。
series: [{
type: 'pie', radius: 50, center: ['25%', '50%'],
// 這個餅圖系列,引用了 index 為 `1` 的 dataset 。也就是,引用了上述
// 2011 年那個 "filter" transform 的結(jié)果。
datasetIndex: 1
}, {
type: 'pie', radius: 50, center: ['50%', '50%'],
datasetIndex: 2
}, {
type: 'pie', radius: 50, center: ['75%', '50%'],
datasetIndex: 3
}]
};
在大多數(shù)情況下,轉(zhuǎn)換只需要輸出一個數(shù)據(jù)。然而,也有一些場景需要輸出多個數(shù)據(jù),每個數(shù)據(jù)可以由不同的系列或數(shù)據(jù)集使用。 例如,在內(nèi)置的“boxplot”轉(zhuǎn)換中,除了boxplot系列所需的數(shù)據(jù)外,還將生成異常值,并可以使用散點圖系列進行顯示。例如 我們提供配置數(shù)據(jù)集FromTransformResult,例如:
option: {
dataset: [{
source: [ ... ] // 原始數(shù)據(jù)
}, {
// 幾個 transform 被聲明成 array ,他們構(gòu)成了一個鏈,
// 前一個 transform 的輸出是后一個 transform 的輸入。
transform: [{
type: 'filter',
config: { dimension: 'Product', value: 'Tofu' }
}, {
type: 'sort',
config: { dimension: 'Year', order: 'desc' }
}]
}],
series: {
type: 'pie',
// 這個系列引用上述 transform 的結(jié)果。
datasetIndex: 1
}
}
當(dāng)使用轉(zhuǎn)換時,有時我們將無法顯示結(jié)果,而且我們不知道哪里出了問題。因此,這里提供了一個配置項轉(zhuǎn)換。打印方便調(diào)試。此配置項僅在開發(fā)環(huán)境中生效。
option = {
dataset: [{
source: [ ... ]
}, {
transform: {
type: 'filter',
config: { ... }
print: true
}
}],
...
}
配置為 true 后, transform 的結(jié)果,會被 console.log 打印出來。

數(shù)據(jù)轉(zhuǎn)換器“排序”還具有一些附加功能: 可以將多個維度一起排序。請參見下面的示例。 整理如下: 默認值是按數(shù)值排序。其中,“可轉(zhuǎn)換為數(shù)值的字符串”也被轉(zhuǎn)換為數(shù)值,并與其他數(shù)值一起按大小排序。 其他“無法轉(zhuǎn)換為數(shù)值的字符串”也可以按字符串排序。此功能在這種情況下很有用:具有相同標(biāo)記的數(shù)據(jù)項被分組在一起,特別是當(dāng)多個維度被排序在一起時。
option = {
dataset: [{
dimensions: ['name', 'age', 'profession', 'score', 'date'],
source: [
[' Hannah Krause ', 41, 'Engineer', 314, '2011-02-12'],
['Zhao Qian ', 20, 'Teacher', 351, '2011-03-01'],
[' Jasmin Krause ', 52, 'Musician', 287, '2011-02-14'],
['Li Lei', 37, 'Teacher', 219, '2011-02-18'],
[' Karle Neumann ', 25, 'Engineer', 253, '2011-04-02'],
[' Adrian Gro?', 19, 'Teacher', null, '2011-01-16'],
['Mia Neumann', 71, 'Engineer', 165, '2011-03-19'],
[' B?hm Fuchs', 36, 'Musician', 318, '2011-02-24'],
['Han Meimei ', 67, 'Engineer', 366, '2011-03-12'],
]
}, {
transform: {
type: 'sort',
config: [
// 對兩個維度按聲明的優(yōu)先級分別排序。
{ dimension: 'profession', order: 'desc' },
{ dimension: 'score', order: 'desc' }
]
}
}],
series: {
type: 'bar',
datasetIndex: 1
},
...
};
當(dāng)對“數(shù)值和可以轉(zhuǎn)換為數(shù)值的字符串”和“不能轉(zhuǎn)換為數(shù)值”進行排序時,或者當(dāng)它們與“其他類型的值”進行比較時,它們不知道如何比較自己。然后我們將“后者”稱為“不可比”,并可以設(shè)置不可比:'min'|'max',以指定“不可比較”在該比較中是最大還是最小,以便它們可以產(chǎn)生比較結(jié)果。例如,此設(shè)置的目的是確定空值(如null、undefined、NaN、“”、“-”)是否位于排序的開始或結(jié)束。
type SortTransform = {
type: 'filter';
config: OrderExpression | OrderExpression[];
};
type OrderExpression = {
dimension: DimensionName | DimensionIndex;
order: 'asc' | 'desc';
incomparable?: 'min' | 'max';
parser?: 'time' | 'trim' | 'number';
};
type DimensionName = string;
type DimensionIndex = number;
filter:可以使用'time'|'trim'|'number',就像在數(shù)據(jù)轉(zhuǎn)換器“filter”中一樣。 如果要對時間進行排序(例如,值是JSDate實例或時間字符串,如“2012-03-12 11:13:54”),我們需要聲明解析器:“time”。 如果我們需要對后綴值進行排序(例如“33%”、“16px”),我們需要聲明parser:'number'。
dataZoom

dataZoom組件用于在軸上執(zhí)行“數(shù)據(jù)窗口縮放”和“數(shù)據(jù)窗口平移”操作。 可以使用dataZoom xAxisIndex或dataZoom YAxisIndex指定dataZoom控件的一個或多個數(shù)字軸。 同時可以有多個dataZoom組件,這些組件起到共同控制的作用??刂葡嗤幪栞S的組件將自動鏈接。下面的示例將詳細解釋。 dataZoom的工作原理是通過“數(shù)據(jù)過濾”來達到“數(shù)據(jù)窗口縮放”的效果。 數(shù)據(jù)過濾模式的不同設(shè)置具有不同的效果。dataZoom。過濾器模式。 目前,dataZoom支持兩種類型的數(shù)據(jù)窗口范圍設(shè)置: 百分比形式:dataZoomStart和dataZoom.end。 絕對數(shù)字形式:dataZoomStartValue和dataZoom.endValue。
option = {
xAxis: {
type: 'value'
},
yAxis: {
type: 'value'
},
dataZoom: [
{ // 這個dataZoom組件,默認控制x軸。
type: 'slider', // 這個 dataZoom 組件是 slider 型 dataZoom 組件
start: 10, // 左邊在 10% 的位置。
end: 60 // 右邊在 60% 的位置。
}
],
series: [
{
type: 'scatter', // 這是個『散點圖』
itemStyle: {
opacity: 0.8
},
symbolSize: function (val) {
return val[2] * 40;
},
data: [["14.616","7.241","0.896"],["3.958","5.701","0.955"],["2.768","8.971","0.669"],["9.051","9.710","0.171"],["14.046","4.182","0.536"],["12.295","1.429","0.962"],["4.417","8.167","0.113"],["0.492","4.771","0.785"],["7.632","2.605","0.645"],["14.242","5.042","0.368"]]
}
]
}
除了圖表之外,ApacheEChartsTM還提供了許多交互式組件。例如: 圖例組件圖例、標(biāo)題組件、可視化映射組件visualMap、數(shù)據(jù)區(qū)域縮放組件dataZoom、時間軸組件。 除了圖表之外,ApacheEChartsTM還提供了許多交互式組件。例如: 圖例組件圖例、標(biāo)題組件、可視化映射組件visualMap、數(shù)據(jù)區(qū)域縮放組件dataZoom、時間軸組件。
以上就是ECharts transform數(shù)據(jù)轉(zhuǎn)換和dataZoom在項目中使用的詳細內(nèi)容,更多關(guān)于ECharts transform數(shù)據(jù)轉(zhuǎn)換的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
umi插件開發(fā)仿dumi項目實現(xiàn)頁面布局詳解
這篇文章主要為大家介紹了umi插件開發(fā)仿dumi項目實現(xiàn)頁面布局詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-01-01
JS版的date函數(shù)(和PHP的date函數(shù)一樣)
這篇文章主要介紹了JS版的date函數(shù),使用方法和PHP的date函數(shù)一樣,需要的朋友可以參考下2014-05-05

