| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <template>
- <view class="charts-box">
- <qiun-data-charts canvas2d type="mount" :ontouch="true" :opts="opts" :chartData="chartData"
- :errorMessage="errorMessage" :errorReload="false" />
- </view>
- </template>
- <script>
- export default {
- props: {
- canvasId: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- isCanvas2d: process.uniEnv.isCanvas2d,
- chartData: {},
- errorMessage: '',
- //这里的 opts 是图表类型 type="mount" 的全部配置参数,您可以将此配置复制到 config-ucharts.js 文件中下标为 ['mount'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
- opts: {
- timing: "easeIn",
- duration: 1000,
- rotate: false,
- rotateLock: false,
- color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
- "#ea7ccc"
- ],
- padding: [15, 15, 0, 5],
- fontSize: 15,
- fontColor: "#000000",
- dataLabel: true,
- dataPointShape: true,
- dataPointShapeType: "solid",
- touchMoveLimit: 60,
- enableScroll: true,
- enableMarkLine: false,
- legend: {
- show: false,
- position: "bottom",
- float: "center",
- padding: 5,
- margin: 5,
- backgroundColor: "rgba(0,0,0,0)",
- borderColor: "rgba(0,0,0,0)",
- borderWidth: 0,
- fontSize: 13,
- fontColor: "#666666",
- lineHeight: 11,
- hiddenColor: "#CECECE",
- itemGap: 10
- },
- xAxis: {
- disableGrid: true,
- disabled: false,
- axisLine: true,
- axisLineColor: "#CCCCCC",
- calibration: false,
- fontColor: "#717A89",
- fontSize: 12,
- lineHeight: 20,
- marginTop: 12,
- rotateLabel: true,
- rotateAngle: 45,
- itemCount: 5,
- boundaryGap: "center",
- splitNumber: 5,
- gridColor: "#CCCCCC",
- gridType: "solid",
- dashLength: 4,
- gridEval: 1,
- scrollShow: false,
- scrollAlign: "left",
- scrollColor: "#A6A6A6",
- scrollBackgroundColor: "#EFEBEF",
- title: "",
- titleFontSize: 13,
- titleOffsetY: 0,
- titleOffsetX: 0,
- titleFontColor: "#717A89",
- format: ""
- },
- yAxis: {
- data: [{
- min: 0
- }],
- disabled: true,
- disableGrid: false,
- splitNumber: 3,
- gridType: "dash",
- dashLength: 8,
- gridColor: "#CCCCCC",
- padding: 10,
- showTitle: false
- },
- extra: {
- mount: {
- type: "bar",
- widthRatio: 0.3,
- borderWidth: 1,
- barBorderCircle: false,
- barBorderRadius: [
- 12,
- 12,
- 0,
- 0
- ],
- linearType: "none",
- linearOpacity: 1,
- colorStop: 0
- },
- tooltip: {
- showBox: true,
- showArrow: true,
- showCategory: false,
- borderWidth: 0,
- borderRadius: 5,
- borderColor: "#000000",
- borderOpacity: 0.7,
- bgColor: "#000000",
- bgOpacity: 0.7,
- gridType: "dash",
- dashLength: 4,
- gridColor: "#cccccc",
- boxPadding: 3,
- fontSize: 13,
- lineHeight: 20,
- fontColor: "#FFFFFF",
- legendShow: true,
- legendShape: "diamond",
- splitLine: true,
- horizentalLine: true,
- xAxisLabel: false,
- yAxisLabel: false,
- labelBgColor: "#FFFFFF",
- labelBgOpacity: 0.7,
- labelFontColor: "#666666"
- },
- markLine: {
- type: "solid",
- dashLength: 4,
- data: []
- }
- }
- }
- };
- },
- onReady() {
- // this.getServerData();
- },
- methods: {
- getServerData() {
- //模拟从服务器获取数据时的延时
- setTimeout(() => {
- //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
- let res = {
- series: [{
- data: [{
- "name": "综合业务二部门",
- "value": 82
- }]
- }]
- };
- this.chartData = JSON.parse(JSON.stringify(res));
- }, 500);
- },
- setNoData() {
- this.chartData = {};
- this.errorMessage = '暂无数据'
- },
- setServerData(data) {
- setTimeout(() => {
- //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
- let res = {
- series: [{
- data: data
- }]
- };
- this.chartData = JSON.parse(JSON.stringify(res));
- }, 100);
- },
- }
- };
- </script>
- <style scoped>
- /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
- .charts-box {
- width: 100%;
- height: 300px;
- }
- </style>
|