How do i change a pivot table from grand total to average? - average

Good afternoon, it is necessary that in the end there is not a sum, but the average of all values. Is it possible to implement this functionality?

In WDR, there is no clear way to make an average grand total if subtotal values contain the sum aggregations.
But you can change the text in grand total cells with the customizeCell function to make it contain an average value.
Example:
<!DOCTYPE html>
<html>
<head>
<title>WDR</title>
</head>
<body>
<link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet" />
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>
<div id="wdr"></div>
<script>
var pivot = new WebDataRocks({
container: "#wdr",
toolbar: true,
customizeCell: customize,
report: {
dataSource: {
filename: "https://cdn.webdatarocks.com/data/data.csv"
}
}
});
function customize(cell,data) {
if(data.isGrandTotalRow) {
cell.text = data.value / (data.rowIndex - 1);
}
}
</script>
</body>
</html>

Related

Embedded Vega is missing tooltips

I have the following JSFiddle, demonstrating a small Vega Bar chart:
<head>
<script src="https://cdn.jsdelivr.net/npm/vega#5"></script>
</head>
<body>
<div id="view"></div>
<script type="text/javascript">
var view;
var chart = { Vega code removed for brevity - please check JSFiddle}
render(chart);
function render(spec) {
view = new vega.View(vega.parse(spec), {
renderer: 'canvas', // renderer (canvas or svg)
container: '#view', // parent DOM container
hover: true // enable hover processing
});
return view.runAsync();
}
</script>
</body>
If you copy the vega object into Vega Editor you get a tooltip when hovering over the chart elements.
Within the JSFiddle there is no tooltip.
Could someone please help me get a tooltip in the HTML-embedded version?
I have been able to get the full functionality through using vega-embed with versions listed below:
<!DOCTYPE html>
<html>
<head>
<script src="vega-5.17.3.min.js"></script>
<script src="vega-lite-4.17.0.min.js"></script>
<script src="vega-embed-6.15.0.min.js"></script>
</head>
<body>
<div id="vis"></div>
<script type="text/javascript">
var spec = { Vega code removed for brevity - please check JSFiddle}
vegaEmbed('#vis', spec).then(function(result) {
}).catch(console.error);
</script>
</body>
</html>

Sgvizler: Create empty table for empty result

When I create a sgvizler.visualization.Table with Sgvizler 0.6 and the SPARQL query has no results, Sgvizler doesn't draw anything, not even the table header. This may confuse users who may think that the result is still being calculated or that the script has crashed. How can I configure Sgvizler to draw the table header even when the result is empty?
Minimum Working Example
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://mgskjaeveland.github.io/sgvizler/v/0.6/sgvizler.js"></script>
<script>
sgvizler
.defaultEndpointURL("https://dbpedia.org/sparql")
.defaultChartFunction("sgvizler.visualization.Table")
.defaultChartWidth(1000);
$(document).ready(function (){ sgvizler.containerDrawAll(); });
</script>
</head>
<body>
<h2>First Table</h2>
<div id="results"
data-sgvizler-query="
select distinct ?class
{
?class rdfs:subClassOf dbo:Animal.
}
">
</div>
<h2>Second Table</h2>
<div id="noresults"
data-sgvizler-query="
select distinct ?class
{
?class rdfs:subClassOf dbo:Unicorn.
}
">
</div>
</body>
</html>
This is a bug in the parser, which looks only at the first row of results to build the JSON accepted by the google.visualization.DataTable object.
The solution would be to rewrite the parser to check the "column headers" of the SPARQL result set.
The parser is here: https://github.com/mgskjaeveland/sgvizler/blob/master/src/parser.js

Dynamic ID in XML view

Experts,
I need to declare an dynamic ID into a XML view in my extended Fiori app. I need this because I need to set an image src based on Item value.
Is there a way to do something like this?
<Image id="myImage{MyModelProperty}" />
Regards,
Andre
The calculated field will serve your requirement.
1.Set the flag in bootstrap configuration data-sap-ui-xx-bindingSyntax="complex". Details is here
2.Define a formatter function in your controller js.
imageFormatter : function(value) {
var imageSrc = "myImage" + value;
return imageSrc;
}
3.Declare the Image in the XML view as following
<Image src="{path:'MyModelProperty',formatter:'.imageFormatter'}"/>
Hope it will solve your issue.
As far as I know IDs can not be built from model properties.
Why do you want to build the ID of the image instead of it's src property?
If you want to make sure the uniqueness of image ID, then just let the framework to handle it.
If you use the src property with model binding, changes of the underlying model property will take effect on the UI immediately. Just call the setProperty("MyModelProperty", "new_image_postfix") on your model instance.
Short example with a button and it's text binding:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.ui.commons"
data-sap-ui-theme="sap_goldreflection">
</script>
<script type="text/javascript">
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({txt: "Sample"});
sap.ui.getCore().setModel(oModel);
var oButton = new sap.ui.commons.Button({id:"testBtn", text:"{/txt}", press:function(oEvent) { oModel.setProperty("/txt", "SampleUpdated") } });
oButton.placeAt("content");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>

