简体   繁体   English

使用Angular.JS将JSON值绑定到Syncfusion圆规

[英]Using Angular.JS to bind a JSON value to a Syncfusion Circular gauge

I am working on a project using Syncfusion Javascript gauge control to display a weekly pay bonus. 我正在使用Syncfusion Javascript量表控件显示每周薪水奖金的项目。 The data is stored on a SharePoint list. 数据存储在SharePoint列表中。 I wrote a javascript to convert the sharepoint list from XML to JSON. 我编写了一个JavaScript,将共享点列表从XML转换为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));
    }
})

Then the value is placed in this Div. 然后将该值放入此Div。

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

Basically what I would like to do is bind the data to the Syncfusion control which is set up like this: 基本上,我想做的就是将数据绑定到Syncfusion控件,该控件的设置如下:

$("#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"
                }],
            }]
        });

Then the gauge is created inside this: 然后在此内部创建量规:

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

The gauge will build but I cannot get the gauge to recieve the value. 量规将建立,但我无法使量规获得该值。

If anyone has any ideas on how I can make this work or things I'm doing I would greatly appreciate any input! 如果有人对我如何进行这项工作或正在做的事情有任何想法,我将不胜感激! Thanks everyone! 感谢大家! EDIT: The synfusion software creates a gauge and changes the needle based on a number value thats given to it. 编辑:synfusion软件会创建一个量规并根据提供给它的数值来更改针。 My ajax call pulls a number entered into a Sharepoint list and then displays that in a div. 我的ajax调用提取一个输入到Sharepoint列表中的数字,然后将其显示在div中。

In the above code snippet you mentioned the passing value as “String”. 在上面的代码片段中,您将传递值称为“字符串”。 If you pass the string value to the loop it will concatenate as string value only. 如果将字符串值传递给循环,则它将仅连接为字符串值。 But we need to pass the integer value to the Circular Gauge properties(width, height, distancefromscale) to take effect. 但是我们需要将整数值传递给“圆规”属性(宽度,高度,距离标尺)才能生效。 Hence, change the code snippet with the following. 因此,请使用以下内容更改代码段。

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

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

And we have prepared the sample to meet your requirement with the MVC application including the “.mdf” database. 并且我们已经准备了样本,以通过MVC应用程序(包括“ .mdf”数据库)满足您的要求。 We have created the table called “GaugeData” and added the two record. 我们创建了名为“ GaugeData”的表,并添加了两个记录。 And using the “$.ajax” called the action method “GetData” and received the “JSON” data from the controller. 然后使用“ $ .ajax”调用操作方法“ GetData”,并从控制器接收“ JSON”数据。 Refer the following code snippet. 请参考以下代码段。

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

}

And then assigned the calculated value to the gauge property. 然后将计算出的值分配给量规属性。 Here, I have used the “MajorDistanceFromScale” value read from the database record and assigned to the gauge properties. 在这里,我使用了从数据库记录中读取并分配给量规属性的“ MajorDistanceFromScale”值。 Refer the following coding 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"
                        }],
                    }]
                });

And also please refer the below attached sample for more reference. 另外,请参考下面随附的示例以获取更多参考。 GaugeListSample 量表列表样本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM