Bar 条状图
平台兼容性
Android uni-app-x | iOS uni-app-x | web | 小程序 |
---|---|---|---|
√ | x | x | x |
示例代码
html
<template>
<ux-page :colors="['black']">
<ux-navbar title="Bar" :border="false"></ux-navbar>
<ux-col>
<view style="height: 400px;">
<ux-chart ref="UxChart" :data="chart"></ux-chart>
</view>
</ux-col>
</ux-page>
</template>
<template>
<ux-page :colors="['black']">
<ux-navbar title="Bar" :border="false"></ux-navbar>
<ux-col>
<view style="height: 400px;">
<ux-chart ref="UxChart" :data="chart"></ux-chart>
</view>
</ux-col>
</ux-page>
</template>
ts
<script>
import { UXChart } from "@/uni_modules/ux-frame/libs/types/chart.uts"
export default {
data() {
return {
}
},
computed: {
chart() : UXChart {
return {
source: {
data: this.getData(),
conf: {
sales: {
tickCount: 5
}
}
},
geom: {
interval: [{
position: 'year*sales',
}]
},
coord: {
transposed: true
},
tooltip: {
showItemMarker: false,
onShow: `function (ev) {
const items = ev.items;
items[0].name = null;
items[0].name = items[0].title;
items[0].value = '¥ ' + items[0].value;
}`
},
axis: [{
field: 'year'
}]
} as UXChart
}
},
onLoad(e : OnLoadOptions) {
},
methods: {
getData() : UTSJSONObject[] {
return [{
year: '1951 年',
sales: 38
}, {
year: '1952 年',
sales: 52
}, {
year: '1956 年',
sales: 61
}, {
year: '1957 年',
sales: 145
}, {
year: '1958 年',
sales: 48
}, {
year: '1959 年',
sales: 38
}, {
year: '1960 年',
sales: 38
}, {
year: '1962 年',
sales: 38
}] as UTSJSONObject[]
},
}
}
</script>
<script>
import { UXChart } from "@/uni_modules/ux-frame/libs/types/chart.uts"
export default {
data() {
return {
}
},
computed: {
chart() : UXChart {
return {
source: {
data: this.getData(),
conf: {
sales: {
tickCount: 5
}
}
},
geom: {
interval: [{
position: 'year*sales',
}]
},
coord: {
transposed: true
},
tooltip: {
showItemMarker: false,
onShow: `function (ev) {
const items = ev.items;
items[0].name = null;
items[0].name = items[0].title;
items[0].value = '¥ ' + items[0].value;
}`
},
axis: [{
field: 'year'
}]
} as UXChart
}
},
onLoad(e : OnLoadOptions) {
},
methods: {
getData() : UTSJSONObject[] {
return [{
year: '1951 年',
sales: 38
}, {
year: '1952 年',
sales: 52
}, {
year: '1956 年',
sales: 61
}, {
year: '1957 年',
sales: 145
}, {
year: '1958 年',
sales: 48
}, {
year: '1959 年',
sales: 38
}, {
year: '1960 年',
sales: 38
}, {
year: '1962 年',
sales: 38
}] as UTSJSONObject[]
},
}
}
</script>
css
<style lang="scss">
</style>
<style lang="scss">
</style>