Hide a row (aka series) in Google chart

Is there please a possibility to blend out (hide) a line in Google Line Chart?
We have many line charts with multiple series of close data values and my boss asks me to add a way to hide a series (preferably by clicking the line or the legend with a mouse).
I have added a select event listener to my very simple test case below (just open it in a browser and it will work), but I'm not sure what to do next:
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}"></script>
<script type="text/javascript">
var data = {"L_B8_ACLR_50_0_QPSK_1_H":{"rows":[
{"c":[{"v":"UTRA_1_DOWN"},{"v":-42.9},{"v":-42.4},{"v":-80},{"v":-35}]},
{"c":[{"v":"E-UTRA_1_DOWN"},{"v":-49.4},{"v":-39.9},{"v":-80},{"v":-32}]},
{"c":[{"v":"E-UTRA_1_UP"},{"v":-48.9},{"v":-48.6},{"v":-80},{"v":-32}]},
{"c":[{"v":"UTRA_1_UP"},{"v":-49.5},{"v":-49.4},{"v":-80},{"v":-35}]},
{"c":[{"v":"UTRA_2_UP"},{"v":-58.9},{"v":-58.9},{"v":-80},{"v":-38}]}],
"cols":[{"p":{"role":"domain"},"label":"MEASUREMENT","type":"string"},
{"p":{"role":"data"},"label":"Row A","type":"number"},
{"p":{"role":"data"},"label":"Row B","type":"number"},
{"p":{"role":"interval"},"label":"LSL","type":"number"},
{"p":{"role":"interval"},"label":"USL","type":"number"}]}};
function drawCharts() {
for (var csv in data) {
var x = new google.visualization.DataTable(data[csv]);
var options = {
title: csv,
width: 800,
height: 600
};
var chart = new google.visualization.LineChart(document.getElementById(csv));
google.visualization.events.addListener(chart, 'select', selectHandler);
chart.draw(x, options);
}
}
function selectHandler(e) {
alert('How to hide a row in the chart?');
}
$(function() {
google.setOnLoadCallback(drawCharts);
});
</script>
</head>
<body>
<div id="L_B8_ACLR_50_0_QPSK_1_H"></div>
</body>
</html>

html2canvas for html page with multiple images from same source

I have multiple images in an html page.I want to use html2canvas to convert the page to image.The images are local and from same source.It always keep on showing the error msg " Unable to get image data from canvas because the canvas has been tainted by cross-origin data."
The same code will work for one image or multiple copy of same image.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="language" content="de">
<script type="text/javascript" src="./js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/html2canvas.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var target = $('#mainDiv');
html2canvas(target, {
onrendered: function(canvas) {
var data = canvas.toDataURL();
var img = document.getElementById('img1');
img.src = data;
}
});
});
</script>
</head>
<body>
<div id="mainDiv">
<div id="div1" ><p>paragraph 1 paragraph 1 paragraph 1 paragraph 1 paragraph 1 paragraph 1 paragraph 1 paragraph 1 </p></div>
<div id="div2" ><p>paragraph2 paragraph2 paragraph2 paragraph2 paragraph2 paragraph2 paragraph2 paragraph2 </p></div>
<img src="images/01.jpg" >
<img src="images/02.jpg" >
<img src="images/03.jpg" >
<img src="images/04.jpg" >
</div>
<img id="img1"></img>
</body>
</html>
I am not sure what does the error message mean.Also if somebody can tell me how do i make this work with multiple images, it will be very helpful
just remove what you dont need. ie, i have Div1,Div2 etc
function PrintChartCanvas(divId) {
//div canvas
var divObj = html2canvas($('#div' + divId));
var divQueu = divObj.parse();
var divCanvas = divObj.render(divQueu);
divImg = divCanvas.toDataURL();
return divImg;
}
document.getElementById("img1").src = PrintChartCanvas(3);
This should work