[LinearGauge.cshtml]
<input type="button" id="btn" onclick="Update()" value="Update Pointer" />
function Update() {
$.ajax({
url: "@Url.Action("GetPointer", "LinearGauge")",
//…
success: function (value) {
var linearGaugeObj = document.getElementById('linear').ej2_instances[0],
axisIndex = 0, pointIndex = 0;
Using the setPointerValue method updated the pointer value
linearGaugeObj.setPointerValue(axisIndex, pointIndex,value)
}
});
}
[LinearGaugeController.cs]
public IActionResult GetPointer()
{
//…
return Json(pointerValue);
}
|
[CircularGaugeController.cs]
Create the required properties for the gauge. Here we have created axes for the circular gauge and pass it to view page using ViewBag
CircularGaugePointer pointer = new CircularGaugePointer();
pointer.Value = 70;
CircularGaugeAxis axis = new CircularGaugeAxis();
axis.Pointers = new List<CircularGaugePointer>();
//…
axis.Pointers.Add(pointer);
List<CircularGaugeAxis> Axes = new List<CircularGaugeAxis>();
Axes.Add(axis);
ViewBag.gaugeAxes = Axes;
[CircularGauge.cshtml]
<ejs-circulargauge id="circular" width="200" height="200" axes="ViewBag.gaugeAxes">
</ejs-circulargauge>
|
<input type="button" value="Add Gauge" onclick="addGauge()" id="Gauge" />
function addGauge() {
$.ajax({
url: "@Url.Action("GetPointer", "CircularGauge")",
dataType: "json",
type: "POST",
success: function (pointerValue) {
In Ajax success event we have created element dynamcially
var gaugeEle = document.createElement('div');
gaugeEle.id = 'circularGauge' + count;
document.getElementById('gaugeContainer').appendChild(gaugeEle);
Created gauge
var currentGauge = new ej.circulargauge.CircularGauge({
axes: [{
pointers: [{
Assigned pointer value from server
value: pointerValue
}]
}]
});
currentGauge.appendTo('#' + gaugeEle.id);
count++;
}
});
}
|
<input type="button" value="Update Pointer" onclick="updateGauge()" id="Gauge" />
function updateGauge() {
setInterval(function () {
$.ajax({
url: "@Url.Action("GetPointer", "CircularGauge")",
dataType: "json",
type: "POST",
success: function (pointerValue) {
Get instance of gauge and update the pointer value
var currentGauge = document.getElementById('circular').ej2_instances[0];
currentGauge.setPointerValue(0, 0, pointerValue);
}
});
}, 5000);
}
|