gpt4 book ai didi

javascript - 如何在 DOJO 的 Grey_CircularLinearGauge 中为一系列值添加差异颜色

转载 作者:行者123 更新时间:2023-11-28 12:18:42 25 4
gpt4 key购买 nike

我正在尝试使用 dojo 工具包并且需要显示 Grey_CircularLinearGauge。像这样:http://download.dojotoolkit.org/release-1.8.3/dojo-release-1.8.3/dojox/dgauges/tests/test_Grey_CircularLinearGauge.html enter image description here

我需要根据值的范围向这个 Grey_CircularLinearGauge 添加不同的颜色。例如:从 0 到 30 绿色,从 30 到 70 黄色,从 70 红色到 100。像这样: enter image description here

谁能帮帮我..

最佳答案

我终于解决了你的问题!看看这个 fiddle :http://jsfiddle.net/v7WwD/我必须深入研究代码才能运行此代码。

首先我在 html 中设置了一个 div,我将仪表连接到:

 <div style="width:300px;height:300px;left:100px;top:100px" id="gauge">
<br />
</div>

然后我这样设置:

  require(["dojox/dgauges/components/grey/CircularLinearGauge"],
function (CircularLinearGauge) {

var myGauge = new CircularLinearGauge({
value: 20,
minimum: 0,
maximum: 150,
majorTickInterval: 25,
minorTickIntervall: 5,
indicatorColor: "#000080", //Zeiger
fillColor: "#FFFFFF"
}, dojo.byId("gauge"));
myGauge.startup();
});

仪表的最终创建从这里开始:

  require(["dojo/ready", "dijit", "dojox/dgauges/TextIndicator",
"dojox/dgauges/LinearScaler","dojox/dgauges/CircularScale",
"dojox/dgauges/CircularRangeIndicator","dojox/dgauges/CircularValueIndicator"],
function (ready, dijit, TextIndicator, LinearScaler, CircularScale,
CircularRangeIndicator,CircularValueIndicator) {
ready(function () {

var gauge = dijit.registry.byId("gauge"); // ADAPT THIS TO YOUR GAUGE ID

gauge.addElement("background", function(g){
g.createEllipse({
cx: 100,
cy: 100,
rx: 100,
ry: 100
}).setFill("#444444");
});

// The scaler
var scaler = new LinearScaler({
minimum: 0,
maximum: 150,
majorTickInterval: 20,
minorTickInterval: 5
});

var scale = new CircularScale({
scaler: scaler,
originX: 100,
originY: 100,
startAngle: 110,
endAngle: 70,
radius: 70,
labelPosition: "outside",
tickShapeFunc: function(group, scale, tick){
return group.createLine({
x1: tick.isMinor ? 2 : 0,
y1: 0,
x2: tick.isMinor ? 8 : 12,
y2: 0
}).setStroke({
color: tick.isMinor ? "black" : "white",
width: tick.isMinor ? 0.5 : 1
});
}
});
gauge.addElement("scale", scale);

// A value indicator
var indicator = new CircularValueIndicator({
interactionArea: "indicator",
indicatorShapeFunc: function(group){
return group.createPolyline([20, -6, 60, 0, 20, 6, 20, -6]).setFill("black").setStroke("white");
},
value: 50
});
scale.addIndicator("indicator", indicator);

//make green range
var rangeIndicatorGreen = new CircularRangeIndicator({
start: 0,
value: 30,
radius: 62,
startThickness:5,
endThickness: 5,
fill: "green",
interactionMode: "none"
});
scale.addIndicator("rangeIndicatorGreen", rangeIndicatorGreen, true);

//make yellow range
var rangeIndicatoryellow = new CircularRangeIndicator({
start: 30,
value: 70,
radius: 62,
startThickness:5,
endThickness: 5,
fill: "yellow",
interactionMode: "none"
});
scale.addIndicator("rangeIndicatoryellow", rangeIndicatoryellow, true)

//make red range
var rangeIndicatorRed = new CircularRangeIndicator({
start: 70,
value: 100,
radius: 62,
startThickness:5,
endThickness: 5,
fill: "red",
interactionMode: "none"
});
scale.addIndicator("rangeIndicatorRed", rangeIndicatorRed, true);

// Indicator Text"
indicator = gauge._elementsIndex.scale._indicators[0];
var indicatorText = new TextIndicator();
indicatorText.set("indicator", indicator);
indicatorText.set("x", 100);
indicatorText.set("y", 100);
gauge.addElement("indicatorText", indicatorText);

});
});

问候,米里亚姆

关于javascript - 如何在 DOJO 的 Grey_CircularLinearGauge 中为一系列值添加差异颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19016938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com