huang-xiao-jian / echarts-ng Goto Github PK
View Code? Open in Web Editor NEWangularjs decoration for Baidu echarts.
License: MIT License
angularjs decoration for Baidu echarts.
License: MIT License
非初始化状态,实例进入loading,重新绘制后,会出现调色板恢复默认状态。
以前的最低支持ng1.3的没有了吗
大致定位了一下,代码默认option下面是series,不存在BaseOption和Options这种嵌套。
echarts-ng.js里第666行代码,echarts的指令配置部分,您的实现是:
function echartsDirective($echarts, $dimension) {
return {
priority: 5,
restrict: "A",
scope: {
echarts: "=",
echartsDimension: "=",
config: "="
},
bindToController: true,
controller: ["$scope", "$element", function ($scope, $element) {
var vm = this; //这里
var OPTION = $echarts.getEchartsGlobalOption()
, identity = vm.echarts
, element = $element[0];
if (!identity) {
throw new Error("Echarts Instance Identity Required");
}
/**
* @type number
*
* @description - 初始化高度设定,避免echarts绘制失败
*/
$dimension.shouldAdaptDimension(element, vm.echartsDimension) && $dimension.adaptEchartsDimension(element, vm.echartsDimension);
/**
* @type object
*
* @description - echarts 实例对象
*/
var instance;
instance = echarts.init(element, OPTION.theme);
instance.setOption(OPTION);
// 调色板增强
$echarts.driftEchartsPalette(instance, OPTION.driftPalette);
// 注册当前实例对象
$echarts.registerEchartsInstance(identity, instance);
// 绘制实例对象
$echarts.updateEchartsInstance(identity, vm.config);
$scope.$watchCollection("chart.config.title", function (current, prev) {
if (!angular.equals(current, prev)) {
$echarts.updateEchartsInstance(identity, vm.config);
}
});
$scope.$watchCollection("chart.config.series", function (current, prev) {
if (!angular.equals(current, prev)) {
$echarts.updateEchartsInstance(identity, vm.config);
}
});
$scope.$on("$destroy", function () {
instance.clear();
instance.dispose();
$echarts.removeEchartsInstance(identity);
$dimension.removeEchartsDimension(element);
});
}],
controllerAs: "chart"
};
}
里面的var vm = this;这行指定了vm,
后面调用了vm的echarts属性,然而$scope和this并不相等。$scope.echarts存在,this.echarts即vm.echarts并不存在,故得到undefined,导致_Echarts Instance Identity Required_错误,修改为$scope后正常使用
麻烦确认一下原因
已更新问题 @BornKiller
我用0.3.13版本
报错:
Uncaught ReferenceError: echarts is not defined at echarts-ng.js:634
你知道有angularjs2和echarts3的库吗?
Hello,
I would like to change the theme with one from the original echarts site (the blue one).
How can I do it?
Thanks
发现通过angular.module('application', ['echarts-ng']);引用echarts-ng后,会导致手机浏览器无法正常加载页面,桌面端倒是没问题,而其它angular插件没有出现这种情况。请问这是怎么回事?
怎样实现外部容器resize后,echart自适应?echarts-ng.js里面有如instance.resize(),应该是实现重画图的,怎样在外部controller使用?请指点,谢谢!
@BornKiller
个人项目中使用echarts-ng
,彼时没有基于echarts3
的封装,但使用过程中,感觉不够顺畅,重构早有打算,但始终无法付诸实践。后续接触ES6
, rollup
, webpack
等新东西,于是元旦三天进行较大的重构,意图修复之前存在的问题。
resize
调用方式诡异: #3Angular2
: #4theme
不够灵活: #5实现Angular2
迁移简单化,需要关键实现做到框架无关,剔除框架特异性考量。
watch
echarts instance
@bornkiller/echarts-bridge
(https://github.com/bornkiller/echarts-ng) 作为中间层,方便迁移创建包装实例,作为echarts
实际接口与控制器内部调用的中间层。包装实例在DOM连接
之后,完全为echarts instance
,在连接之前,使用monkey patch
实现部分方法,几乎全部支持链式调用。
monkey patch
实现(连接之前即可使用):
group
分组属性showLoading
, hideLoading
clear
dispose
(不支持链式调用,因为实例已销毁)resize
on
off
实例工具类函数基本不会再连接之前调用,进行延迟挂载即可:
getWidth
getHeight
getDom
getOption
getDataURL
getConnectedDataURL
isDisposed
dispatchAction
convertToPixel
convertToPixel
containPixel
目前仅提供临时开发样例,后续会通过其他方式,大概理解新版本使用方式即可。
/**
* @description - develop helper for showcase
* @author - bornkiller <[email protected]>
*/
(function (angular) {
'use strict';
angular.module('echarts-showcase', ['echarts-ng'])
.controller('ShowcaseController', ['$echarts', '$timeout', function ($echarts, $timeout) {
this.themes = ['vintage', 'dark', 'macarons', 'infographic', 'shine', 'roma'];
this.theme = 'vintage';
this.show = true;
this.mediaOptions = [
{
option: {
legend: {
orient: 'horizontal',
left: 'center',
top: 'top'
},
grid: {
right: '10%'
}
}
},
{
query: {
maxWidth: 850
},
option: {
legend: {
orient: 'vertical',
right: 10,
top: '10%'
},
grid: {
right: '15%'
}
}
}
];
this.options = {
tooltip: {
trigger: 'axis'
},
legend: {
data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
},
xAxis: [
{
type: 'category',
boundaryGap: false,
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
name: '邮件营销',
type: 'line',
stack: '总量',
areaStyle: { normal: {} },
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '联盟广告',
type: 'line',
stack: '总量',
areaStyle: { normal: {} },
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: '视频广告',
type: 'line',
stack: '总量',
areaStyle: { normal: {} },
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: '直接访问',
type: 'line',
stack: '总量',
areaStyle: { normal: {} },
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: '搜索引擎',
type: 'line',
stack: '总量',
areaStyle: { normal: {} },
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
this.legends = [
{ description: '邮件营销', selected: true },
{ description: '联盟广告', selected: true },
{ description: '视频广告', selected: true },
{ description: '直接访问', selected: true },
{ description: '搜索引擎', selected: true }
];
this.instance = $echarts.create(this.theme, {}, this.mediaOptions);
this.instance
.showLoading()
.on('click', (event) => {
console.log(event);
})
.on('legendselectchanged', (event) => {
console.log(event);
});
$timeout(() => {
this.instance.setOption(this.options).hideLoading();
}, 1200);
this.handleThemeChange = () => {
this.instance = $echarts.create(this.theme).setOption(this.options);
};
this.handleLegendChange = (name, selected) => {
this.instance.dispatchAction({
type: selected ? 'legendSelect' : 'legendUnSelect',
name: name
})
};
this.toggleSwitchStatus = () => {
this.show = !this.show;
};
this.sync = _.debounce(() => {
this.instance.resize();
}, 100);
window.addEventListener('resize', this.sync);
}]);
angular.bootstrap(document.body, ['echarts-showcase'], { strictDi: true });
})(angular);
录屏地址:https://www.opentest.co/share/56a9c8b0d0be11e688ecd510bcea4514
ng-if
等指令,重连接之前,所有操作全部丢失,所以重连接后方可进一步操作,暨ng-if=true
条件先于后续操作;DOM
尺寸,可以连接后直接调用echarts#resize
方法;A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.