Commit ebd4dd54 by 王志慧

echart

1 parent 9d0d4e53
<canvas
class="f2-canvas"
canvas-id="{{ canvasId }}"
bindinit="init"
bindtouchstart="touchStart"
bindtouchmove="touchMove"
bindtouchend="touchEnd"
bindlongtap="press"
>
</canvas>
\ No newline at end of file \ No newline at end of file
This diff could not be displayed because it is too large.
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _EventEmitterMin = require('./EventEmitter.min.js');
var _EventEmitterMin2 = _interopRequireDefault(_EventEmitterMin);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CAPITALIZED_ATTRS_MAP = {
fontSize: 'FontSize',
opacity: 'GlobalAlpha',
lineDash: 'LineDash',
textAlign: 'TextAlign'
};
/**
* wxapp textAlign align 可选值为 left|center|right
* 标准canvas textAlign align 可选值为 left|center|right|start|end
*/
var TEXT_ALIGN_MAP = {
'start': 'left',
'end': 'right'
};
var Renderer = function (_EventEmitter) {
_inherits(Renderer, _EventEmitter);
function Renderer(wxCtx) {
_classCallCheck(this, Renderer);
var _this = _possibleConstructorReturn(this, (Renderer.__proto__ || Object.getPrototypeOf(Renderer)).call(this));
var self = _this;
self.ctx = wxCtx;
self.style = {}; // just mock
self._initContext(wxCtx);
return _this;
}
_createClass(Renderer, [{
key: 'getContext',
value: function getContext(type) {
if (type === '2d') {
return this.ctx;
}
}
}, {
key: '_initContext',
value: function _initContext(wxCtx) {
Object.keys(CAPITALIZED_ATTRS_MAP).map(function (style) {
Object.defineProperty(wxCtx, style, {
set: function set(value) {
if (style == "textAlign") {
value = TEXT_ALIGN_MAP[value] ? TEXT_ALIGN_MAP[value] : value;
}
var name = 'set' + CAPITALIZED_ATTRS_MAP[style];
wxCtx[name](value);
}
});
});
}
}]);
return Renderer;
}(_EventEmitterMin2.default);
exports.default = Renderer;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJlbmRlcmVyLmpzIl0sIm5hbWVzIjpbIkNBUElUQUxJWkVEX0FUVFJTX01BUCIsImZvbnRTaXplIiwib3BhY2l0eSIsImxpbmVEYXNoIiwidGV4dEFsaWduIiwiVEVYVF9BTElHTl9NQVAiLCJSZW5kZXJlciIsInd4Q3R4Iiwic2VsZiIsImN0eCIsInN0eWxlIiwiX2luaXRDb250ZXh0IiwidHlwZSIsIk9iamVjdCIsImtleXMiLCJtYXAiLCJkZWZpbmVQcm9wZXJ0eSIsInNldCIsInZhbHVlIiwibmFtZSIsIkV2ZW50RW1pdHRlciJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUE7Ozs7Ozs7Ozs7OztBQUVBLElBQU1BLHdCQUF3QjtBQUM1QkMsWUFBVSxVQURrQjtBQUU1QkMsV0FBUyxhQUZtQjtBQUc1QkMsWUFBVSxVQUhrQjtBQUk1QkMsYUFBVztBQUppQixDQUE5Qjs7QUFPQTs7OztBQUlBLElBQU1DLGlCQUFpQjtBQUNyQixXQUFTLE1BRFk7QUFFckIsU0FBTztBQUZjLENBQXZCOztJQUtxQkMsUTs7O0FBQ25CLG9CQUFZQyxLQUFaLEVBQW1CO0FBQUE7O0FBQUE7O0FBRWpCLFFBQU1DLFlBQU47QUFDQUEsU0FBS0MsR0FBTCxHQUFXRixLQUFYO0FBQ0FDLFNBQUtFLEtBQUwsR0FBYSxFQUFiLENBSmlCLENBSUE7QUFDakJGLFNBQUtHLFlBQUwsQ0FBa0JKLEtBQWxCO0FBTGlCO0FBTWxCOzs7OytCQUVVSyxJLEVBQU07QUFDZixVQUFJQSxTQUFTLElBQWIsRUFBbUI7QUFDakIsZUFBTyxLQUFLSCxHQUFaO0FBQ0Q7QUFDRjs7O2lDQUVZRixLLEVBQU87QUFDbEJNLGFBQU9DLElBQVAsQ0FBWWQscUJBQVosRUFBbUNlLEdBQW5DLENBQXVDLGlCQUFTO0FBQzlDRixlQUFPRyxjQUFQLENBQXNCVCxLQUF0QixFQUE2QkcsS0FBN0IsRUFBb0M7QUFDbENPLGVBQUssb0JBQVM7QUFDWixnQkFBSVAsU0FBUyxXQUFiLEVBQTBCO0FBQ3hCUSxzQkFBUWIsZUFBZWEsS0FBZixJQUF3QmIsZUFBZWEsS0FBZixDQUF4QixHQUFnREEsS0FBeEQ7QUFDRDtBQUNELGdCQUFNQyxPQUFPLFFBQVFuQixzQkFBc0JVLEtBQXRCLENBQXJCO0FBQ0FILGtCQUFNWSxJQUFOLEVBQVlELEtBQVo7QUFDRDtBQVBpQyxTQUFwQztBQVNELE9BVkQ7QUFXRDs7OztFQTNCbUNFLHlCOztrQkFBakJkLFEiLCJmaWxlIjoicmVuZGVyZXIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgRXZlbnRFbWl0dGVyIGZyb20gJy4vRXZlbnRFbWl0dGVyLm1pbi5qcydcblxuY29uc3QgQ0FQSVRBTElaRURfQVRUUlNfTUFQID0ge1xuICBmb250U2l6ZTogJ0ZvbnRTaXplJyxcbiAgb3BhY2l0eTogJ0dsb2JhbEFscGhhJyxcbiAgbGluZURhc2g6ICdMaW5lRGFzaCcsXG4gIHRleHRBbGlnbjogJ1RleHRBbGlnbicsXG59O1xuXG4vKipcbiAqIHd4YXBwIHRleHRBbGlnbiBhbGlnbiDlj6/pgInlgLzkuLogbGVmdHxjZW50ZXJ8cmlnaHRcbiAqIOagh+WHhmNhbnZhcyB0ZXh0QWxpZ24gYWxpZ24g5Y+v6YCJ5YC85Li6IGxlZnR8Y2VudGVyfHJpZ2h0fHN0YXJ0fGVuZFxuICovXG5jb25zdCBURVhUX0FMSUdOX01BUCA9IHtcbiAgJ3N0YXJ0JzogJ2xlZnQnLFxuICAnZW5kJzogJ3JpZ2h0Jyxcbn07XG5cbmV4cG9ydCBkZWZhdWx0IGNsYXNzIFJlbmRlcmVyIGV4dGVuZHMgRXZlbnRFbWl0dGVyIHtcbiAgY29uc3RydWN0b3Iod3hDdHgpIHtcbiAgICBzdXBlcigpO1xuICAgIGNvbnN0IHNlbGYgPSB0aGlzO1xuICAgIHNlbGYuY3R4ID0gd3hDdHg7XG4gICAgc2VsZi5zdHlsZSA9IHt9OyAvLyBqdXN0IG1vY2tcbiAgICBzZWxmLl9pbml0Q29udGV4dCh3eEN0eCk7XG4gIH1cblxuICBnZXRDb250ZXh0KHR5cGUpIHtcbiAgICBpZiAodHlwZSA9PT0gJzJkJykge1xuICAgICAgcmV0dXJuIHRoaXMuY3R4O1xuICAgIH1cbiAgfVxuXG4gIF9pbml0Q29udGV4dCh3eEN0eCkge1xuICAgIE9iamVjdC5rZXlzKENBUElUQUxJWkVEX0FUVFJTX01BUCkubWFwKHN0eWxlID0+IHtcbiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh3eEN0eCwgc3R5bGUsIHtcbiAgICAgICAgc2V0OiB2YWx1ZSA9PiB7XG4gICAgICAgICAgaWYgKHN0eWxlID09IFwidGV4dEFsaWduXCIpIHtcbiAgICAgICAgICAgIHZhbHVlID0gVEVYVF9BTElHTl9NQVBbdmFsdWVdID8gVEVYVF9BTElHTl9NQVBbdmFsdWVdIDogdmFsdWU7XG4gICAgICAgICAgfVxuICAgICAgICAgIGNvbnN0IG5hbWUgPSAnc2V0JyArIENBUElUQUxJWkVEX0FUVFJTX01BUFtzdHlsZV07XG4gICAgICAgICAgd3hDdHhbbmFtZV0odmFsdWUpO1xuICAgICAgICB9XG4gICAgICB9KTtcbiAgICB9KTtcbiAgfVxufVxuIl19
\ No newline at end of file \ No newline at end of file
import WxCanvas from './wx-canvas';
import * as echarts from './echarts';
let ctx;
function compareVersion(v1, v2) {
v1 = v1.split('.')
v2 = v2.split('.')
const len = Math.max(v1.length, v2.length)
while (v1.length < len) {
v1.push('0')
}
while (v2.length < len) {
v2.push('0')
}
for (let i = 0; i < len; i++) {
const num1 = parseInt(v1[i])
const num2 = parseInt(v2[i])
if (num1 > num2) {
return 1
} else if (num1 < num2) {
return -1
}
}
return 0
}
Component({
properties: {
canvasId: {
type: String,
value: 'ec-canvas'
},
ec: {
type: Object
},
forceUseOldCanvas: {
type: Boolean,
value: false
}
},
data: {
isUseNewCanvas: false
},
ready: function () {
// Disable prograssive because drawImage doesn't support DOM as parameter
// See https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.drawImage.html
echarts.registerPreprocessor(option => {
if (option && option.series) {
if (option.series.length > 0) {
option.series.forEach(series => {
series.progressive = 0;
});
}
else if (typeof option.series === 'object') {
option.series.progressive = 0;
}
}
});
if (!this.data.ec) {
console.warn('组件需绑定 ec 变量,例:<ec-canvas id="mychart-dom-bar" '
+ 'canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>');
return;
}
if (!this.data.ec.lazyLoad) {
this.init();
}
},
methods: {
init: function (callback) {
const version = wx.getSystemInfoSync().SDKVersion
const canUseNewCanvas = compareVersion(version, '2.9.0') >= 0;
const forceUseOldCanvas = this.data.forceUseOldCanvas;
const isUseNewCanvas = canUseNewCanvas && !forceUseOldCanvas;
this.setData({ isUseNewCanvas });
console.log(this.data.isUseNewCanvas)
if (forceUseOldCanvas && canUseNewCanvas) {
console.warn('开发者强制使用旧canvas,建议关闭');
}
if (isUseNewCanvas) {
// console.log('微信基础库版本大于2.9.0,开始使用<canvas type="2d"/>');
// 2.9.0 可以使用 <canvas type="2d"></canvas>
this.initByNewWay(callback);
} else {
const isValid = compareVersion(version, '1.9.91') >= 0
if (!isValid) {
console.error('微信基础库版本过低,需大于等于 1.9.91。'
+ '参见:https://github.com/ecomfe/echarts-for-weixin'
+ '#%E5%BE%AE%E4%BF%A1%E7%89%88%E6%9C%AC%E8%A6%81%E6%B1%82');
return;
} else {
console.warn('建议将微信基础库调整大于等于2.9.0版本。升级后绘图将有更好性能');
this.initByOldWay(callback);
}
}
},
initByOldWay(callback) {
// 1.9.91 <= version < 2.9.0:原来的方式初始化
ctx = wx.createCanvasContext(this.data.canvasId, this);
const canvas = new WxCanvas(ctx, this.data.canvasId, false);
echarts.setCanvasCreator(() => {
return canvas;
});
// const canvasDpr = wx.getSystemInfoSync().pixelRatio // 微信旧的canvas不能传入dpr
const canvasDpr = 1
var query = wx.createSelectorQuery().in(this);
query.select('.ec-canvas').boundingClientRect(res => {
if (typeof callback === 'function') {
this.chart = callback(canvas, res.width, res.height, canvasDpr);
}
else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
this.chart = this.data.ec.onInit(canvas, res.width, res.height, canvasDpr);
}
else {
this.triggerEvent('init', {
canvas: canvas,
width: res.width,
height: res.height,
canvasDpr: canvasDpr // 增加了dpr,可方便外面echarts.init
});
}
}).exec();
},
initByNewWay(callback) {
// version >= 2.9.0:使用新的方式初始化
const query = wx.createSelectorQuery().in(this)
query
.select('.ec-canvas')
.fields({ node: true, size: true })
.exec(res => {
const canvasNode = res[0].node
this.canvasNode = canvasNode
const canvasDpr = wx.getSystemInfoSync().pixelRatio
const canvasWidth = res[0].width
const canvasHeight = res[0].height
const ctx = canvasNode.getContext('2d')
const canvas = new WxCanvas(ctx, this.data.canvasId, true, canvasNode)
echarts.setCanvasCreator(() => {
return canvas
})
if (typeof callback === 'function') {
this.chart = callback(canvas, canvasWidth, canvasHeight, canvasDpr)
} else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
this.chart = this.data.ec.onInit(canvas, canvasWidth, canvasHeight, canvasDpr)
} else {
this.triggerEvent('init', {
canvas: canvas,
width: canvasWidth,
height: canvasHeight,
dpr: canvasDpr
})
}
})
},
canvasToTempFilePath(opt) {
if (this.data.isUseNewCanvas) {
// 新版
const query = wx.createSelectorQuery().in(this)
query
.select('.ec-canvas')
.fields({ node: true, size: true })
.exec(res => {
const canvasNode = res[0].node
opt.canvas = canvasNode
wx.canvasToTempFilePath(opt)
})
} else {
// 旧的
if (!opt.canvasId) {
opt.canvasId = this.data.canvasId;
}
ctx.draw(true, () => {
wx.canvasToTempFilePath(opt, this);
});
}
},
touchStart(e) {
if (this.chart && e.touches.length > 0) {
var touch = e.touches[0];
var handler = this.chart.getZr().handler;
handler.dispatch('mousedown', {
zrX: touch.x,
zrY: touch.y,
preventDefault: () => {},
stopImmediatePropagation: () => {},
stopPropagation: () => {}
});
handler.dispatch('mousemove', {
zrX: touch.x,
zrY: touch.y,
preventDefault: () => {},
stopImmediatePropagation: () => {},
stopPropagation: () => {}
});
handler.processGesture(wrapTouch(e), 'start');
}
},
touchMove(e) {
if (this.chart && e.touches.length > 0) {
var touch = e.touches[0];
var handler = this.chart.getZr().handler;
handler.dispatch('mousemove', {
zrX: touch.x,
zrY: touch.y,
preventDefault: () => {},
stopImmediatePropagation: () => {},
stopPropagation: () => {}
});
handler.processGesture(wrapTouch(e), 'change');
}
},
touchEnd(e) {
if (this.chart) {
const touch = e.changedTouches ? e.changedTouches[0] : {};
var handler = this.chart.getZr().handler;
handler.dispatch('mouseup', {
zrX: touch.x,
zrY: touch.y,
preventDefault: () => {},
stopImmediatePropagation: () => {},
stopPropagation: () => {}
});
handler.dispatch('click', {
zrX: touch.x,
zrY: touch.y,
preventDefault: () => {},
stopImmediatePropagation: () => {},
stopPropagation: () => {}
});
handler.processGesture(wrapTouch(e), 'end');
}
}
}
});
function wrapTouch(event) {
for (let i = 0; i < event.touches.length; ++i) {
const touch = event.touches[i];
touch.offsetX = touch.x;
touch.offsetY = touch.y;
}
return event;
}
<!-- 新的:接口对其了H5 -->
<canvas wx:if="{{isUseNewCanvas}}" type="2d" class="ec-canvas" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>
<!-- 旧的 -->
<canvas wx:else class="ec-canvas" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>
/* f2-canvas.wxss */ .ec-canvas {
.f2-canvas {
width: 100%; width: 100%;
height: 100%; height: 100%;
z-index:10;
} }
This diff could not be displayed because it is too large.
export default class WxCanvas {
constructor(ctx, canvasId, isNew, canvasNode) {
this.ctx = ctx;
this.canvasId = canvasId;
this.chart = null;
this.isNew = isNew
if (isNew) {
this.canvasNode = canvasNode;
}
else {
this._initStyle(ctx);
}
// this._initCanvas(zrender, ctx);
this._initEvent();
}
getContext(contextType) {
if (contextType === '2d') {
return this.ctx;
}
}
// canvasToTempFilePath(opt) {
// if (!opt.canvasId) {
// opt.canvasId = this.canvasId;
// }
// return wx.canvasToTempFilePath(opt, this);
// }
setChart(chart) {
this.chart = chart;
}
addEventListener() {
// noop
}
attachEvent() {
// noop
}
detachEvent() {
// noop
}
_initCanvas(zrender, ctx) {
zrender.util.getContext = function () {
return ctx;
};
zrender.util.$override('measureText', function (text, font) {
ctx.font = font || '12px sans-serif';
return ctx.measureText(text);
});
}
_initStyle(ctx) {
ctx.createRadialGradient = () => {
return ctx.createCircularGradient(arguments);
};
}
_initEvent() {
this.event = {};
const eventNames = [{
wxName: 'touchStart',
ecName: 'mousedown'
}, {
wxName: 'touchMove',
ecName: 'mousemove'
}, {
wxName: 'touchEnd',
ecName: 'mouseup'
}, {
wxName: 'touchEnd',
ecName: 'click'
}];
eventNames.forEach(name => {
this.event[name.wxName] = e => {
const touch = e.touches[0];
this.chart.getZr().handler.dispatch(name.ecName, {
zrX: name.wxName === 'tap' ? touch.clientX : touch.x,
zrY: name.wxName === 'tap' ? touch.clientY : touch.y,
preventDefault: () => {},
stopImmediatePropagation: () => {},
stopPropagation: () => {}
});
};
});
}
set width(w) {
if (this.canvasNode) this.canvasNode.width = w
}
set height(h) {
if (this.canvasNode) this.canvasNode.height = h
}
get width() {
if (this.canvasNode)
return this.canvasNode.width
return 0
}
get height() {
if (this.canvasNode)
return this.canvasNode.height
return 0
}
}
...@@ -4,151 +4,15 @@ ...@@ -4,151 +4,15 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@antv/adjust": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@antv/adjust/-/adjust-0.1.1.tgz",
"integrity": "sha512-9FaMOyBlM4AgoRL0b5o0VhEKAYkexBNUrxV8XmpHU/9NBPJONBOB/NZUlQDqxtLItrt91tCfbAuMQmF529UX2Q==",
"requires": {
"@antv/util": "~1.3.1"
},
"dependencies": {
"@antv/util": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@antv/util/-/util-1.3.1.tgz",
"integrity": "sha512-cbUta0hIJrKEaW3eKoGarz3Ita+9qUPF2YzTj8A6wds/nNiy20G26ztIWHU+5ThLc13B1n5Ik52LbaCaeg9enA==",
"requires": {
"@antv/gl-matrix": "^2.7.1"
}
}
}
},
"@antv/f2": {
"version": "3.7.8",
"resolved": "https://registry.npmjs.org/@antv/f2/-/f2-3.7.8.tgz",
"integrity": "sha512-ZPwgKd/ycQAQBhNoOn7+silxURYJVgtRv/q7f68X9++XRvitQPwtDnpUsR0gyLUbFO1XiFbhXtbRx8RzyZWFdg==",
"requires": {
"@antv/adjust": "~0.1.1",
"@antv/scale": "~0.3.3",
"@antv/util": "~2.0.6",
"@babel/runtime": "^7.7.7",
"@types/hammerjs": "^2.0.36",
"hammerjs": "^2.0.8",
"type-fest": "^0.15.1"
}
},
"@antv/f2-canvas": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@antv/f2-canvas/-/f2-canvas-1.0.5.tgz",
"integrity": "sha512-iE4u1kAcxGaluu1CA6F5R0/dfsCMhubEfOKvR6zRwGC9S9bCil0y6JNCsIkyPZGCQYkAtsg3WDlcu2yneyqUuw==",
"requires": {
"@antv/wx-f2": "^1.1.4"
},
"dependencies": {
"@antv/wx-f2": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/@antv/wx-f2/-/wx-f2-1.1.4.tgz",
"integrity": "sha512-XaMUwS16ONcpHIEK4yv6wOIxrwSqzhLx4di2kmumQI8xi5vZK1bslJCtjSaxbNS99febpZkZqgwgAmXOOrMYmA==",
"requires": {
"@antv/f2": "^3.3.3",
"wolfy87-eventemitter": "^5.2.4"
}
}
}
},
"@antv/f6-wx": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/@antv/f6-wx/-/f6-wx-0.0.7.tgz",
"integrity": "sha512-Q6GKLAWBUZ1H74PpUAPPq+laP+DtdTKnIIeq6FCufVyHOgSlJSf+Jm6aPdASok+oNJvgUDcFWvZS9qLqyV/2TA=="
},
"@antv/gl-matrix": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/@antv/gl-matrix/-/gl-matrix-2.7.1.tgz",
"integrity": "sha512-oOWcVNlpELIKi9x+Mm1Vwbz8pXfkbJKykoCIOJ/dNK79hSIANbpXJ5d3Rra9/wZqK6MC961B7sybFhPlLraT3Q=="
},
"@antv/scale": {
"version": "0.3.18",
"resolved": "https://registry.npmjs.org/@antv/scale/-/scale-0.3.18.tgz",
"integrity": "sha512-GHwE6Lo7S/Q5fgaLPaCsW+CH+3zl4aXpnN1skOiEY0Ue9/u+s2EySv6aDXYkAqs//i0uilMDD/0/4n8caX9U9w==",
"requires": {
"@antv/util": "~2.0.3",
"fecha": "~4.2.0",
"tslib": "^2.0.0"
}
},
"@antv/util": {
"version": "2.0.17",
"resolved": "https://registry.npmjs.org/@antv/util/-/util-2.0.17.tgz",
"integrity": "sha512-o6I9hi5CIUvLGDhth0RxNSFDRwXeywmt6ExR4+RmVAzIi48ps6HUy+svxOCayvrPBN37uE6TAc2KDofRo0nK9Q==",
"requires": {
"csstype": "^3.0.8",
"tslib": "^2.0.3"
}
},
"@antv/wx-f2": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@antv/wx-f2/-/wx-f2-2.1.1.tgz",
"integrity": "sha512-15S+Fz9NYFpZvXHaOM65lcNWEpsx7SmIyDDGMDZ0/beNW2T4DkxBdJwVLjE/SBIZc7kbQKJsC8n2p4HLbHcJYg==",
"requires": {
"@antv/f2": "~3.7.0"
}
},
"@babel/runtime": {
"version": "7.21.0",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz",
"integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==",
"requires": {
"regenerator-runtime": "^0.13.11"
}
},
"@types/hammerjs": {
"version": "2.0.41",
"resolved": "https://registry.npmjs.org/@types/hammerjs/-/hammerjs-2.0.41.tgz",
"integrity": "sha512-ewXv/ceBaJprikMcxCmWU1FKyMAQ2X7a9Gtmzw8fcg2kIePI1crERDM818W+XYrxqdBBOdlf2rm137bU+BltCA=="
},
"@vant/weapp": { "@vant/weapp": {
"version": "1.10.15", "version": "1.10.15",
"resolved": "https://registry.npmjs.org/@vant/weapp/-/weapp-1.10.15.tgz", "resolved": "https://registry.npmjs.org/@vant/weapp/-/weapp-1.10.15.tgz",
"integrity": "sha512-swM4k3pVwt/6Tnijvq86paLiKE1CzbrBQ4lR7+9uRhwKOM0HS3ooK1Q4IjSEyxQ59ZFKmYYvZln77RZcnSDqmA==" "integrity": "sha512-swM4k3pVwt/6Tnijvq86paLiKE1CzbrBQ4lR7+9uRhwKOM0HS3ooK1Q4IjSEyxQ59ZFKmYYvZln77RZcnSDqmA=="
}, },
"csstype": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.2.tgz",
"integrity": "sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ=="
},
"fecha": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz",
"integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw=="
},
"glsx-applet-component": { "glsx-applet-component": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/glsx-applet-component/-/glsx-applet-component-1.1.3.tgz", "resolved": "https://registry.npmjs.org/glsx-applet-component/-/glsx-applet-component-1.1.3.tgz",
"integrity": "sha512-Ze+HdtFJImhOsWLfV+ZzB86Kf18pm9M9CZWhctPel/qJNMEn29g9ywC16NXmeac+gTu07MOpURyF+YmO8ojkJA==" "integrity": "sha512-Ze+HdtFJImhOsWLfV+ZzB86Kf18pm9M9CZWhctPel/qJNMEn29g9ywC16NXmeac+gTu07MOpURyF+YmO8ojkJA=="
},
"hammerjs": {
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/hammerjs/-/hammerjs-2.0.8.tgz",
"integrity": "sha512-tSQXBXS/MWQOn/RKckawJ61vvsDpCom87JgxiYdGwHdOa0ht0vzUWDlfioofFCRU0L+6NGDt6XzbgoJvZkMeRQ=="
},
"regenerator-runtime": {
"version": "0.13.11",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
"integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg=="
},
"tslib": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
"integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg=="
},
"type-fest": {
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.15.1.tgz",
"integrity": "sha512-n+UXrN8i5ioo7kqT/nF8xsEzLaqFra7k32SEsSPwvXVGyAcRgV/FUQN/sgfptJTR1oRmmq7z4IXMFSM7im7C9A=="
},
"wolfy87-eventemitter": {
"version": "5.2.9",
"resolved": "https://registry.npmjs.org/wolfy87-eventemitter/-/wolfy87-eventemitter-5.2.9.tgz",
"integrity": "sha512-P+6vtWyuDw+MB01X7UeF8TaHBvbCovf4HPEMF/SV7BdDc1SMTiBy13SRD71lQh4ExFTG1d/WNzDGDCyOKSMblw=="
} }
} }
} }
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
"description": "", "description": "",
"main": "app.js", "main": "app.js",
"dependencies": { "dependencies": {
"@antv/f2-canvas": "^1.0.5",
"@antv/f6-wx": "0.0.7",
"@antv/wx-f2": "^2.1.1",
"@vant/weapp": "^1.10.7", "@vant/weapp": "^1.10.7",
"glsx-applet-component": "^1.1.3" "glsx-applet-component": "^1.1.3"
}, },
......
...@@ -14,13 +14,22 @@ Component({ ...@@ -14,13 +14,22 @@ Component({
* 组件的初始数据 * 组件的初始数据
*/ */
data: { data: {
tabIndex: 0 dataType: 3,
}, },
/** /**
* 组件的方法列表 * 组件的方法列表
*/ */
methods: { methods: {
selectCondition(e) {
let {
condition,
type
} = e.currentTarget.dataset
this.setData({
[condition]: type
})
this.triggerEvent('selectEvent')
},
} }
}) })
\ No newline at end of file \ No newline at end of file
.bar-wrap { .bar-wrap {
width: 710rpx;
height: 516rpx;
background: #FFFFFF;
box-shadow: 0 2rpx 20rpx 0 #b4bacc52;
border-radius: 20rpx;
margin: 0 auto;
padding: 34rpx 30rpx 30rpx 40rpx; padding: 34rpx 30rpx 30rpx 40rpx;
box-sizing: border-box; box-sizing: border-box;
.searchList { .searchList {
height: 104rpx;
display: flex; display: flex;
align-items: center; align-items: center;
......
<view class="bar-wrap"> <view class="bar-wrap">
<view class="searchList"> <view class="searchList">
<block wx:for="{{opts.tabList}}"> <block wx:for="{{opts.barList}}" wx:for-item="item">
<view class="search-text {{tabIndex==index?'active':''}}">{{item}}</view></block> <view class="search-text {{dataType==item.type?'active':''}}" data-condition="dataType" data-type="{{item.type}}" bindtap="selectCondition">{{item.title}}</view></block>
</view> </view>
<view class="container" style="height: 200px;"> <view class="container" style="height: 200px;">
<bar-echart class="f2-chart" chartData="{{opts.chartData}}" color="{{opts.color}}" tickCount="{{opts.tickCount}}" /> <bar-echart class="f2-chart" keys="{{opts.keys}}" chartData="{{opts.chartData}}" color="{{opts.color}}" tickCount="{{opts.tickCount}}" />
</view> </view>
</view> </view>
\ No newline at end of file \ No newline at end of file
...@@ -42,27 +42,18 @@ Component({ ...@@ -42,27 +42,18 @@ Component({
type type
} = e.currentTarget.dataset } = e.currentTarget.dataset
this.setData({ this.setData({
[condition]: type [condition]: type,
startTime: '',
endTime:''
}) })
if(condition == 'dataType') this.setData({timePeriod:1})
this.triggerEvent('selectEvent') this.triggerEvent('selectEvent')
}, },
selectTime() { selectTime() {
this.setData({ console.log(122)
isShow: true this.triggerEvent('selectTime')
})
},
onConfirm(event) {
const [start, end] = event.detail;
this.setData({
isShow: false,
startTime: this.formatDate(start),
endTime: this.formatDate(end)
});
},
formatDate(date) {
date = new Date(date);
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
}, },
} }
}) })
\ No newline at end of file \ No newline at end of file
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
border: 2rpx solid #EBEBEB; border: 2rpx solid #EBEBEB;
border-radius: 32rpx; border-radius: 32rpx;
font-weight: 400; font-weight: 400;
font-size: 20rpx; font-size: 24rpx;
color: #A6A6A6; color: #A6A6A6;
} }
...@@ -54,20 +54,19 @@ ...@@ -54,20 +54,19 @@
position: absolute; position: absolute;
right:30rpx; right:30rpx;
.time-icon { .time-icon {
width: 25.6rpx; width: 28rpx;
height: 24.6rpx; height: 26rpx;
} }
.temporal { .temporal {
font-size: 24rpx; font-size: 26rpx;
color: #A6A6A6; color: #A6A6A6;
margin: 0 8rpx; margin: 0 8rpx;
} }
.arrows { .arrows {
font-size: 26rpx; width: 20rpx;
color: #A6A6A6; height: 12rpx;
transform: rotate(90deg);
} }
} }
} }
......
<view class="bar-wrap"> <view class="bar-wrap">
<view class="searchList"> <view class="searchList">
<block wx:for="{{opts.tabList}}" wx:for-item="item"> <block wx:for="{{opts.lineList}}" wx:for-item="item">
<view class="search-text {{dataType==item.type?'active':''}}" data-condition="dataType" data-type="{{item.type}}" bindtap="selectCondition">{{item.title}}</view></block> <view class="search-text {{dataType==item.type?'active':''}}" data-condition="dataType" data-type="{{item.type}}" bindtap="selectCondition">{{item.title}}</view></block>
</view> </view>
<view class="searchTime"> <view class="searchTime">
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
<view class="flex" bindtap="selectTime"> <view class="flex" bindtap="selectTime">
<glsx-image class="time-icon" src="store-assistant-assemble/output/output-time.png"></glsx-image> <glsx-image class="time-icon" src="store-assistant-assemble/output/output-time.png"></glsx-image>
<view class="temporal" >{{startTime?startTime+'-'+endTime:'自定义'}}</view> <view class="temporal" >{{startTime?startTime+'-'+endTime:'自定义'}}</view>
<view class="arrows">></view> <glsx-image class="arrows" src="store-assistant-assemble/output/arrow.png"></glsx-image>
</view> </view>
</view> </view>
<view class="container" style="height: 180px;"> <view class="container" style="height: 180px;">
<line-echart class="f2-chart" chartData="{{opts.lineData}}" color="{{opts.lineColr}}" tickCount="{{opts.tickCount}}" keys="{{opts.keys}}"/> <line-echart class="f2-chart" period="{{timePeriod}}" chartData="{{opts.lineData}}" color="{{opts.lineColr}}" tickCount="{{opts.tickCount}}" keys="{{opts.keys}}"/>
</view> </view>
<van-calendar show="{{ isShow }}" type="range" color="#4466F0" bind:confirm="onConfirm"/>
</view> </view>
\ No newline at end of file \ No newline at end of file
import ActivityApi from '~/api/activityApi/index' import ActivityApi from '~/api/activityApi/index'
let thisPage; let thisPage;
Component({ Component({
options: {
styleIsolation: 'shared'
},
/** /**
* 组件的属性列表 * 组件的属性列表
*/ */
...@@ -111,52 +114,130 @@ Component({ ...@@ -111,52 +114,130 @@ Component({
total: 0, total: 0,
pageSize: 10, pageSize: 10,
noResult: false, noResult: false,
isShow: false,
opts: { opts: {
keys: ['abscissaValue', 'ordinateValue'], keys: ['abscissaValue', 'ordinateValue'],
color: '#69C9FF', color: '#69C9FF',
lineColr: '#6ED0BE', lineColr: '#6ED0BE',
tickCount: 8, tickCount: 8,
tabList: [{ lineList: [{
title: '营业额', title: '营业额',
type: 1 type: 1
}, { }, {
title: '到店量', title: '到店量',
type: 2 type: 2
}], }],
barList: [{
title: '发券量',
type: 3
}, {
title: '营业额',
type: 1
}],
chartData: [{ chartData: [{
year: '1951 年', "abscissaValue": "昨日",
sales: 10000 "ordinateValue": 100
}, }, {
{ "abscissaValue": "今日",
year: '1952 年', "ordinateValue": 34
sales: 2000 }, {
}, "abscissaValue": "上月",
{ "ordinateValue": 67
year: '1956 年', }, {
sales: 61 "abscissaValue": "当月",
}, "ordinateValue": 90
{ }],
year: '1957 年', lineData: [{
sales: 145 "abscissaValue": "2023-03-23",
}, "ordinateValue": 12
{ }, {
year: '1958 年', "abscissaValue": "2023-03-24",
sales: 48 "ordinateValue": 45
}, }, {
{ "abscissaValue": "2023-03-25",
year: '1959 年', "ordinateValue": 78
sales: 38 }, {
}, "abscissaValue": "2023-03-26",
{ "ordinateValue": 3
year: '1960 年', }, {
sales: 38 "abscissaValue": "2023-03-27",
}, "ordinateValue": 56
{ }, {
year: '1962 年', "abscissaValue": "2023-03-28",
sales: 38 "ordinateValue": 34
}, }, {
], "abscissaValue": "2023-03-29",
lineData: [] "ordinateValue": 78
}, {
"abscissaValue": "2023-03-30",
"ordinateValue": 54
}, {
"abscissaValue": "2023-03-31",
"ordinateValue": 20
}, {
"abscissaValue": "2023-04-01",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-02",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-03",
"ordinateValue": 100
}, {
"abscissaValue": "2023-04-04",
"ordinateValue": 78
}, {
"abscissaValue": "2023-04-05",
"ordinateValue": 56
}, {
"abscissaValue": "2023-04-06",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-07",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-08",
"ordinateValue": 38
}, {
"abscissaValue": "2023-04-09",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-10",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-11",
"ordinateValue": 76
}, {
"abscissaValue": "2023-04-12",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-13",
"ordinateValue": 12
}, {
"abscissaValue": "2023-04-14",
"ordinateValue": 3
}, {
"abscissaValue": "2023-04-15",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-16",
"ordinateValue": 43
}, {
"abscissaValue": "2023-04-17",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-18",
"ordinateValue": 16
}, {
"abscissaValue": "2023-04-19",
"ordinateValue": 0
}, {
"abscissaValue": "2023-04-20",
"ordinateValue": 23
}, {
"abscissaValue": "2023-04-21",
"ordinateValue": 0
}]
}, },
}, },
...@@ -211,25 +292,63 @@ Component({ ...@@ -211,25 +292,63 @@ Component({
selectEvent() { selectEvent() {
this.getTrend() this.getTrend()
}, },
selectBarEvent() {
this.getHistogram()
},
selectTime() {
this.setData({
isShow: true
})
},
onClose(){
this.setData({
isShow: false
});
},
onConfirm(event) {
const [start, end] = event.detail;
const lineObj = this.selectComponent('#line')
this.setData({
isShow: false
});
lineObj.setData({
startTime: this.formatDate(start),
endTime: this.formatDate(end),
timePeriod: ''
})
this.getTrend()
},
formatDate(date) {
date = new Date(date);
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
},
/**柱状图 */ /**柱状图 */
getHistogram() { getHistogram() {
const barObj = this.selectComponent('#bar')
let {
dataType
} = barObj.data
const params = { const params = {
merchantId: thisPage.data.merchantId, merchantId: 44211765,
dataType: 1, //数据类型:1报价量/ 2成交量 /3产值 dataType, //数据类型:1报价量/ 2成交量 /3产值
timePeriod: 1, //时间类型 1本周 / 2本月 /3全年
startTime: '',
endTime: ''
} }
ActivityApi.merchantsHistogram(params).then(res => { ActivityApi.boutiquecouponQueryCouponCountAndOrderMoney(params).then(res => {
console.log(res) this.setData({
'opts.chartData': res
})
}) })
}, },
/**折线图 */ /**折线图 */
getTrend() { getTrend() {
const lineObj = this.selectComponent('#line') const lineObj = this.selectComponent('#line')
let { dataType, timePeriod, startTime, endTime } = lineObj.data let {
dataType,
timePeriod,
startTime,
endTime
} = lineObj.data
const params = { const params = {
merchantId: thisPage.data.merchantId, merchantId: 44211765,
dataType, //数据类型:1报价量/ 2成交量 /3产值 dataType, //数据类型:1报价量/ 2成交量 /3产值
dateDimension: timePeriod, //时间类型 1本周 / 2本月 /3全年 dateDimension: timePeriod, //时间类型 1本周 / 2本月 /3全年
startDate: startTime, startDate: startTime,
...@@ -239,7 +358,6 @@ Component({ ...@@ -239,7 +358,6 @@ Component({
this.setData({ this.setData({
'opts.lineData': res 'opts.lineData': res
}) })
console.log(this.data.opts.lineData)
}) })
}, },
getOutputReport() { getOutputReport() {
...@@ -254,7 +372,9 @@ Component({ ...@@ -254,7 +372,9 @@ Component({
const dataT = { const dataT = {
1: () => { 1: () => {
apiName = 'boutiquecouponQueryEmployeeRankList', apiName = 'boutiquecouponQueryEmployeeRankList',
params = { merchantId: thisPage.data.merchantId }, params = {
merchantId: thisPage.data.merchantId
},
tabelTh = { tabelTh = {
employeeName: '员工姓名', employeeName: '员工姓名',
orderMoneyTotal: '产值(营业额)', orderMoneyTotal: '产值(营业额)',
...@@ -265,7 +385,9 @@ Component({ ...@@ -265,7 +385,9 @@ Component({
}, },
2: () => { 2: () => {
apiName = 'merchantsStaffOutput', apiName = 'merchantsStaffOutput',
params = { merchantIds: [thisPage.data.merchantId] } params = {
merchantIds: [thisPage.data.merchantId]
}
tabelTh = { tabelTh = {
transferName: "员工姓名", transferName: "员工姓名",
outputValue: "产值", outputValue: "产值",
...@@ -279,7 +401,10 @@ Component({ ...@@ -279,7 +401,10 @@ Component({
dataT[type]() dataT[type]()
ActivityApi[apiName](params).then(res => { ActivityApi[apiName](params).then(res => {
const sfaffList = res.list || res || [] const sfaffList = res.list || res || []
this.setData({ sfaffList ,tabelTh}) this.setData({
sfaffList,
tabelTh
})
}) })
}, },
formatArr(arr, fn) { formatArr(arr, fn) {
......
...@@ -93,3 +93,6 @@ ...@@ -93,3 +93,6 @@
} }
} }
} }
.van-calendar{
z-index:9999;
}
\ No newline at end of file \ No newline at end of file
<scroll-view scroll-y class="content" class="content" refresher-triggered="{{triggered}}" refresher-enabled bindrefresherrefresh="activityRefresh" style="{{'height: calc(100% - 22rpx);'}}"> <scroll-view scroll-y class="content" class="content" refresher-triggered="{{triggered}}" refresher-enabled bindrefresherrefresh="activityRefresh" bindscroll="scrollIng" style="{{'height: calc(100% - 22rpx);'}}">
<view class="output-box"> <view class="output-box">
<view class="output-title">产值总览</view> <view class="output-title">产值总览</view>
<view class="output-value"> <view class="output-value">
...@@ -16,14 +16,18 @@ ...@@ -16,14 +16,18 @@
</view> </view>
</view> </view>
<view class="line-box"> <view class="line-box">
<output-line id="line" opts="{{opts}}" bind:selectEvent="selectEvent"></output-line> <output-line id="line" opts="{{opts}}" bind:selectTime="selectTime" bind:selectEvent="selectEvent"></output-line>
</view> </view>
<view class="bar-box"> <view class="bar-box">
<output-bar opts="{{opts}}"></output-bar> <output-bar opts="{{opts}}" id="bar" bind:selectEvent="selectBarEvent"></output-bar>
</view>
<view class="staf-box">
555
</view> </view>
<staff sfaffList="{{sfaffList}}" tabelTh="{{tabelTh}}" downType="{{type ==2?'equity':'boutique'}}"/>
<view class="table-box"> <view class="table-box">
<view class="btn-box day-btn" bindtap="jumpReport" data-time="day">查看日报表</view> <view class="btn-box day-btn" bindtap="jumpReport" data-time="day">查看日报表</view>
<view class="btn-box month-btn" bindtap="jumpReport" data-time="month">查看月报表</view> <view class="btn-box month-btn" bindtap="jumpReport" data-time="month">查看月报表</view>
</view> </view>
</scroll-view>
\ No newline at end of file \ No newline at end of file
</scroll-view >
<van-calendar show="{{ isShow }}" type="range" color="#4466F0" bind:confirm="onConfirm" bind:close="onClose"/>
\ No newline at end of file \ No newline at end of file
// packageOutput/components/echart/echart.js import * as echarts from '../../../../ec-canvas/echarts';
import F2 from '../../../../common/lib/f2'
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -24,18 +24,27 @@ Component({ ...@@ -24,18 +24,27 @@ Component({
}, },
observers: { observers: {
'chartData': function (data) { 'chartData': function (data) {
if (data.length == 0) {
this.setData({ this.setData({
optsBar: { chartShow: true,
ec: {
onInit: this.onInitChart() //这里就是在js中用到的方法名 onInit: this.onInitChart() //这里就是在js中用到的方法名
} }
}) })
} else {
// this.data.chart.changeData(data)
}
}, },
}, },
/** /**
* 组件的初始数据 * 组件的初始数据
*/ */
data: { data: {
optsBar: {}, ec: {
onInit: null
}
}, },
/** /**
...@@ -43,59 +52,95 @@ Component({ ...@@ -43,59 +52,95 @@ Component({
*/ */
methods: { methods: {
onInitChart() { onInitChart() {
return (canvas, width, height) => { return (canvas, width, height, dpr) => {
const chart = new F2.Chart({ const chart = echarts.init(canvas, null, {
el: canvas, width: width,
width, height: height,
height, devicePixelRatio: dpr, // new
padding: ['auto', 'auto', 'auto', '40'], padding:[10, 20,10,20]
animate: true,
}); });
const data = this.data.chartData; canvas.setChart(chart);
const [a, b] = this.data.keys
chart.source(data, { var option = {
[b]: { grid: {
tickCount: this.data.tickCount left: 8,
right: 10,
top: 50,
bottom: 0,
containLabel: true
},
tooltip: {
trigger: 'axis',
triggerOn: "mousemove",
axisPointer: {
lineStyle: {
type: 'solid'
} }
}); },
chart.tooltip({ padding: [2, 10],
showItemMarker: false, borderWidth: 2,
background: { borderColor: this.data.color,
radius: 10, borderRadius: 10,
fill: '#fff', textStyle: {
stroke: "#69C9FF", color: this.data.color,
lineWidth: 2, fontSize: 10
padding: [5, 10] },
}, // position: function(pt) {
valueStyle: { // console.log(pt)
fill: '#69C9FF', // return [pt[0], pt[1]+20];
size: 12 // },
}, formatter: function (item) {
tooltipMarkerStyle: { console.log(item)
fill: '#1890FF', return `${item[0].value}` + '人'
fillOpacity: 0.1
},
onShow: function onShow(ev) {
const items = ev.items;
items[0].name = null
items[0].value = items[0].value + '张';
} }
}); },
chart.axis(a, { xAxis: {
label: { type: 'category',
fill: '#A6A6A6' axisLabel: {
fontSize: 11,
color: '#A6A6A6'
},
axisLine: {
show: false //坐标轴线线
},
axisTick: {
show: false //坐标轴刻度
},
data: ['Mon', 'Tue', 'Wed', 'Thu']
},
yAxis: {
x: 'center',
type: 'value',
axisLabel: {
fontSize: 11,
color: '#A6A6A6'
},
axisLine: {
show: false //坐标轴线线
},
axisTick: {
show: false //坐标轴刻度
},
splitLine: {
lineStyle: {
type: 'dashed'
} }
});
chart.axis(b, {
label: {
fill: '#A6A6A6'
} }
}); },
chart.interval().position(`${a}*${b}`).color(this.data.color).size(12).style({ series: [{
radius: [6, 6, 0, 0] data: [820, 932, 901, 934],
}); type: 'bar',
chart.render(); color: this.data.color,
return chart itemStyle: {
borderRadius: [50, 50, 0, 0],
padding:[50, 50, 0, 0]
},
barWidth: 24
}]
};
chart.setOption(option);
return chart;
} }
}, },
......
{ {
"component": true, "component": true,
"usingComponents": { "usingComponents": {
"ff-canvas": "../../../../common/f2-canvas" "ec-canvas": "../../../../ec-canvas/ec-canvas"
} }
} }
<!--packageOutput/components/echart/echart.wxml-->
<ff-canvas opts="{{ optsBar }}" data="{{chartData}}" /> <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>
import F2 from '../../../../common/lib/f2' import * as echarts from '../../../../ec-canvas/echarts';
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -23,15 +23,16 @@ Component({ ...@@ -23,15 +23,16 @@ Component({
}, },
observers: { observers: {
'chartData': function (data) { 'chartData': function (data) {
this.initData(data)
if (data.length == 0) { if (data.length == 0) {
this.setData({ this.setData({
chartShow: true, chartShow: true,
opts: { ec: {
onInit: this.onInitChart() //这里就是在js中用到的方法名 onInit: this.onInitChart()
} }
}) })
} else { } else {
this.data.chart.changeData(data) // this.data.chart.changeData(data)
} }
...@@ -41,9 +42,11 @@ Component({ ...@@ -41,9 +42,11 @@ Component({
* 组件的初始数据 * 组件的初始数据
*/ */
data: { data: {
initEchart: null, ec: {
chart: null, onInit: null
opts: {}, // 资金占比饼状图 },
xData:[],
yData:[]
}, },
...@@ -52,111 +55,112 @@ Component({ ...@@ -52,111 +55,112 @@ Component({
*/ */
methods: { methods: {
onInitChart() { onInitChart() {
return (canvas, width, height) => { return (canvas, width, height, dpr) => {
this.data.chart = new F2.Chart({ console.log(width, height, )
el: canvas, const chart = echarts.init(canvas, null, {
width, width: width,
height, height: height,
padding: ['auto', 'auto', 'auto', '40'], devicePixelRatio: dpr // new
animate: true,
}); });
const data = this.data.chartData; canvas.setChart(chart);
const [a, b] = this.data.keys
console.log(a, b) var option = {
let tickIntervalNum = 0 grid: {
// 判断lineData是否有值,根据barList中最大值计算tickInterval left: 8,
if (data.length) { right: 10,
let s = data[0].value top: 50,
for (var i = 1; i < data.length; i++) { bottom: 0,
if (s < data[i].value) { containLabel: true
s = data[i].value },
} tooltip: {
} trigger: 'axis',
tickIntervalNum = s triggerOn: "mousemove",
} axisPointer: {
this.data.chart.source(data, { lineStyle: {
[a]: { type: 'solid'
// type: 'timeCat',
// mask: 'MM/DD',
// range: [0, 1]
// 滚动条包含几个
min: 3,
max: 1000,
// tickCount: 4,
// 传入不同的sort转换对应的名字
// formatter: function(val) {
// return name_list[val]
// }
},
[b]: {
type: 'linear',
nice: true,
// tickCount: 4,
// tickInterval: Math.ceil(tickIntervalNum / 3)
}
})
this.data.chart.tooltip({
showItemMarker: false,
background: {
radius: 10,
fill: '#fff',
stroke: "#69C9FF",
lineWidth: 2,
padding: [5, 10]
},
valueStyle: {
fill: '#69C9FF',
size: 12
},
onShow: function onShow(ev) {
const items = ev.items;
items[0].name = null
items[0].value = items[0].value + '人';
} }
}); },
this.data.chart.axis(a, { padding: [2, 10],
label: { borderWidth: 2,
fill: '#A6A6A6' borderColor: '#6ED0BE',
borderRadius: 10,
textStyle: {
color: '#6ED0BE',
fontSize: 10
},
// position: function(pt) {
// console.log(pt)
// return [pt[0], pt[1]+20];
// },
formatter: function (item) {
console.log(item)
return `${item[0].value}` + '人'
} }
}); },
this.data.chart.axis(b, { xAxis: {
label: { type: 'category',
fill: '#A6A6A6' boundaryGap: false,
axisLabel: {
fontSize: 11,
color: '#A6A6A6'
},
axisLine: {
show: false //坐标轴线线
},
axisTick: {
show: false //坐标轴刻度
},
data:this.data.xData
},
yAxis: {
x: 'center',
type: 'value',
axisLabel: {
fontSize: 11,
color: '#A6A6A6'
},
axisLine: {
show: false //坐标轴线线
},
axisTick: {
show: false //坐标轴刻度
},
splitLine: {
lineStyle: {
type: 'dashed'
} }
});
this.data.chart.line().position(`${a}*${b}`).shape('smooth').color(this.data.color).style({
lineWidth: 2
});
this.data.chart.legend(false)
this.data.chart.interaction('pan');
// // 定义进度条
this.data.chart.scrollBar({
mode: 'x',
xStyle: {
offsetY: 0
} }
}); },
dataZoom: {
start: 10,
type: "inside"
},
series: [{
data: this.data.yData,
type: 'line',
smooth: true,
color: this.data.color
}]
};
this.data.chart.render(); chart.setOption(option);
return this.data.chart return chart;
} }
}, },
//初始化数据 //初始化数据
initData() { initData(data) {
let { let {
chartData, xData,
keys, yData
viewData } = this.data
} = this data.forEach(item => {
chartData.forEach(item => { xData.push(item.abscissaValue)
viewData.push({ yData.push(item.ordinateValue)
name: item[keys[0]],
value: item[keys[1]]
}) })
this.setData({
xData,
yData
}) })
}, },
} }
......
{ {
"component": true, "component": true,
"usingComponents": { "usingComponents": {
"ff-canvas": "../../../../common/f2-canvas" "ec-canvas": "../../../../ec-canvas/ec-canvas"
} }
} }
.line-container { ec-canvas {
position: relative;
}
.f2-chart {
width: 100%;
height: 500rpx;
}
#pieSelect {
width: 600rpx;
height: 500rpx;
}
.line-tooltip {
opacity: 0;
position: absolute;
width: 140rpx;
height: 70rpx;
border-radius: 6rpx;
box-shadow: 0rpx 2rpx 5rpx 0rpx rgba(0, 0, 0, 0.05);
background: #ffffff;
z-index: 99;
flex-direction: column;
font-size: 16rpx;
box-sizing: border-box;
padding: 10rpx;
left: 0;
top: 0;
.time {
color: #a9a9a9;
}
.item,
.time {
width: 100%; width: 100%;
text-align: left; height: 100%;
font-size: 16rpx;
}
.arc {
border-radius: 100%;
font-size: 5rpx;
margin-right: 4rpx;
}
} }
\ No newline at end of file \ No newline at end of file
<!--packageOutput/components/line/line.wxml--> <!--packageOutput/components/line/line.wxml-->
<ff-canvas opts="{{ opts }}" data="{{chartData}}" /> <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec="{{ ec }}"></ec-canvas>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!