Leveraging the power of Angular.JS to synchronize a JSON value with a Syncfusion Circular gauge

I've been working on a project that involves using the Syncfusion Javascript gauge control to show a weekly pay bonus. The data for this is stored in a SharePoint list, and I have written a JavaScript code to convert the SharePoint list from XML to JSON.

<script type="text/javascript">
$ajax({
    url: "/_api/web/lists/GetByTitle('bonusEntry')/items?$orderby=Date desc&$filter=Department eq 'Meltshop'&$top=1",
    type: "GET",
    headers: {
        "accept":"application/json;odata=verbose",
    },
    success: function (data) {      
        var newMsBonus = "";
            for(i=0; i < data.d.results.length; i++){
                newMsBonus = newMsBonus + "<div>" + data.d.results[i].ACrew + "</div>";
        }
            $('#oDataanalysisScoreBoard').html(newMsBonus);
    },
    error: function (error) {
        alert("error: " + JSON.stringify(error));
    }
})

Following this, the value retrieved is placed in this specific Div.

<div id="oDataanalysisScoreBoard"></div>

My main goal is to bind this data to the Syncfusion control setup as shown below:

$("#CircularGauge1").ejCircularGauge({
            width: 500,
            height: 500,
            backgroundColor: "#3D3F3D",
            readOnly: false,
            scales: [{
                ticks: [{
                    type: "major",
                    distanceFromScale: 70,
                    height: 20,
                    width: 3,
                    color: "#ffffff"
                }, {
                    type: "minor",
                    height: 12,
                    width: 1,
                    distanceFromScale: 70,
                    color: "#ffffff"
                }],
            }]
        });

The gauge itself is created within this container:

<div id="CircularGauge1"></div>

Even though the gauge is successfully built, I'm facing issues with passing the value to it.

If anyone has any suggestions or insights on how I can resolve this issue or if there are any improvements I can make, your feedback would be greatly appreciated! Thank you all! EDIT: The Syncfusion software generates a gauge and adjusts the needle according to a numerical input. My AJAX call fetches a number from a SharePoint list and displays it in a div.

Answer №1

Your code snippet mentions passing the value as a "String". If the string value is passed to the loop, it will concatenate as a string value only. However, in order for Circular Gauge properties (width, height, distanceFromScale) to take effect, integer values need to be passed instead. Therefore, modify the code snippet as shown below:

                  $.ajax({
            url: "/Gauge/GetData",
            type: "POST",
            success: function (data) {
                var newMsBonus = 0;
                for (i = 0; i < data.length; i++) {
                    newMsBonus = newMsBonus + data[i].MajorDistanceFromScale;   // Using MajorScale distanceFromScale value for demo
                }

                $('#oDataanalysisScoreBoard').html(newMsBonus);
                 },
            failure: function (error) {
                alert("No data available");
            }
        });

We have prepared a sample MVC application with an ".mdf" database meeting your requirements. A table called "GaugeData" has been created with two records. The "$.ajax" method calls the action method "GetData" to retrieve JSON data from the controller. See the code snippets below.

View Page:

            $.ajax({
            url: "/Gauge/GetData",
            type: "POST",
            success: function (data) {},
            failure: function (error) {
           }
        });

Controller Page:

 public class GaugeController : Controller
{
    GaugeDataDataContext db = new GaugeDataDataContext();

    public JsonResult GetData()
    {
        IEnumerable data = db.GaugeDatas.Take(500); 
        return Json(data, JsonRequestBehavior.AllowGet);
    }

}

The calculated value is then assigned to the gauge property. The "MajorDistanceFromScale" value from the database record is used and assigned to the gauge properties. Refer to the following code snippet.

                var distanceValue = parseInt($("#oDataanalysisScoreBoard")[0].innerHTML);
                $("#CircularGauge1").ejCircularGauge({
                    width: 500,
                    height: 500,
                    backgroundColor: "#3D3F3D",
                    readOnly: false,
                    scales: [{
                        ticks: [{
                            type: "major",
                            distanceFromScale: distanceValue,
                            height: 20,
                            width: 3,
                            color: "#ffffff"
                        }, {
                            type: "minor",
                            height: 12,
                            width: 1,
                            distanceFromScale: 70,
                            color: "#ffffff"
                        }],
                    }]
                });

For more reference, please check out the attached sample: GaugeListSample

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 process of implementing a service in AngularJS?

For my Angular JS project, I am working on creating a module to include my service (file: utils/productos.js) and then load it as a dependency for my ventas module (ventas/ventas.js). However, I encountered the following error: Error: [$injector:nomod] Mo ...

Is there a way I can run certain code asynchronously before my service methods are invoked?

