<!DOCTYPE html>
<html>
<head>
<title>Histogram and Pie Chart Twinning - based on Powerball Winning Numbers Since 2010 - State of New York USA - Thanks to https://catalog.data.gov/dataset?q=&sort=views_recent+desc and https://data.ny.gov/api/views/d6yy-54nr/rows.xml and https://www.w3schools.com/xml/xpath_examples.asp</title>
<script type=text/javascript>
var xtitleis=location.search.split('xtitle=')[1] ? decodeURIComponent(location.search.split('xtitle=')[1].split('&')[0]).replace(/\+/g,' ') : "Powerball Winning Numbers Since 2010 - State of New York USA";
var xurlis=location.search.split('xurl=')[1] ? decodeURIComponent(location.search.split('xurl=')[1].split('&')[0]).replace(/\+/g,' ') : "//data.ny.gov/api/views/d6yy-54nr/rows.xml";
var xbasisis=location.search.split('xbasis=')[1] ? decodeURIComponent(location.search.split('xbasis=')[1].split('&')[0]).replace(/\+/g,' ') : "count";
var xpathis=location.search.split('xpath=')[1] ? decodeURIComponent(location.search.split('xpath=')[1].split('&')[0]).replace(/\+/g,' ') : "/response/row/row/winning_numbers";
var xdelimis=location.search.split('xdelim=')[1] ? decodeURIComponent(location.search.split('xdelim=')[1].split('&')[0]).replace(/\+/g,' ') : " ";
var xposis=location.search.split('xcountbasisposition=')[1] ? decodeURIComponent(location.search.split('xcountbasisposition=')[1].split('&')[0]).replace(/\+/g,' ') : "";
var froms='youllneverfindthis';
var tos='youllneverfindthis';
if (xbasisis != 'count') {
xposis='';
froms=xbasisis;
tos=xbasisis + ' selected';
}
var formurl=document.URL.split('?')[0].split('#')[0];
var prefix=(formurl == document.URL ? '' : '<details><summary></summary>');
var suffix=(formurl == document.URL ? '' : '</details>');
var typepos=(xposis.replace('0','') == '' ? 'text' : 'number');
var dataprefix=(xposis.replace('0','') == '' ? '' : 'data-');
var formhtml="<hr><div style='width:100%;background-color:cyan;margin:5 5 5 5;border-radius:10px;'>" + prefix + "<h1> Google Chart Histogram and Pie Chart XML Data Twinning</h1><h3> RJM Programming - December, 2023</h3><h4> Thanks to https://catalog.data.gov/dataset?q=&sort=views_recent+desc and https://data.ny.gov/api/views/d6yy-54nr/rows.xml and https://www.w3schools.com/xml/xpath_examples.asp</h4><br><br><form method=GET action='" + formurl + "'><br> <input onblur=titletweak(this); type=text name=xtitle id=xtitle title='Histogram and Pie Chart title' placeholder='Histogram and Pie Chart title' value='" + xtitleis + "' style=width:50%;background-color:#f0f0f0;></input> title for<br> <input type=text name=xurl id=xurl title='Public data XML URL' placeholder='Public data XML URL' value='" + xurlis + "' style=width:50%;background-color:#f0f0f0;></input> XML public data items URL<br> <select onchange=titletweak(this); id=xbasis name=xbasis title='Measure basis' style=background-color:#f0f0f0;>" + ("<option value=count>Count</option><option value=mean>Mean (for numeric)</option><option value=median>Median (for numeric)</option><option value=mode>Mode (for numeric)</option><option value=range>Range (for numeric)</option><option value=sum>Sum (for numeric)</option><option value=deviation>Standard Deviation (for numeric)</option>").replace(froms,tos) + "</select> of position <input onchange=titletweak(this); onblur=titletweak(this); type=" + typepos + " " + dataprefix + "onclick=\"if (this.value.length == 0) { this.value='0'; } this.type='number';\" placeholder='Not applicable (ie all) [0]' id=xcountbasisposition name=xcountbasisposition value='" + xposis + "' min=0 step=1 style=width:10%;background-color:#f0f0f0;></input><br> <input type=text name=xpath id=xpath title='XML XPath' placeholder='XML XPath' value='" + xpathis + "' style=width:40%;background-color:#f0f0f0;></input> XML XPath<br> <input type=text name=xdelim id=xdelim title='XML Data Member delimiter' placeholder='XML Data Member delimiter' value='" + xdelimis + "' style=width:40px;background-color:#f0f0f0;></input> delimits data items regarding position<br><br> <input type=submit value=Display style=background-color:yellow;border-radius:100px;></input><br><br></form>" + suffix + "</div>";
var proposedtitle=xtitleis;
var isn=false;
var ttw=true;
</script>
</head>
<body>
<p id="demo"></p>
<script>
var datasofar='', nums=[], ij=0, jk=0;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
showResult(xhttp.responseXML);
}
};
xhttp.open("GET", xurlis, true);
xhttp.send();
function showResult(xml) {
var txt = "";
var meanval=0.0;
var npush=[];
var spush=[];
var mdev=0.0;
var slast=0;
var big=0, bigwhat=1, wasm=0;
path = xpathis;
if (xml.evaluate) {
var nodes = xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result = nodes.iterateNext();
while (result) {
txt += result.childNodes[0].nodeValue + "<br>";
nums=('' + result.childNodes[0].nodeValue).split(xdelimis);
isn=false;
if (nums[0].trim() != '') {
if (nums[0].trim().replace(/\-/g,'').replace(/\./g,'').replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '') {
isn=true;
} else if (xbasisis != 'count') {
document.getElementById('xbasis').value='count';
isn=false;
document.getElementById('xcountbasisposition').value='0';
xposis='0';
}
}
if (xposis.replace('0','').trim() != '') {
if (eval('' + nums.length) >= eval(xposis.replace('0','').trim())) {
nums=['' + nums[eval(-1 + eval(xposis.replace('0','').trim()))]];
} else if (xposis.replace('0','').trim() != '') {
nums=[];
}
} else if (xbasisis != 'count') {
meanval=0.0;
mdev=0.0;
big=0;
bigwhat=1;
slast=0;
spush=[];
npush=[];
wasm=0;
for (ii=0; ii<nums.length; ii++) {
npush.push(('' + nums[ii]));
meanval+=eval('' + nums[ii]);
}
wasm=meanval;
meanval/=eval('' + nums.length);
npush.sort((a,b) => a-b);
spush.push(1);
for (ii=0; ii<nums.length; ii++) {
mdev+=eval(eval(nums[ii] - meanval) * eval(nums[ii] - meanval));
if (ii > 0) {
if (npush[ii] == npush[eval(-1 + ii)]) {
spush[slast]++;
if (spush[slast] > bigwhat) {
big=slast;
bigwhat=spush[slast];
}
spush.push(0);
} else {
spush.push(1);
slast=eval(-1 + ii);
}
}
}
mdev/=eval('' + nums.length);
if (xbasisis == 'mean') {
nums=['' + meanval.toPrecision(4)];
} else if (xbasisis == 'sum') {
nums=['' + wasm];
} else if (xbasisis == 'median') {
if (eval(eval('' + nums.length) % 2) == 1) {
nums=[('' + npush[eval(-1 + eval('' + npush.length) / 2)])];
} else if (Math.abs(npush[eval(0 + eval('' + nums.length) / 2)] - meanval) < Math.abs(npush[eval(-1 + eval('' + nums.length) / 2)] - meanval)) {
nums=[('' + npush[eval(0 + eval('' + npush.length) / 2)])];
} else {
nums=[('' + npush[eval(-1 + eval('' + npush.length) / 2)])];
}
} else if (xbasisis == 'range') {
nums=[Math.abs(eval(('' + npush[0]) - ('' + npush[eval(-1 + npush.length)])))];
} else if (xbasisis == 'deviation') {
nums=['' + Math.pow(mdev, 0.5).toPrecision(4)];
} else if (xbasisis == 'mode') {
if (bigwhat == 1) {
if (eval(eval('' + nums.length) % 2) == 1) {
nums=[('' + npush[eval(-1 + eval('' + npush.length) / 2)])];
} else if (Math.abs(npush[eval(0 + eval('' + npush.length) / 2)] - meanval) < Math.abs(npush[eval(-1 + eval('' + npush.length) / 2)] - meanval)) {
nums=[('' + npush[eval(0 + eval('' + npush.length) / 2)])];
} else {
nums=[('' + npush[eval(-1 + eval('' + npush.length) / 2)])];
}
} else {
nums=['' + npush[big]];
}
}
}
for (ii=0; ii<nums.length; ii++) {
if (datasofar.indexOf(',[~' + nums[ii] + '~,') == -1) {
datasofar+=',[~' + nums[ii] + '~,1]';
} else {
jk=eval(datasofar.split(',[~' + nums[ii] + '~,')[1].split(']')[0]);
datasofar=datasofar.replace(',[~' + nums[ii] + '~,' + jk + ']', ',[~' + nums[ii] + '~,' + eval(1 + jk) + ']');
}
}
result = nodes.iterateNext();
}
// Code For Internet Explorer
} else if (window.ActiveXObject || xhttp.responseType == "msxml-document") {
xml.setProperty("SelectionLanguage", "XPath");
nodes = xml.selectNodes(path);
for (i = 0; i < nodes.length; i++) {
txt += nodes[i].childNodes[0].nodeValue + "<br>";
nums=('' + nodes[i].childNodes[0].nodeValue).split(xdelimis);
isn=false;
if (nums[0].trim() != '') {
if (nums[0].trim().replace(/\-/g,'').replace(/\./g,'').replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '') {
isn=true;
} else if (xbasisis != 'count') {
document.getElementById('xbasis').value='count';
isn=false;
document.getElementById('xcountbasisposition').value='0';
xposis='0';
}
}
if (xposis.replace('0','').trim() != '') {
if (eval('' + nums.length) >= eval(xposis.replace('0','').trim())) {
nums=['' + nums[eval(-1 + eval(xposis.replace('0','').trim()))]];
} else if (xposis.replace('0','').trim() != '') {
nums=[];
}
} else if (xbasisis != 'count') {
meanval=0.0;
meanval=0.0;
mdev=0.0;
big=0;
bigwhat=1;
slast=0;
spush=[];
npush=[];
wasm=0;
for (ii=0; ii<nums.length; ii++) {
npush.push(('' + nums[ii]));
meanval+=eval('' + nums[ii]);
}
wasm=meanval;
meanval/=eval('' + nums.length);
npush.sort((a,b) => a-b);
spush.push(1);
for (ii=0; ii<nums.length; ii++) {
mdev+=eval(eval(nums[ii] - meanval) * eval(nums[ii] - meanval));
if (ii > 0) {
if (npush[ii] == npush[eval(-1 + ii)]) {
spush[slast]++;
if (spush[slast] > bigwhat) {
big=slast;
bigwhat=spush[slast];
}
spush.push(0);
} else {
spush.push(1);
slast=eval(-1 + ii);
}
}
}
mdev/=eval('' + nums.length);
if (xbasisis == 'mean') {
nums=['' + meanval.toPrecision(4)];
} else if (xbasisis == 'sum') {
nums=['' + wasm];
} else if (xbasisis == 'median') {
if (eval(eval('' + nums.length) % 2) == 1) {
nums=[('' + npush[eval(-1 + eval('' + npush.length)) / 2])];
} else if (Math.abs(npush[eval(0 + eval('' + npush.length) / 2)] - meanval) < Math.abs(npush[eval(-1 + eval('' + npush.length) / 2)] - meanval)) {
nums=[('' + npush[eval(0 + eval('' + npush.length) / 2)])];
} else {
nums=[('' + npush[eval(-1 + eval('' + npush.length) / 2)])];
}
} else if (xbasisis == 'range') {
nums=[Math.abs(eval(('' + npush[0]) - ('' + npush[eval(-1 + npush.length)])))];
} else if (xbasisis == 'deviation') {
nums=['' + Math.pow(mdev, 0.5).toPrecision(4)];
} else if (xbasisis == 'mode') {
if (bigwhat == 1) {
if (eval(eval('' + nums.length) % 2) == 1) {
nums=[('' + npush[eval(-1 + eval('' + npush.length) / 2)])];
} else if (Math.abs(npush[eval(0 + eval('' + npush.length) / 2)] - meanval) < Math.abs(npush[eval(-1 + eval('' + npush.length) / 2)] - meanval)) {
nums=[('' + npush[eval(0 + eval('' + npush.length) / 2)])];
} else {
nums=[('' + npush[eval(-1 + eval('' + npush.length) / 2)])];
}
} else {
nums=['' + npush[big]];
}
}
}
for (ii=0; ii<nums.length; ii++) {
if (datasofar.indexOf(',[~' + nums[ii] + '~,') == -1) {
datasofar+=',[~' + nums[ii] + '~,1]';
} else {
jk=eval(datasofar.split(',[~' + nums[ii] + '~,')[1].split(']')[0]);
datasofar=datasofar.replace(',[~' + nums[ii] + '~,' + jk + ']', ',[~' + nums[ii] + '~,' + eval(1 + jk) + ']');
}
}
}
}
//document.getElementById("demo").innerHTML = txt;
document.getElementById('myi').src=document.getElementById('myi').src.replace(encodeURIComponent('Powerball Winning Numbers Since 2010 - State of New York USA'), encodeURIComponent(xtitleis));
document.getElementById('mpi').src=document.getElementById('mpi').src.replace(encodeURIComponent('Powerball Winning Numbers Since 2010 - State of New York USA'), encodeURIComponent(xtitleis));
document.getElementById('xhtitle').value=xtitleis;
document.getElementById('xptitle').value=xtitleis;
var proposed=document.getElementById('myi').src.split('&data=')[0] + '&data=' + datasofar;
if (eval('' + proposed.length) < 650) {
document.getElementById('myi').src=document.getElementById('myi').src.split('&data=')[0] + '&data=' + datasofar;
document.getElementById('mpi').src=document.getElementById('mpi').src.split('&data=')[0] + '&data=' + datasofar.replace(/\]\,\[/g, ']%20,%20[').replace(',[', ',%20[');
} else {
document.getElementById('data').value=datasofar;
document.getElementById('mybut').click();
document.getElementById('datap').value=datasofar.replace(/\]\,\[/g, '] , [').replace(',[', ', ['); // ,%20[~45~,23]%20,%20[~
document.getElementById('mybutp').click();
}
document.getElementById('myi').style.display='block';
document.getElementById('mpi').style.display='block';
if (xposis.replace('0','') != '') {
document.getElementById('xtitle').title=xtitleis;
document.getElementById('xcountbasisposition').type='number';
if (document.getElementById('xtitle').title.indexOf(' ' + xposis + getOrdinal(eval('' + xposis))) != -1) {
document.getElementById('xtitle').title=document.getElementById('xtitle').title.replace(' ' + xposis + getOrdinal(eval('' + xposis)), '');
proposedtitle=document.getElementById('xtitle').title;
xtitleis=proposedtitle;
//alert(document.getElementById('xtitle').title);
}
}
}
function getOrdinal(n) { // thanks to https://www.sitepoint.com/convert-numbers-to-ordinals-javascript/#:~:text=How%20to%20Get%20the%20Ordinal%20of%20a%20Number&text=The%20function%20getOrdinal%20accepts%20an,change%20the%20ordinal%20if%20necessary.
let ord = 'th';
if (n % 10 == 1 && n % 100 != 11) {
ord = 'st';
} else if (n % 10 == 2 && n % 100 != 12) {
ord = 'nd';
} else if (n % 10 == 3 && n % 100 != 13) {
ord = 'rd';
}
return ord;
}
function antittw() {
ttw=true;
}
function titletweak(otxt) {
if (!ttw) { return ''; }
//ttw=false;
//setTimeout(antittw, 3000);
var huh='' + otxt.value;
if (huh != 'count' && otxt.id == 'xbasis') {
if (('' + document.getElementById('xcountbasisposition').value).replace('0','') != '') {
document.getElementById('xcountbasisposition').value='0';
document.getElementById('xcountbasisposition').type='number';
}
if (proposedtitle == document.getElementById('xtitle').title || proposedtitle == xtitleis) {
//alert(proposedtitle);
if (proposedtitle.indexOf('Winning Numbers') != -1) {
//alert(111);
document.getElementById('xtitle').value=proposedtitle.replace('Winning Numbers', 'Winning ' + (huh.substring(0,1).toUpperCase() + huh.substring(1).toLowerCase()).replace(/^Deviation$/g, 'Standard Deviation') + ' Numbers');
} else {
document.getElementById('xtitle').value=proposedtitle + ' ... ' + (huh.substring(0,1).toUpperCase() + huh.substring(1).toLowerCase()).replace(/^Deviation$/g, 'Standard Deviation');
}
}
} else if (huh > '0' && otxt.id == 'xcountbasisposition') {
//alert(1);
if (proposedtitle == document.getElementById('xtitle').title || proposedtitle == xtitleis) {
//alert(proposedtitle);
if (proposedtitle.indexOf('Winning Numbers') != -1) {
//alert(111);
document.getElementById('xtitle').value=proposedtitle.replace('Winning Numbers', 'Winning ' + huh + getOrdinal(eval('' + huh)) + ' Numbers');
} else {
document.getElementById('xtitle').value=proposedtitle + ' ... ' + huh + getOrdinal(eval('' + huh));
}
}
} else if (otxt.id == 'xcountbasisposition') {
if (document.getElementById('xtitle').title.indexOf('Winning Numbers') != -1) {
document.getElementById('xtitle').value=document.getElementById('xtitle').title;
} else {
document.getElementById('xtitle').value=document.getElementById('xtitle').title;
}
} else if (huh != proposedtitle && otxt.id == 'xtitle') {
proposedtitle=huh;
otxt.title=otxt.value;
}
}
</script>
<form style=display:none; target=myi method=POST action=//www.rjmprogramming.com.au/PHP/HistogramChart/histogram_chart.php>
<input type=hidden value='Powerball Winning Numbers Since 2010 - State of New York USA' name=title id=xhtitle></input>
<input type=hidden value=y name=onclick></input>
<input type=hidden value=Number name=task></input>
<input type=hidden value=Count name=desc></input>
<input type=hidden value=y name=wouldlikeyoutoseekpermission></input>
<input name=data id=data value='' type=hidden></input>
<input type=submit value=Show id=mybut style='display:none;'></input>
</form>
<form style=display:none; target=mpi method=POST action=//www.rjmprogramming.com.au/PHP/PieChart/pie_chart.php>
<input type=hidden value='Powerball Winning Numbers Since 2010 - State of New York USA' name=title id=xptitle></input>
<input type=hidden value=y name=onclick></input>
<input type=hidden value=Number name=task></input>
<input type=hidden value=Count name=desc></input>
<input type=hidden value=y name=wouldlikeyoutoseekpermission></input>
<input name=data id=datap value='' type=hidden></input>
<input type=submit value=Show id=mybutp style='display:none;'></input>
</form>
<table>
<tr><td>
<iframe style='display:none;' width=740 height=600 id='myi' name='myi' src='//www.rjmprogramming.com.au/PHP/HistogramChart/histogram_chart.php?title=Powerball%20Winning%20Numbers%20Since%202010%20-%20State%20of%20New%20York%20USA&onclick=y&task=Number&desc=Count&data=,[~-1~,0],[~-2~,0]' title='Powerball Winning Numbers Since 2010 - State of New York USA'></iframe>
</td><td>
<iframe style='display:none;' width=660 height=600 id='mpi' name='mpi' src='//www.rjmprogramming.com.au/PHP/PieChart/pie_chart.php?title=Powerball%20Winning%20Numbers%20Since%202010%20-%20State%20of%20New%20York%20USA&onclick=y&task=Number&desc=Count&data=,[~-1~,0],[~-2~,0]' title='Powerball Winning Numbers Since 2010 - State of New York USA'></iframe>
</td></tr>
</table>
<script>
document.write(formhtml);
</script>
</body>
</html>