Adding different colors for a range of values in the Grey_CircularLinearGauge component of DOJO can be achieved by customizing the

I'm currently working with the dojo toolkit and I am looking to incorporate the Grey_CircularLinearGauge component into my project. Here is an example of how I want it to look:

In addition, I also need to customize the colors based on specific value ranges for this Grey_CircularLinearGauge. For example, I would like the gauge to show green from 0 to 30, yellow from 30 to 70, and red from 70 to 100. Here is an example of how I envision it:

If anyone has experience with this and can offer some guidance, I would greatly appreciate it.

Answer №1

After thoroughly investigating your issue, I have successfully found a solution! Please take a moment to review the following fiddle: http://jsfiddle.net/pxQ4L/ It required delving deep into the code to make it operational.

To begin with, I added a div element in the html where the gauge is connected:

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

Following that, I configured it like this:

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();
});

The final steps for creating the gauge are as follows:

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);

   //create 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);

   //create 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)

 //create 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);

});
});

Best regards, Miriam

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method to vertically center a container in bootstrap 4 at a specified height?

I'm trying to center a container in Bootstrap 4. I have an element with a width of 300px. .guide-background{ background: url("https://www.webascender.com/wp-content/uploads/executive-guide-1.jpg"); background-repeat: no-repeat; backgrou ...

Tips for detecting if text appears in bold on a webpage using Selenium

I came across a pdf document with the following content: <div class=**"cs6C976429"** style="width:671px;height:18px;line-height:17px;margin-top:98px;margin-left:94px;position:absolute;text-align:left;vertical-align:top;"> <nobr ...

"Utilizing multiple materials in a single obj file using the power of three.js

As I work with three.js to load an obj file featuring a ring adorned with pearls, I face a challenge. The obj file lacks an mtl file, a result of the exporting software - possibly Rhinoceros - not including it (as per the graphic designer's explanatio ...

Instructions for accessing a single element in a nested JSON file

I am struggling with extracting only the TEXT values from a JSON file that contains the following data: { "language": "en", "textAngle": 0, "orientation": "Up", "regions": [ { "boundingBox": "21,16,304,451", "lines": [ { ...

What is the best way to inline center two block buttons using CSS?

Having difficulty centering two block buttons using inline CSS in the Darkly theme from Bootstrap. I am unable to directly edit the CSS and can only utilize inline CSS due to using the CDN version of the theme. <a href='/start'><button c ...

Securing URL Query Parameters

Working with Liferay 5.2 and ExtJS 3.4 poses a challenge for parameter passing in the URL. The issue arises when reports are generated based on parameters passed in the URL, allowing manual changes that lead to the generation of unauthorized reports. The ...

Combining two sets of data into one powerful tool: ngx-charts for Angular 2

After successfully creating a component chart using ngx-charts in angular 2 and pulling data from data.ts, I am now looking to reuse the same component to display a second chart with a different data set (data2.ts). Is this even possible? Can someone guide ...

Trigger the click event on the ul element instead of the li element using jQuery

Is there a way to make the click event only affect ul tags and not all li elements using jQuery? <!-- HTML --> <ul class="wrap"> <li>test1</li> <li>test2</li> <li>test3</li> </ul> I attemp ...

Extract the ID from the array, save it, and then delete it from the local storage

I am currently developing a mobile application using Angular, JavaScript, Ionic, and Cordova. Within one of my functions, I make use of an array called existingEntries, which is stored as a variable. categories: Array [276] [0...99] 0: Object id ...

Leveraging the socket.io and express modules independently of npm

I am currently developing a project for an embedded Linux system using busybox created with buildroot. I'm intrigued by the idea of utilizing node.js modules such as socket.io and express without needing to depend on the installation or execution of n ...

Analyzing the values of two sets of key-value pairs

I am facing an issue where I have two sets of objects labeled LABELS1 and LABELS2, and my goal is to iterate through them. If any of the IDs from LABELS1 match any of the IDs from LABEL2, I need to update the simple_value of LABELS1 with the correspondin ...

Using jQuery to Validate Input Text Control Depending on Radio Selection

How can I ensure that the input text linked to the selected radio option is filled in? For instance, in the example above: If Contact 1's Email radio option is chosen, the Email text field for Contact 1 must not be empty, while the Phone and US Mai ...

Choosing an ID along with a numerical value in jQuery

Being new to both stackoverflow and jQuery, I'm facing a challenge in creating a basic function. In my website, there are multiple links with IDs such as "filtro1", "filtro2", and so on. My goal is to write a single piece of code that will be trigger ...

Tips for rearranging array position retrieved from API in Vue.js

props: { groups: Array, }, computed: { groups: function(arr) { alert('hi') } }, <div v-for="(item, index) in groups" :key="item.id" :id="item.id" class="group-name" @click="isOnlySelected ? null : $emit('setSele ...

The effectiveness of border-radius is limited to only one side of the div

After experimenting with applying the border-radius property to a div, I encountered an issue where the border radius only worked on one side when the radius value was too large. How can I resolve this problem while maintaining the border-radius value on a ...

CSS exclusive - achieving a horizontal scrolling list with all list items in a single row

I am working with a div that has a fixed width. Inside this div, there is an unordered list (ul) containing a random number of list items (li) with varying widths. My project utilizes the Bootstrap framework. Below is an example of the code structure: & ...

Incorporating tags into the react-select component

https://i.sstatic.net/Fsknq.pngI am still a beginner in the world of react-js. Currently, I am experimenting with the following: https://i.sstatic.net/4Ggoz.png This is what I have attempted so far: const options = [ { value: 'chocolate', ...

What is the process for removing globally declared types in TypeScript definitions?

There are numerous libraries that cater to various platforms such as the web, Node servers, and mobile apps like React Native. This means they can be integrated using <script /> tags, require() calls, or the modern import keyword, particularly with t ...

Converting arrays of objects in JavaScript made easy

Could someone please assist me in converting my array of objects into an object or JSON format? Here is a sample snippet: var data = [ {"code":"M","montant":"2000","title":"Masculine"}, {"code" ...

Swapped out image hyperlink for a clickable button

As someone new to javascript, I'm encountering an issue with this code. I want to update my image links when a button is clicked in my code. However, the problem is that my image links are already being updated before I even click the button. Below ar ...