I want to add a count down pie charts inside our web page,and the pie charts will show the renaming time for our projects in the following format:-
**Project A**
starts in 3 weeks and 3 days
**Project B**
starts in 1 month and 2 weeks
here is the JavaSscript to implement this functionality and to show the above result:-
<script src="/Resources/jquery-1.11.3.js"></script>
<script>
$(function () {
var htmlinit = "";
htmlinit = "<image id= 'customloader' src= '/resources/ajax-loader.gif'></image>";
$("#inserhere").after(htmlinit);
var html="<div class='ms-comm-adminLinks ms-core-defaultFont ms-noList' unselectable='on'><div class='ms-webpart-titleText' unselectable='on'><a style='color:white' href='/Lists/Counter/AllItems.aspx'> Useful Links </a> </div><ul class='ms-comm-adminLinksList' unselectable='on'>";
$.ajax({
url: "/_api/web/lists/getbytitle('Counter')/items?$select=Title,CounterStartDate&$orderby=CounterStartDate asc",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
if(data.d.results.length>0){
var items=data.d.results;
for(var i=0;i<items.length;i++){
var nurl = items[i].CounterStartDate.toString();
var ntitle = items[i].Title.toString();
var loopidcustom = "demo"+i.toString();
var formatteddate = datediff(new Date (nurl));
document.getElementById(loopidcustom).innerHTML = "<b>" + ntitle + "</b><br> Start Date "+ d+"<br/> Starts in " + formatteddate +"<hr/>" ;
if (distance < 0) {
//clearInterval(x);
document.getElementById(loopidcustom).innerHTML = "";
}
}
}
},
error: function (data) {
$("#customloader").hide();
}
});
});
function datediff(date) {
let d1 = date;
let d2 = now = new Date();
if (d2.getTime() < d1.getTime()) {
d1 = now;
d2 = date;
}
let yd = d1.getYear();
let yn = d2.getYear();
let years = yn - yd;
let md = d1.getMonth();
let mn = d2.getMonth();
let months = mn - md;
if (months < 0) {
years--;
months = 12 - md + mn;
}
let dd = d1.getDate();
let dn = d2.getDate();
let days = dn - dd;
if (days < 0) {
months--;
// figure out how many days there are in the last month
d2.setMonth(mn, 0);
days = d2.getDate() - dd + dn;
}
let weeks = Math.floor(days / 7);
days = days % 7;
if (years > 0) return years + ' years' + (months > 0 ? ' and ' + months + ' months' : '');
if (months > 0) return months + ' months' + (weeks > 0 ? ' and ' + weeks + ' weeks' : '');
if (weeks > 0) return weeks + ' weeks' + (days > 0 ? ' and ' + days + ' days' : '');
return days + ' days';
}
</script>
now i want to modifiy this and to show the remaining Year,Month,Week and Days inside pie charts,instead of only showing text. so i find this Read-Only knob pie chart interesting http://anthonyterrien.com/demo/knob/ :-
but i am facing these issues, when i try to test it inside our web page:-
i added the following code to test how the pie chart will look like:-
<script> $(function($) { $(".knob").knob({ change : function (value) { //console.log("change : " + value); }, release : function (value) { //console.log(this.$.attr('value')); console.log("release : " + value); }, cancel : function () { console.log("cancel : ", this); }, /*format : function (value) { return value + '%'; },*/ draw : function () { // "tron" case if(this.$.data('skin') == 'tron') { this.cursorExt = 0.3; var a = this.arc(this.cv) // Arc , pa // Previous arc , r = 1; this.g.lineWidth = this.lineWidth; if (this.o.displayPrevious) { pa = this.arc(this.v); this.g.beginPath(); this.g.strokeStyle = this.pColor; this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, pa.s, pa.e, pa.d); this.g.stroke(); } this.g.beginPath(); this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ; this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, a.s, a.e, a.d); this.g.stroke(); this.g.lineWidth = 2; this.g.beginPath(); this.g.strokeStyle = this.o.fgColor; this.g.arc( this.xy, this.xy, this.radius - this.lineWidth + 1 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false); this.g.stroke(); return false; } } }); // Example of infinite knob, iPod click wheel var v, up=0,down=0,i=0 ,$idir = $("div.idir") ,$ival = $("div.ival") ,incr = function() { i++; $idir.show().html("+").fadeOut(); $ival.html(i); } ,decr = function() { i--; $idir.show().html("-").fadeOut(); $ival.html(i); }; $("input.infinite").knob( { min : 0 , max : 20 , stopper : false , change : function () { if(v > this.cv){ if(up){ decr(); up=0; }else{up=1;down=0;} } else { if(v < this.cv){ if(down){ incr(); down=0; }else{down=1;up=0;} } } v = this.cv; } }); }); </script> <style> body{ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-weight: 300; text-rendering: optimizelegibility; } p{font-size: 30px; line-height: 30px} div.demo{text-align: center; width: 280px; float: left} div.demo > p{font-size: 20px} </style>
but i got only the number without any pie chart around it as follow:-
Second question, now let say i manage to show the pie chart correctly. then can i modify the way the pie charts are being constructed? for example in my case i want the pie charts to show count downs, so if the remaining is 1-Day then the pie chart should be almost fully colored. and i will have those different ranges:-
- for Day it can be from 1 to 7
- for month it can be from 1 to 12
- for weeks it can be from 1 to 4
so is this possible ?
datediff
function will return a string as follow1 week and 3 days
or4 months and 3 weeks
. so i will need to split the text between the wordand
,, and then build the charts – john Gu