| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <template>
- <view class="charts-box">
- <qiun-data-charts type="mix" :opts="opts" :canvas2d='isCanvas2d' :canvasId='canvasId' :chartData="chartData" />
- </view>
- </template>
- <script>
- export default {
- props: {
- canvasId: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- chartData: {},
- //这里的 opts 是图表类型 type="mix" 的全部配置参数,您可以将此配置复制到 config-ucharts.js 文件中下标为 ['mix'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
- opts: {
- timing: "easeOut",
- duration: 1000,
- rotate: false,
- rotateLock: false,
- color: ["#EEF2FA"],
- padding: [15, 15, 0, 15],
- fontSize: 13,
- fontColor: "#666666",
- dataLabel: false,
- dataPointShape: false,
- dataPointShapeType: "solid",
- touchMoveLimit: 60,
- enableScroll: false,
- 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: false,
- axisLineColor: "#CCCCCC",
- calibration: false,
- fontColor: "#666666",
- fontSize: 13,
- lineHeight: 20,
- marginTop: 20,
- rotateLabel: false,
- 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: "#666666",
- format: ""
- },
- yAxis: {
- disabled: false,
- disableGrid: true,
- splitNumber: 4,
- gridType: "dash",
- dashLength: 4,
- gridColor: "#CCCCCC",
- padding: 10,
- showTitle: false,
- data: [{
- position: "left",
- title: "折线",
- calibration: false,
- type: "value",
- axisLineColor: "#ffffff"
- },
- {
- position: "right",
- min: 0,
- // max: 99999,
- title: "柱状图",
- textAlign: "left",
- disabled: false,
- axisLineColor: "#FFFFFF"
- },
- {
- position: "right",
- min: 0,
- // max: 99999,
- title: "点",
- textAlign: "left",
- calibration: false,
- disabled: true,
- axisLineColor: "#FFFFFF"
- }
- ]
- },
- extra: {
- mix: {
- column: {
- width: 30,
- seriesGap: 2,
- barBorderCircle: false,
- barBorderRadius: [
- 5,
- 5,
- 0,
- 0
- ],
- linearOpacity: 0.5,
- colorStop: 0
- },
- area: {
- opacity: 0.2,
- gradient: false
- },
- line: {
- width: 2
- }
- },
- tooltip: {
- showBox: true,
- showArrow: true,
- showCategory: false,
- borderWidth: 0,
- borderRadius: 0,
- borderColor: "#000000",
- borderOpacity: 0.7,
- bgColor: "#000000",
- bgOpacity: 0.7,
- gridType: "solid",
- dashLength: 4,
- gridColor: "#CCCCCC",
- boxPadding: 3,
- fontSize: 13,
- lineHeight: 20,
- fontColor: "#FFFFFF",
- legendShow: true,
- legendShape: "auto",
- splitLine: true,
- horizentalLine: false,
- 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 = {
- categories: ["2018", "2019", "2020", "2021", "2022"],
- series: [{
- name: "柱1",
- index: 1,
- type: "column",
- data: [160, {
- "value": 90,
- }, 100, 150, 90]
- },
- {
- name: "柱2",
- index: 1,
- type: "column",
- data: [160, {
- "value": 90,
- }, 100, 150, 90]
- },
- {
- name: "曲线",
- type: "line",
- style: "curve",
- color: "#FFD023",
- disableLegend: true,
- data: [70, 50, 85, 130, 64]
- },
- {
- name: "曲线",
- type: "line",
- style: "curve",
- color: "#0CAF60",
- disableLegend: true,
- data: [50, 20, 60, 100, 20]
- }
- ]
- };
- this.chartData = JSON.parse(JSON.stringify(res));
- }, 500);
- },
- setServerData(data){
- setTimeout(() => {
- //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
- let res = {
- categories: data.titles,
- series: [{
- name: "金额(男)",
- index: 1,
- type: "column",
- data: data.oneMoney
- },
- {
- name: "金额(女)",
- index: 2,
- type: "column",
- data: data.twoMoney
- },
- {
- name: "数量(男)",
- type: "line",
- style: "curve",
- color: "#FFD023",
- disableLegend: true,
- data: data.oneNum
- },
- {
- name: "数量(女)",
- type: "line",
- style: "curve",
- color: "#0CAF60",
- disableLegend: true,
- data: data.twoNum
- }
- ]
- };
- this.chartData = JSON.parse(JSON.stringify(res));
- }, 50);
- }
- }
- };
- </script>
- <style scoped>
- /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
- .charts-box {
- width: 100%;
- height: 300px;
- }
- </style>
|