如何访问 dojox 图表并将其作为 js 对象获取?在普通的 dijit 小部件中,它可以使用,registry.byId("id")
但这不适用于 dojox 图表。
我也尝试过dom.byId
,但我需要它作为调用函数的对象,而不是作为 dom 节点。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="dijit/themes/claro/claro.css">
<script>dojoConfig = {async: true}</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.8.0/dojo/dojo.js"></script>
<script>
require(["dojox/charting/Chart", "dojox/charting/axis2d/Default", "dojox/charting/plot2d/Lines", "dojox/charting/plot2d/Grid", "dojox/charting/themes/Claro", "dojo/ready"],
function(Chart, Default, Lines, Grid, theme, ready){
ready(function(){
var chart1 = new Chart("chartId");
chart1.setTheme(theme);
chart1.addPlot("default", {type: Lines});
chart1.addPlot("Grid", {type: "Grid"});
chart1.addAxis("x",{});
chart1.addAxis("y", {vertical: true});
chart1.addSeries("Visits",[
{ x: 1, y: 200 },
{ x: 2, y: 185 },
{ x: 3, y: 100 },
{ x: 4, y: 110 },
{ x: 5, y: 130 },
{ x: 6, y: 70 },
{ x: 7, y: 30 },
{ x: 8, y: 200 }
]);
chart1.render();
});
});
require(["dojo/ready", "dijit/form/Button", "dojo/dom"], function(ready, Button, dom){
ready(function(){
var button = new Button({
label: "Change my label"
}, "buttonId");
});
});
function tryToAccess()
{
require(["dojo/ready", "dijit/registry", "dojo/dom"], function(ready, registry, dom){
ready(function(){
var button = registry.byId("buttonId");
console.log(button); /*returns an object*/
button.set("label","successfully changed!");
/*var chart = ????????????????; */
});
});
}
</script>
</head>
<body class="claro">
<button id="buttonId"></button>
<div id="chartId" style="height: 300px;"></div>
<!-- JUST 4 DEBUGGING -->
<button onClick="tryToAccess();">try to access</button>
</body>
</html>