<button id="add" onclick="AddGauge()">Click to Add Gauge</button>
// parent element for gauges
<div id="gauges">
</div>
var count = 0;
function AddGauge() {
var parent = document.getElementById('gauges');
//Creating div element dynamically
var element = document.createElement('div');
//Creating unique id here
element.id = 'container'+ count;
parent.appendChild(element);
var circulargauge = new ej.circulargauge.CircularGauge({
// other configurations
});
circulargauge.appendTo('#' + element.id);
count++;
} |
Hi Dharani,
I appreciate the code snippet, but I believe I have not made myself clear. I am attempting to create gauges in specific parts of my ASP.NET MVC page, I have c# code to create the gauge:
@(Html.EJS().CircularGauge("container").Loaded("loaded").Load("gaugeLoad").Title("Total Score")
.TitleStyle(ts => ts.Size("18px")).Axes(axes => axes.Radius("70%").StartAngle(180).EndAngle(180).Minimum(1).Maximum(4)
.LabelStyle(ls => ls.Position(Position.Inside)).MajorTicks(major => major.Height(0)).MinorTicks(minor => minor.Height(0))
.Pointers(pt => pt.Value( DataLibrary.BusinessLogic.AssessmentProcessor.LoadTotalResult(assessmentId2).Select(x => x.score).DefaultIfEmpty(0).Average() ).RoundedCornerRadius(20).Type(PointerType.RangeBar).Radius("90%").Color("#e5ce20").PointerWidth(30).Animation(animation => animation.Enable(true))
.Border(border => border.Width(0)).Add()).LineStyle(lin => lin.Width(0))
.Ranges(ranges => ranges.Start(1).End(4).Radius("90%").StartWidth("30").EndWidth("30").Color("#E0E0E0").RoundedCornerRadius(0).Add()).Add()).Render())
And javascript to handle the gaugeLoad and the loaded functions.
<script type="text/javascript">
var circulargauge;
function gaugeLoad(args) {
console.log(args.gauge.axes[0]);
var arctheme = location.hash.split('/')[1];
arctheme = arctheme ? arctheme : 'Material';
args.gauge.theme = (arctheme.charAt(0).toUpperCase() + arctheme.slice(1));
if (!circulargauge) {
circulargauge = args.gauge;
args.gauge.axes[0].minorTicks.height = 0;
args.gauge.axes[0].majorTicks.height = 0;
args.gauge.axes[0].labelStyle.font.size = "0px";
args.gauge.axes[0].annotations = [{
content: '<div id="pointervalue" style="font-size:35px;width:120px;text-align:center">' +
parseFloat(Math.round(2 * 100) / 100).toFixed(2).toString() + '/4</div>',
angle: 0,
zIndex: '1',
radius: '0%'
},
{
content: '<div id="slider" style="height:70px;width:250px;"></div>',
angle: 0,
zIndex: '1',
radius: '-100%'
},
];
}
}
function loaded(args) {
if (!isNaN(sliderValue)) {
circulargauge.isProtectedOnChange = true;
if (sliderValue >= 1 && sliderValue < 2) {
circulargauge.axes[0].pointers[0].color = '#ea501a';
}
else if (sliderValue >= 2 && sliderValue < 3) {
circulargauge.axes[0].pointers[0].color = '#e5ce20';
}
else if (sliderValue >= 3 && sliderValue < 4) {
circulargauge.axes[0].pointers[0].color = '#a1cb43';
}
else if (sliderValue >= 4 && sliderValue < 5) {
circulargauge.axes[0].pointers[0].color = '#82b944';
}
}
}
When I reuse my C# code I do not get a new CircularGauge in the position. I can't find any specific reference to a div in the code so I figure I must have a concept completely wrong. I would really appreciate further assistance in this matter. Apologies for the lack of code-blocks but I seem unable to create them in the text edit UI.
Thank you.
function gaugeLoad(args) {
var arctheme = location.hash.split('/')[1];
arctheme = arctheme ? arctheme : 'Material';
args.gauge.theme = (arctheme.charAt(0).toUpperCase() + arctheme.slice(1));
circulargauge = args.gauge;
args.gauge.axes[0].minorTicks.height = 0;
args.gauge.axes[0].majorTicks.height = 0;
args.gauge.axes[0].labelStyle.font.size = "0px";
args.gauge.axes[0].annotations = [{
content: '<div id="pointervalue" style="font-size:35px;width:120px;text-align:center">' +
parseFloat(Math.round(2 * 100) / 100).toFixed(2).toString() + '/4</div>',
angle: 0,
zIndex: '1',
radius: '0%'
},
{
content: '<div id="slider" style="height:70px;width:250px;"></div>',
angle: 0,
zIndex: '1',
radius: '-100%'
},
];
} |