Having difficulty executing tasks before initializing my service and using its methods. The scenario is as follows: I am developing an application that communicates with 2 different backend systems via REST (to ensure future compatibility for client upgra ...

Trouble displaying Firestore data in Vuejs with v-html update feature not functioning as expected

I have been trying to fetch data from Firestore and display it on the interface using Vuejs. However, I am facing an issue where the innerHTML is not getting updated despite spending 3 hours troubleshooting without any success. Here is a snippet of the co ...

Print the content from the selected tab in AngularJS UI tab

In my AngularJS application, I have implemented nested tabs and encountered an issue. I am trying to enable users to print the selected content list from both parent and child tabs. Is there a way to achieve this so that when a user clicks on "print list ...

Instructions for incorporating a glyphicon glyphicon-calendar into a bootstrap dropdown using pug

I am a beginner in the world of pug and I'm trying to include the glyphicon glyphicon-calendar in a dropdown menu labeled "All months". .pull-right select.form-control.btn-primary#selectMonth(style="margin-top: -15px;") option(selected="selecte ...

Refine objects based on their properties without removing them from the dataset

I have a specific object structured as follows: var myObj: { 2:"None", 20:"A", 31:"A", 32:"A", Social:"B", Method:"None" } My goal is to retrieve the object without the properties 'Social' and 'Method'. Initia ...

Is Node.js categorized as multithreading due to its utilization of worker threads?

Throughout my life, I was under the impression that Node.js and JavaScript operated as a single threaded language. It was always said that Node.js wasn't ideal for CPU intensive tasks due to its single threaded nature. Multithreading, on the other han ...

JavaScript: Unusual behavior discovered in forEach iteration

Here's the code snippet I'm having trouble with: someArray.forEach(x => { // do something console.log(‘calling api for ‘ + x); callAnHttpApiAsync(...); sleep(10); }); The issue lies in the asynchronous nature of the HTTP API call within ...

Encountering errors when initializing a JavaScript module through Angular2 instantiation

I have a situation where I need to utilize a plain JavaScript module within my Angular service. However, when I try to create an instance of the module in the constructor, I encounter the following error: TypeError: Engine is not a constructor The code ...

Discovering the version of the Javascript library utilized on a website - a step-by-step guide

My quest is to uncover the versions of JavaScript libraries being utilized by popular websites. By using phantomjs.exe, I successfully identified the version information for jquery. However, I am currently at a loss on how to expand this capability to inc ...

Ramjet: Unveiling the Magic of Making Elements Appear and Disappear

Currently, I am attempting to implement the code for ramjet from . However, I am facing an issue where element a does not disappear when transitioning into b. Additionally, I am encountering an error message "--Uncaught TypeError: Cannot read property &apo ...

"Implementing a UITableView alphabetical index feature for efficiently displaying vast amounts of

My current project involves loading data from a webservice that returns JSON data into a table. To handle the large amount of data in the database, I implement dynamic loading when the user scrolls down. One challenge I am facing is whether it would be fe ...

Swirling hues transforming into #000000 upon second attempt

My goal is to create a button that generates two random color codes. Initially, this button seems to work fine on the first click, but on the second click, both codes turn into #000000. Despite my attempts to troubleshoot the issue, I haven't been ab ...

Sharing data between controllers in angular 1.5 components for effective communication

I have recently delved into the world of Angular and TypeScript. The project is utilizing Typescript, Angular 1.5 components, with the goal to avoid using $scope if possible One of the components features search input fields, while another component is r ...

Using Python to generate a JSON file containing a list of artifacts through a loop

My file_list variable contains a list of files (artifacts), although it has been shortened for this example. print(type(file_list)) <class 'list'> print(file_list) ['file_AA.txt', 'file_BB.txt', 'file_CC.txt', ...

Eliminate the alert message that appears when dynamically rendering a React styled component

When checking the browser console, I noticed a warning that reads as follows: react_devtools_backend.js:3973 The component styled.div with the id of "sc-dmRaPn" has been created dynamically. You may see this warning because you've called sty ...

What is the best way to augment an AJAX array response with additional data?

I'm working on an AJAX request and I need to add additional properties to the response I receive. Can anyone offer some guidance? Here is the AJAX request code I'm using: var form_data = {}; $.ajax({ type: "GET", url: "../../../sample_ ...

change visibility:hidden to visible in a css class using JavaScript

I've put together a list of Game of Thrones characters who might meet their demise (no spoilers included). However, I'm struggling with removing a CSS class as part of my task. Simply deleting the CSS is not the solution I am looking for. I' ...

Pass the form data to a Bootstrap modal upon submission of the form

I'm attempting to retrieve form data and convert it to JSON to display in a modal dialog that opens on the Submit button click! This is my progress so far: HTML <form class="form-horizontal" id="configuration-form"> --irrelevant-- <button ...

Tips for preventing the occurrence of numerous instances of braintree.setup in Angular

I am encountering an issue with a Braintree payment form displayed in a modal window: $scope.displayModalBraintree = function () { $scope.modal = 'modal_payment_form.html', $scope.$on('$includeContentLoaded', function () { ...