Skip to content
本页导读

Bar 条状图

组件类型:UxChartComponentPublicInstance

平台兼容性

Android uni-app-xiOS uni-app-xweb小程序
xxx

示例代码

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>

上次更新: