I'm using Google Charts to display a SCATTER chart and the vAxis title is not displayed.
When I go on my chart graphic editor, I can see that my hAxis title is set but vAxis not.
For testing you can try with this simple code that reproduced the problem :
function test1() {
var app = SpreadsheetApp;
var classeur = app.getActiveSpreadsheet();
var sheet = classeur.getActiveSheet();
var range = sheet.getRange("A1:B7");
var data = [
['Age', 'Weight'],
[ 8, 12],
[ 4, 5.5],
[ 11, 14],
[ 4, 5],
[ 3, 3.5],
[ 6.5, 7]
];
range.setValues(data);
var chart = sheet.newChart()
.setChartType(Charts.ChartType.SCATTER)
.addRange(range)
.setPosition(5, 5, 0, 0)
.setOption('title','title')
.setOption('width', 300)
.setOption('height', 400)
.setOption('hAxis', {title: 'labelX'})
.setOption('vAxis', {title: 'labelY'})
.build()
sheet.insertChart(chart);
}
Thanks in advance for your help !
Related
I have an html table defined based on dynamic data. The table contains a thead, tfoot and tbody. The tfoot is mapped to specific values within my json. However, when using JSPDF Autotable and exporting to PDF the footer is not rendered. I have seen information but no code examples of the showfoot option and have tried it after the doc.autotable, and even after the style options but to no avail. The footer is not exported. I'm sure it super simple - but I can't seem to figure it out. Note: I do not want JSDPF Autotable to 'create' a footer - it is defined, it is part of my table - I simply want it rendered on the pdf. I found an old stackoverflow from 2016 where this was mentioned - Simon B. commented it would be added - the topic was closed - but I couldn't find a code example anywhere.
Here is my jspdf autotable code where I have tried to 'show my footer' - but to no avail. Any assistance appreciated.
<script>
function generate() {
//Creation of PDF document
let doc = new jsPDF('l', 'pt');
const totalPagesExp = '{total_pages_count_string}';
var elem = document.getElementById('${pm.info.requestId}');
var data = doc.autoTableHtmlToJson(elem);
doc.autoTable(data.columns, data.rows, {
headStyles: {
cellWidth: 'wrap',
fontSize: 10,
lineWidth: 0,
lineColor: [0, 0, 0],
textColor: [0, 0, 0],
fillColor: [255,255,255]
},
bodyStyles: {
cellWidth: 'wrap',
fontSize: 8,
lineWidth: 0,
lineColor: [0, 0, 0],
textColor: [0, 0, 0],
fillColor: [255,255,255]
},
footStyles: {
cellWidth: 'wrap',
fontSize: 10,
lineWidth: 0,
lineColor: [0, 0, 0],
textColor: [0, 0, 0],
fillColor: [211,211,211]
},
//Formatting of pages
didDrawPage: function (data) {
//Summa logo on top of the page
doc.addImage('${pm.variables.get("summa")}', 'PNG', 20, 20, 145, 42.63);
//Font sizes of report information
doc.setFontSize(8);
//Report information: portfolio name, knowledge time and report time
doc.text(35, 75, '${pm.variables.get("portfolioName")}');
doc.text(35, 85, '${pm.variables.get("reportTime")}');
doc.text(35, 95, '${pm.variables.get("knowledgeTime")}');
//Page numbers
var str = "Page " + doc.internal.getNumberOfPages()
if (typeof doc.putTotalPages === 'function') {
str = str + " of " + totalPagesExp;
};
//Page size
var pageSize = doc.internal.pageSize;
var pageHeight = pageSize.height ? pageSize.height : pageSize.getHeight();
doc.text('Theme "plain"', 14, 16);
},
margin: {
top: 100
},
});
//Number of pages
if (typeof doc.putTotalPages === 'function') {
doc.putTotalPages(totalPagesExp);
},
//--------------------------------------------------------------------------------------------------START
//Change name of report if desired
doc.save('${pm.info.requestName}${pm.variables.get("reportTime")}.pdf');
//--------------------------------------------------------------------------------------------------END
}
Not sure if you already managed to export footer totals to the jspdf. I got it to working, with a small adjustment.
Replace the var elem = document.getElementById('${pm.info.requestId}'); to var elem = document.getElementById('NAME');
And replace the doc.autoTable(data.columns, data.rows, { to doc.autoTable({html: '#NAME',
I'm using Highcharts and initializing the data using;
var graph = Highcharts.chart('container', {
................
series: [{
color: 'red',
data: [[5, 2], [800, 2], [801, 1],[802, 3],[803, 2],[804, 2],[1200, 3]]
},
.............
}
The problem I have is when I want to add more data dynamically, after rendering the initial chart.
In this case I'm using the update;
graph.update(
{
series: [{
color: 'blue',
data: [[100, 2], [101, 2], [102, 1] ]
},
});
And this works but it replaces the entire data set.
So, how should I use the update() function to add points and not replace them?
I saw people are using other functions such as addPoint() and setData() but I couldn't make them work properly...
Thanks in advance
Gus
Refer to this live demo: http://jsfiddle.net/kkulig/opr4Lgpe/
I add all the points in a loop. redraw argument (second one) of the addPoint function is set to false - there's no need to redraw the chart after each addition. The redraw is performed only once in the end.
var chart = Highcharts.chart('container', {
series: [{
data: [1, 2]
}]
});
var pointsToAdd = [4, 5, 6, 6, 7];
pointsToAdd.forEach(function(p) {
chart.series[0].addPoint(p, false);
});
chart.redraw();
API reference:
https://api.highcharts.com/class-reference/Highcharts.Series#addPoint
I am trying to use the plotting library JSXGraph from Dart using dart js but I have problems.
This is working javascript code
var board = JXG.JSXGraph.initBoard(
'box',
{
boundingbox: [-10, 10, 2, -1],
axis: true,
keepaspectratio: false,
showNavigation: false
}
);
var graph = board.create(
'functiongraph',
[function(x){ return 3*x*x + 5*x + 1;}, -10, 10],
{strokeColor: '#ffff00'}
);
You can try it here on jsFiddle.
I want to do basically the identicall thing but from dart. This is what I have come up with so far:
JsObject jsxGraph = context['JXG']['JSXGraph'];
var board = jsxGraph.callMethod('initBoard', [
'box',
new JsObject.jsify({
'boundingbox': [-10, 10, 2, -1],
'axis': true,
'keepaspectratio': false,
'showNavigation': false
})
]);
var graph = board.callMethod('create', [
'functiongraph',
[(x){return 3*x*x + 5*x + 1;}, -10, 10],
new JsObject.jsify({'strokeColor': '#ffff00'})
]);
I get the plot area and axes but I can't get the actual plot line. Instead, there is an error on the console: Uncaught TypeError: this.Y is not a function.
Could someone, please, point me to what I could be doing wrong? I suspect it is something about the callback function but I really don't know what.
There's a jsify missing in your code:
JsObject jsxGraph = context['JXG']['JSXGraph'];
var board = jsxGraph.callMethod('initBoard', [
'box',
new JsObject.jsify({
'boundingbox': [-10, 10, 2, -1],
'axis': true,
'keepaspectratio': false,
'showNavigation': false
})
]);
var graph = board.callMethod('create', [
'functiongraph',
new JsObject.jsify([(x){return 3*x*x + 5*x + 1;}, -10, 10]},
new JsObject.jsify({'strokeColor': '#ffff00'})
]);
I just included the Flot plugin and tried running the sample as mentioned in the documentation.
As per the documentation, the index page looks like this
class FlotController {
def index = {
[data: [[0, 10], [4, 5], null, [6, 2.5], [12, 10]]]
}
}
When rendered in GSP, it
var d4 = \u005b\u005b0\u002c 10\u005d\u002c \u005b4\u002c 5\u005d\u002c null\u002c \u005b6\u002c 2.5\u005d\u002c \u005b12\u002c 10\u005d\u005d;
what is the correct way to define data in the Controller? Thanks
The javascript is as shown below
<g:javascript>
var d1 = [];
for (var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];
var d4 = ${raw(data)}; //line causing the problem
var data = [d1, d2, d3, { label: "server data", data: d4}];
var options = { lines: { show: true }, points: { show: true } };
var d5 = [];
var series = Math.floor(Math.random()*10)+1;
for( var i = 0; i < series; i++) {
d5[i] = { label: "Series"+(i+1), data: Math.floor(Math.random()*100)+1 }
}
var pieOptions = { series: { pie: { show: true } }, legend: { show: false } };
</g:javascript>
EDIT (with the good answer):
For those who have the resources plugin, you need to replace :
<g:javascript></g:javascript>
by
<r:script>...</r:script>
And it works (with or without the function raw()
Previous answer:
In your GSP, you can use the raw() function.
More information here: documentation
But watch out:
"So what happens when you want to stop Grails from escaping some content? There are valid use cases for putting HTML into the database and rendering it as-is, as long as that content is trusted. In such cases, you can tell Grails that the content is safe as should be rendered raw, i.e. without any escaping:"
how to use double click get the Category, name, y of a line of a line chart?
i tries use customEvents plugin.
but i don't know get those data in line chart
in the column chart, i use below code is okay.
series: [{
name: 'John',
data: [5, 3, 4, 7, 2],
point: {
events: {
dblclick: function(e) {
var c = this.point.category;
var y = this.point.options.y;
var n = this.point.series.name;
}
}
}
}
I updated the plugin, so please check if all works as you expect.