123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509 |
- <template>
- <view class="page">
- <view class="chart" v-if="testData.length">
- <cusEcharts :option="testOption"></cusEcharts>
- </view>
- <view class="chart" v-if="kxData.length">
- <cusEcharts :option="kxOption"></cusEcharts>
- </view>
- <view class="chart" v-if="kxData2.length">
- <cusEcharts :option="kxOption2"></cusEcharts>
- </view>
- <tabbar :tabbarIndex="1"></tabbar>
- </view>
- </template>
- <script>
- import * as echarts from "echarts";
- import aqiData from '@/static/js/aqi-beijing.js'
- export default {
- data(){
- return {
- testData:[],
- testOption:null,
- kxData:[],
- kxOption:null,
- kxData2:[],
- kxOption2:null
- }
- },
- mounted() {
- this.init();
- },
- methods:{
- init(){
- this.initTestChart();
- this.initKxChart();
- this.initKxChart2();
- },
- initTestChart(){
- this.testData = [150, 230, 224, 218, 135, 147, 260];
- this.testOption = {
- xAxis: {
- type: 'category',
- data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
- },
- yAxis: {
- type: 'value'
- },
- series: [
- {
- data: this.testData,
- type: 'line'
- }
- ]
- };
- },
- initKxChart(){
- this.kxData = [270,220,350,210,280,400];
- const offsetX = 4;
- const offsetY = 2;
- // 绘制左侧面
- const CubeLeft = echarts.graphic.extendShape({
- shape: {
- x: 0,
- y: 0,
- },
- buildPath: function (ctx, shape) {
- // 会canvas的应该都能看得懂,shape是从custom传入的
- const xAxisPoint = shape.xAxisPoint;
- const c0 = [shape.x, shape.y];
- const c1 = [shape.x - offsetX, shape.y - offsetY];
- const c2 = [xAxisPoint[0] - offsetX, xAxisPoint[1] - offsetY];
- const c3 = [xAxisPoint[0], xAxisPoint[1]];
- ctx
- .moveTo(c0[0], c0[1])
- .lineTo(c1[0], c1[1])
- .lineTo(c2[0], c2[1])
- .lineTo(c3[0], c3[1])
- .closePath();
- },
- });
- // 绘制右侧面
- const CubeRight = echarts.graphic.extendShape({
- shape: {
- x: 0,
- y: 0,
- },
- buildPath: function (ctx, shape) {
- const xAxisPoint = shape.xAxisPoint;
- const c1 = [shape.x, shape.y];
- const c2 = [xAxisPoint[0], xAxisPoint[1]];
- const c3 = [xAxisPoint[0] + offsetX, xAxisPoint[1] - offsetY];
- const c4 = [shape.x + offsetX, shape.y - offsetY];
- ctx
- .moveTo(c1[0], c1[1])
- .lineTo(c2[0], c2[1])
- .lineTo(c3[0], c3[1])
- .lineTo(c4[0], c4[1])
- .closePath();
- },
- });
- // 绘制顶面
- const CubeTop = echarts.graphic.extendShape({
- shape: {
- x: 0,
- y: 0,
- },
- buildPath: function (ctx, shape) {
- const c1 = [shape.x, shape.y];
- const c2 = [shape.x + offsetX, shape.y - offsetY]; //右点
- const c3 = [shape.x, shape.y - offsetX];
- const c4 = [shape.x - offsetX, shape.y - offsetY];
- ctx
- .moveTo(c1[0], c1[1])
- .lineTo(c2[0], c2[1])
- .lineTo(c3[0], c3[1])
- .lineTo(c4[0], c4[1])
- .closePath();
- },
- });
- // 注册三个面图形
- echarts.graphic.registerShape("CubeLeft", CubeLeft);
- echarts.graphic.registerShape("CubeRight", CubeRight);
- echarts.graphic.registerShape("CubeTop", CubeTop);
- this.kxOption = {
- tooltip: {
- trigger: 'axis',
- backgroundColor: 'rgba(13,5,30,.6)',
- borderWidth: 1,
- borderColor: '#4ddd8f',
- padding: 5,
- textStyle: {
- color: '#fff'
- }
- },
- legend: {
- right: 170,
- top: 15,
- textStyle: {
- fontSize: 12,
- color: '#A7BFDE'
- },
- itemWidth: 6,
- itemHeight: 8
- },
- grid: {
- left: '4%',
- right: '3%',
- top: '25%',
- bottom: '8%',
- containLabel: true,
- },
- xAxis: {
- type: 'category',
- data: ['3月', '4月', '5月', '6月', '7月', '8月'],
- axisPointer: {
- type: 'shadow'
- },
- axisTick: {
- show: true,
- length: 4,
- lineStyle: {
- color: 'rgba(199,211,229,0.5)'
- }
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: 'rgba(199,211,229,0.5)'
- }
- },
- axisLabel: {
- color: '#c7d3e5'
- }
- },
- yAxis: {
- name:'(单位)',
- type: 'value',
- nameTextStyle: {
- fontSize: 12,
- color: '#C6D7F1',
- fontWeight: 400,
- },
- nameGap: 25,
- axisLine: {
- show: false,
- lineStyle: {
- width: 1,
- color: '#545454'
- }
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: 'rgba(199,211,229,0.3)',
- width: 1,
- type: 'dashed'
- }
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- fontSize: 12,
- color: '#c7d3e5'
- }
- },
- series: [
- {
- name: "国内",
- type: "custom",
- renderItem: (params, api) => {
- const location = api.coord([api.value(0), api.value(1)]);
- const xAxisPoint = api.coord([api.value(0), 0]);
- const distance = 7;
- return {
- type: "group",
- children: [{
- type: "CubeLeft",
- shape: {
- api,
- xValue: api.value(0),
- yValue: api.value(1),
- x: location[0] + distance,
- y: location[1],
- xAxisPoint: [xAxisPoint[0] + distance, xAxisPoint[1]],
- },
- style: {
- fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: '#0B5FA9',
- },
- {
- offset: 1,
- color: 'rgba(11,95,169,0)'
- }
- ]),
- },
- },
- {
- type: "CubeRight",
- shape: {
- api,
- xValue: api.value(0),
- yValue: api.value(1),
- x: location[0] + distance,
- y: location[1],
- xAxisPoint: [xAxisPoint[0] + distance, xAxisPoint[1]],
- },
- style: {
- fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: '#088BFF',
- },
- {
- offset: 1,
- color: 'rgba(8,139,255,0)'
- }
- ]),
- },
- },
- {
- type: "CubeTop",
- shape: {
- api,
- xValue: api.value(0),
- yValue: api.value(1),
- x: location[0] + distance,
- y: location[1],
- xAxisPoint: [xAxisPoint[0] + distance, xAxisPoint[1]],
- },
- style: {
- fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: '#61B5FF',
- },
- {
- offset: 1,
- color: '#61B5FF'
- }
- ]),
- },
- },
- ],
- };
- },
- itemStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: "#00BFF4",
- },
- {
- offset: 1,
- color: "#A5E2FF",
- },
- ]),
- },
- data: [410,330,210,210,480,190],
- },
- {
- name: "出口",
- type: "custom",
- renderItem: (params, api) => {
- const location = api.coord([api.value(0), api.value(1)]);
- const xAxisPoint = api.coord([api.value(0), 0]);
- const distance = 7;
- return {
- type: "group",
- children: [{
- type: "CubeLeft",
- shape: {
- api,
- xValue: api.value(0),
- yValue: api.value(1),
- x: location[0] - distance,
- y: location[1],
- xAxisPoint: [xAxisPoint[0] - distance, xAxisPoint[1]],
- },
- style: {
- fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: '#28A9A2',
- },
- {
- offset: 1,
- color: 'rgba(40,169,162,0)'
- }
- ]),
- },
- },
- {
- type: "CubeRight",
- shape: {
- api,
- xValue: api.value(0),
- yValue: api.value(1),
- x: location[0] - distance,
- y: location[1],
- xAxisPoint: [xAxisPoint[0] - distance, xAxisPoint[1]],
- },
- style: {
- fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: '#35FFF4',
- },
- {
- offset: 1,
- color: 'rgba(53,255,244,0)'
- }
- ]),
- },
- },
- {
- type: "CubeTop",
- shape: {
- api,
- xValue: api.value(0),
- yValue: api.value(1),
- x: location[0] - distance,
- y: location[1],
- xAxisPoint: [xAxisPoint[0] - distance, xAxisPoint[1]],
- },
- style: {
- fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: '#7EFFF8',
- },
- {
- offset: 1,
- color: '#7EFFF8'
- }
- ]),
- },
- },
- ],
- };
- },
- itemStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: "#6AAAFF",
- },
- {
- offset: 1,
- color: "#046EFE",
- },
- ]),
- },
- data: this.kxData,
- }
- ],
- };
- },
- initKxChart2(){
- this.kxData2 = [0];
- let data = aqiData;
- this.kxOption2 = {
- title: {
- text: 'Beijing AQI',
- left: '1%'
- },
- tooltip: {
- trigger: 'axis'
- },
- grid: {
- left: '10%',
- right: '150px',
- bottom: '20%'
- },
- xAxis: {
- data: data.map(function (item) {
- return item[0];
- })
- },
- yAxis: {},
- dataZoom: [
- {
- startValue: '2014-06-01'
- },
- {
- type: 'inside'
- }
- ],
- visualMap: {
- top: 50,
- right: 10,
- pieces: [
- {
- gt: 0,
- lte: 50,
- color: '#93CE07'
- },
- {
- gt: 50,
- lte: 100,
- color: '#FBDB0F'
- },
- {
- gt: 100,
- lte: 150,
- color: '#FC7D02'
- },
- {
- gt: 150,
- lte: 200,
- color: '#FD0100'
- },
- {
- gt: 200,
- lte: 300,
- color: '#AA069F'
- },
- {
- gt: 300,
- color: '#AC3B2A'
- }
- ],
- outOfRange: {
- color: '#999'
- }
- },
- series: {
- name: 'Beijing AQI',
- type: 'line',
- data: data.map(function (item) {
- return item[1];
- }),
- markLine: {
- silent: true,
- lineStyle: {
- color: '#333'
- },
- data: [
- {
- yAxis: 50
- },
- {
- yAxis: 100
- },
- {
- yAxis: 150
- },
- {
- yAxis: 200
- },
- {
- yAxis: 300
- }
- ]
- }
- }
- }
- },
- }
- }
- </script>
- <style scoped lang="less">
- .chart{
- width: 100%;
- height: 300px;
- margin-top: 50px;
- &:first-child{
- margin-top: 0;
- }
- }
- </style>
|