Skip to content

Commit be12707

Browse files
Merge pull request #113 from vueblocks/develop
feat: 新增X轴和Y轴反向属性
2 parents e2a942c + c9fef0c commit be12707

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

app/data/bar.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,14 @@ export default {
162162
}
163163
},
164164
{
165-
title: '条形图',
165+
title: '条形图-X轴Y轴翻转',
166166
data: simpleData,
167167
settings: {
168168
direction: 'row',
169169
xAxisLabelType: ['zh'],
170-
xAxisLabelDigits: 0
170+
xAxisLabelDigits: 0,
171+
yAxisInverse: true,
172+
xAxisInverse: true
171173
}
172174
},
173175
{

docs/chart-bar.md

+2
Original file line numberDiff line numberDiff line change
@@ -658,3 +658,5 @@
658658
| yAxisScale | 是否是脱离 0 值比例。设置成 true 后坐标刻度不会强制包含零刻度 | Boolean | - | 参见[文档](https://www.echartsjs.com/option.html#yAxis.scale) |
659659
| yAxisName | 坐标轴名称 | Array | - | 参见[文档](https://www.echartsjs.com/option.html#yAxis.name) |
660660
| percentage | 是否是百分比堆叠柱状图,通常结合 `yAxisLabelType` 一起使用 | Boolean | `true`/`false` | 默认 `false` |
661+
| xAxisInverse | X轴方向反向| Boolean | `true`/`false` | 默认 `false` 参见[文档](https://www.echartsjs.com/zh/option.html#xAxis.inverse) |
662+
| yAxisInverse | Y轴方向反向| Boolean | `true`/`false` | 默认 `false` 参见[文档](https://www.echartsjs.com/zh/option.html#yAxis.inverse) |

src/packages/bar/chart.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class BarChart extends BaseChart {
209209
} = settings
210210

211211
// 默认柱状图
212+
// TODO 此处注意值与命名语义相反,true代表是条形图,false是柱图
212213
const isBar = direction !== 'column' && direction === 'row'
213214

214215
const defaultMeaAxisType = secondMeaAxis !== null ? ['normal', 'normal'] : ['normal']
@@ -240,6 +241,11 @@ class BarChart extends BaseChart {
240241

241242
const series = BarChart.getBarSeries(data, settings, isBar)
242243

244+
// 处理X轴和Y轴翻转
245+
const { yAxisInverse, xAxisInverse } = settings
246+
if (yAxisInverse !== undefined) yAxis.forEach(i => { i.inverse = yAxisInverse })
247+
if (xAxisInverse !== undefined) xAxis.forEach(i => { i.inverse = xAxisInverse })
248+
243249
// build echarts options
244250
const options = {
245251
grid,
@@ -251,7 +257,7 @@ class BarChart extends BaseChart {
251257
series
252258
}
253259

254-
console.log(options)
260+
// console.log(options)
255261

256262
return options
257263
}

0 commit comments

Comments
 (0)