如何在Sencha Extjs中使用canvasjs库



我可以看到有一些插件可以用于d3图表和highcharts,以便在Sencha ExtJS中使用。但是我找不到canvasjs的Any。有没有一种方法可以将CanvasJS与Sencha Ext JS集成。

CanvasJS只需要一个div就可以将它们的内容呈现到。

一个超级简单的方法可能是这样的:

Ext.create('Ext.Component', {
layout: 'fit',
width: 500,
height: 500,
renderTo: Ext.getBody(),
border: 1,
style: {
backgroundColor: '#EEEEEE',
borderStyle: 'solid',
borderWidth: '1px'
},
listeners: {
afterrender: function (cmp) {
Ext.Loader.loadScript({
url: 'https://canvasjs.com/assets/script/canvasjs.min.js',
onLoad: function () {
console.log('ok, lets create the chart..');
cmp.createChart();
},
onError: function () {
console.log('canvasJS not loaded');
}
});
}
},
createChart: function () {
var htmlIdOfCmp = this.id;
var chart = new CanvasJS.Chart(htmlIdOfCmp, {
animationEnabled: true,
theme: "light2",
title: {
text: "Simple Line Chart"
},
axisY: {
includeZero: false
},
data: [{
type: "line",
dataPoints: [{
y: 450
}, {
y: 414
}, {
y: 520,
indexLabel: "highest",
markerColor: "red",
markerType: "triangle"
}, {
y: 460
}, {
y: 450
}, {
y: 500
}, {
y: 480
}, {
y: 480
}, {
y: 410,
indexLabel: "lowest",
markerColor: "DarkSlateGrey",
markerType: "cross"
}, {
y: 500
}, {
y: 480
}, {
y: 510
}]
}]
});
chart.render();
}
});

https://fiddle.sencha.com/#view/editor&小提琴/2k59

这是ExtJS6的一个例子。

最新更新