Skip to content

Commit

Permalink
新增:折线图新增nameMap
Browse files Browse the repository at this point in the history
  • Loading branch information
quietcoder committed Aug 6, 2017
1 parent 4689d2e commit 1213001
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ module.exports = {
extends: 'standard',
plugins: [
'html'
]
],
rules: {
'no-mixed-operators': 'off'
}
}
5 changes: 5 additions & 0 deletions docs/line.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

<iframe width="100%" height="415" src="//jsfiddle.net/vue_echarts/jepw6dy2/34/embedded/result,html,js/?bodyColor=fff" allowfullscreen="allowfullscreen" frameborder="0"></iframe>

#### 修改指标名称

<iframe width="100%" height="415" src="//jsfiddle.net/vue_echarts/jepw6dy2/38/embedded/result,html,js/?bodyColor=fff" allowfullscreen="allowfullscreen" frameborder="0"></iframe>

#### settings 配置项

| 配置项 | 简介 | 类型 | 备注 |
Expand All @@ -20,6 +24,7 @@
| max | 左右坐标轴最大值 | Array | - |
| nullAddZero | 空值补零 | Boolean | 设置为true后,如果数据中对应某项<br>为null或undefined,则在表格中补0 |
| digit | 设置数据类型为percent时保留的位数 | Number | 默认为2 |
| labelMap | 设置指标的别名,同时作用于提示框和图例 | Object | - |
| legendName | 设置图表上方图例的别名 | Object | - |

> 备注1. axisSite 可以设置 left 和 right,例如示例所示 `axisSite: { right: ['占比'] }` 即将占比的数据置于右轴上。
Expand Down
20 changes: 20 additions & 0 deletions examples/test-data/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ export default {
},
settings: {}
},
{
name: '设置指标名称',
data: {
columns: ['date', 'balance', 'age'],
rows: [
{ 'date': '1-1', 'balance': 123, 'age': 3 },
{ 'date': '1-2', 'balance': 1223, 'age': 6 },
{ 'date': '1-3', 'balance': 2123, 'age': 9 },
{ 'date': '1-4', 'balance': 4123, 'age': 12 },
{ 'date': '1-5', 'balance': 3123, 'age': 15 },
{ 'date': '1-6', 'balance': 7123, 'age': 20 }
]
},
settings: {
labelMap: {
date: '日期',
balance: '余额'
}
}
},
{
name: '设置legend别名折线图',
data: {
Expand Down
33 changes: 22 additions & 11 deletions src/line/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ function getLineSeries (args) {
metrics,
area,
stack,
nullAddZero
nullAddZero,
labelMap
} = args
let series = []
const dataTemp = {}
Expand All @@ -47,7 +48,7 @@ function getLineSeries (args) {
})
metrics.forEach(item => {
let seriesItem = {
name: item,
name: labelMap && labelMap[item] || item,
type: 'line',
data: dataTemp[item]
}
Expand Down Expand Up @@ -100,7 +101,8 @@ function getLineYAxis (args) {
return yAxis
}

function getLineTooltip (axisSite, yAxisType, digit) {
function getLineTooltip (args) {
const { axisSite, yAxisType, digit } = args
return {
trigger: 'axis',
formatter (items) {
Expand All @@ -122,12 +124,15 @@ function getLineTooltip (axisSite, yAxisType, digit) {
}

function getLegend (args) {
const { metrics, legendName } = args
if (!legendName) return { data: metrics }
const { metrics, legendName, labelMap } = args
if (!legendName && !labelMap) return { data: metrics }
const data = labelMap
? metrics.map(item => (labelMap[item] == null ? item : labelMap[item]))
: metrics
return {
data: metrics,
data,
formatter (name) {
return legendName[name] || name
return legendName && legendName[name] || name
}
}
}
Expand All @@ -147,7 +152,8 @@ export const line = (columns, rows, settings, extra) => {
max = [null, null],
nullAddZero = false,
digit = 2,
legendName
legendName,
labelMap
} = settings
const { tooltipVisible, legendVisible } = extra
let metrics = columns.slice()
Expand All @@ -158,8 +164,12 @@ export const line = (columns, rows, settings, extra) => {
metrics.splice(columns.indexOf(dimension[0]), 1)
}

const legend = legendVisible && getLegend({ metrics, legendName })
const tooltip = tooltipVisible && getLineTooltip(axisSite, yAxisType, digit)
const legend = legendVisible && getLegend({ metrics, legendName, labelMap })
const tooltip = tooltipVisible && getLineTooltip({
axisSite,
yAxisType,
digit
})
const xAxis = getLineXAxis({ dimension, rows, xAxisName, axisVisible })
const yAxisParams = {
yAxisName,
Expand All @@ -177,7 +187,8 @@ export const line = (columns, rows, settings, extra) => {
metrics,
area,
stack,
nullAddZero
nullAddZero,
labelMap
}
const series = getLineSeries(seriesParams)
if (!xAxis || !series) return false
Expand Down

0 comments on commit 1213001

Please sign in to comment.