feat: column, bar and line charts support series

This commit is contained in:
ulleo
2025-06-16 14:28:53 +08:00
parent 35def63d0d
commit 8ffa457231
4 changed files with 22 additions and 6 deletions
@@ -8,8 +8,10 @@ export class Bar extends BaseG2Chart {
init(axis: Array<ChartAxis>, data: Array<ChartData>) {
super.init(axis, data)
const x = this.axis.filter((item) => item.type === 'x')
const y = this.axis.filter((item) => item.type === 'y')
const series = this.axis.filter((item) => item.type === 'series')
if (x.length == 0 || y.length == 0) {
return
@@ -28,5 +30,9 @@ export class Bar extends BaseG2Chart {
nice: true,
})
.interaction('elementHighlight', { background: true })
if (series.length > 0) {
this.chart?.encode('color', series[0].value).transform({ type: 'stackY' })
}
}
}
@@ -11,6 +11,7 @@ export class Column extends BaseG2Chart {
const x = this.axis.filter((item) => item.type === 'x')
const y = this.axis.filter((item) => item.type === 'y')
const series = this.axis.filter((item) => item.type === 'series')
if (x.length == 0 || y.length == 0) {
return
@@ -28,5 +29,9 @@ export class Column extends BaseG2Chart {
nice: true,
})
.interaction('elementHighlight', { background: true })
if (series.length > 0) {
this.chart?.encode('color', series[0].value).transform({ type: 'stackY' })
}
}
}
@@ -11,6 +11,7 @@ export class Line extends BaseG2Chart {
const x = this.axis.filter((item) => item.type === 'x')
const y = this.axis.filter((item) => item.type === 'y')
const series = this.axis.filter((item) => item.type === 'series')
if (x.length == 0 || y.length == 0) {
return
@@ -27,6 +28,10 @@ export class Line extends BaseG2Chart {
nice: true,
})
if (series.length > 0) {
this.chart?.encode('color', series[0].value)
}
this.chart?.line().label({
text: y[0].value,
style: {