I don’t know if this is the right approach… I’d like to include a Dashboard in our solution (only webclient) with a lot of amazing charts. VelocityReport plugin uses an old API from Google to create charts, so I’m thinking about using Velocity Web Client to create pages with these charts (using new Google API). If it is the better way, How can I integrate that page into my solution?
Are you talking about creating reports? In that case you cannot use the new Google charts API because it’s HTML5 or Flash based, meaning it’s dynamic. And you want a fixed image to embed in your report.
Or are you talking about adding it in Servoy Web Client? In which case you could go the route David is talking about (or embed the google charts JS files using the web client utils as well)
If you are talking about a web site constructed with Velocity, then you are free to embed any JS libraries including charting libraries… Just put them in your template. Then pass the init parameters of your charts dynamically in your context object when you return a plugins.Velocity.createResponse(context)
I’ve tested several approaches… I want to use Google Charts API, and, in my opinion, the best option is using web client utils to add required js files and putting a html area with js code to drawing the charts.
juan.cristobo:
I’ve tested several approaches… I want to use Google Charts API, and, in my opinion, the best option is using web client utils to add required js files and putting a html area with js code to drawing the charts.
Thanks!
Regards,
Did it work? If so, can you contribute your code to SOS and the how-to-do to ServoyForge?
You can assign the remaining code to ‘chart’ variable, but I prefer to do it this way (this is the complete code for onShow method):
function onShow(firstShow, event)
{
plugins.WebClientUtils.addJsReference('https://www.google.com/jsapi');
var datasource = [
['Topping', 'Slices'],
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
];
var chartOptions = {
'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300
};
chart = '<script type="text/javascript">\
google.load("visualization", "1.0", {"packages":["corechart"]});\
google.setOnLoadCallback(drawChart);\
function drawChart() {\
var data = new google.visualization.arrayToDataTable(' + JSON.stringify(datasource) + ');\
var options = ' + JSON.stringify(chartOptions) + ';\
var chart = new google.visualization.PieChart(document.getElementById("chart_div"));\
chart.draw(data, options);\
}\
</script>\
<div id="chart_div"></div>';
}
As you can see, I define the values and the chart options as variables in Servoy code and then 'inject" them using JSON.stringify, I think that the code is very clear. Of course, you can populate ‘datasource’ array with data from Servoy.
I think you’ll need to be a Contributor of the project (VelocityReport) to post something within. But, you also can create a new project and call it ‘Charts with Velocity Web Client’ module. If you want, send me the solution you already created and I’ll add it to ServoyForge on your behalf.
juan.cristobo:
But this has nothing to do with Velocity.
Of course, you can use Velocity Web Client, but I only use Servoy forms, web client and Web Client Plugin for embed js libraries.
Regards,
I see. Then you can just create a new project in ServoyForge. Call it something like ‘Charts with the Web Client Plugin’ module. Just post the example solution and the explanation you already typed. It’s all good.