Time for a new graph/chart library in Moodle?

Time for a new graph/chart library in Moodle?

by Joseph Rézeau -
Number of replies: 32
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi all,

Currently, Moodle uses a fairly old and limited graphlib (Graph Class. Version: 1.6.3 * Copyright (C) 2000  Herman Veluwenkamp).

In my current efforts at introducing the new "Personality Test" feature into the Questionnaire plugin, I wanted to output some results as a radar chart, and others as a "bi-polar" chart. I came across the pChart library, which does exactly what I want. See examples below.

pChart is already used in some Moodle (3rd-party) plugins. It is also used by the current version of LimeSurvey (v. 2). On the LimeSurvey site there is an interesing Comparison of different charting libraries, although it dates back to 2009.

I was wondering if there are any plans to update the graph/chart library included in Moodle to something more current and powerful.

Joseph

Here are 2 examples of output done with pChart and the Questionnaire module (WIP new features).

 

Attachment 08-01-2013 14-34-40.jpg
Average of ratings: Useful (4)
In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Tomasz Muras -
Picture of Core developers Picture of Plugin developers Picture of Plugins guardians Picture of Translators

What a timing - I was just reviewing PHP chart libriaries - and I've ended up with the same - pChart.

It looks like the best option out there but there are few things I didn't like about it:

1. The development is not open - or at least I didnt' find any public version control system with the code (the official one).
2. There is no community around the project - or if there is, it's buried deep down under all the spam - see the pchart forum.

Technically though, it looks like the best PHP charting library out there.

cheers,
Tomek

In reply to Tomasz Muras

Re: Time for a new graph/chart library in Moodle?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Tomasz,

I agree with all you have found out.

For as much as I've used it, it looks like an excellent library, with lots of features.

Unfortunately it does not seem to be actively maintained, and the forum is at the moment over-flooded with spam.

But I notice that after weighing pros and cons, LimeSurvey has decided to keep it in ther latest current version. If the Moodle community is interested, it might be worth trying to approach the developer and see how things look for the future of this library.

Joseph

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Bernard Boucher -

Bonjour Joseph,

                        personally I have started to integrate RGraph with my Moodle work.

It is based on html5 and javascript, meaning that the client machine instead of the server do the processing for creating the charts. Another great debate to have wink

As you suggest it is Time for a new graph/chart library in Moodle server or client side!

Bernard

 

 

In reply to Bernard Boucher

Re: Time for a new graph/chart library in Moodle?

by Danny Wahl -

only "downside" I see to rgraph is it's jQuery powered.  Notice that "downside" is in quotes only because I don't consider jQuery bad...

Average of ratings: Useful (1)
In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Totally agree that we need to decide on this for 2.5.

I'd appreciate if you guys here could consider yourselves a task force and come up with a good recommendation for us to put in core.

Needs to be GPL-compatible obviously, and I would suggest focussing on HTML5 solutions just because of the flexibility and taking load off the server,

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Further to Bernard's suggestion I have started experimenting with RGraph which uses HTML5 and JavaScript. It looks more "dynamic" than PHP-based PChart and is actively maintained.

I also found that, for my so-called "Personality test" Questionnaire needs, both the "rose" and "bi-polar" libraries provided excellent results, see attached.

However, as pointed by Danny Wahl, RGraph uses JQuery, which is not the library of choice in Moodle. I have no idea how far this is a problem.

Where should we go from here? Anyone interested try out various Graph libraries and post their findings in this thread or should a proper bug report be started or what?

Joseph

Attachment 14-01-2013 22-51-36.jpg
Average of ratings: Useful (3)
In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Danny Wahl -

However, as pointed by Danny Wahl, RGraph uses JQuery, which is not the library of choice in Moodle. I have no idea how far this is a problem.

I really don't want to ruffle feathers - but I would hope that "picking the right tool" would prevail over "not using jQuery".  To that end, Moodle has already included jQuery in core (mymobile theme) and the new Moodle Mobile app is built on jQuery, so maybe there's a case and a methodology to include jQuery in core - but only call it when YUI can't do (reasonably) what's being attempted.

That would make it easier for contrib authors to use jQuery in a non-conflict mode too (maybe $PAGE->requires->js('/lib/jQuery.js');)

I'm really not trying to start the "why doesn't Moodle use jQuery" argument again...

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Ankit Agarwal -

And also just for comparision, I would also like to recomend yui3 charts, they seem pretty flexible, simple to use and with all the basic features that we can need.

In reply to Ankit Agarwal

Re: Time for a new graph/chart library in Moodle?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Ankit,

The examples of yui3 charts I have found so far do not provide radar or "rose" or "bi-polar" charts similar to the 2 charts I posted here on Monday, 14 January 2013, 10:58 PM.

Can you please point to examples of those chart types for yui3 on the Internet?

Joseph

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Ankit Agarwal -

I haven't looked in detail all the possible charts that are supported by yui3.  I just wanted to get it out there for consideration as well basically because:-

# Chart generation will be done on client side

# Long upstream support assured

# Yui3 libraries are already in place in moodle.

There are some dual axis support as well, but havent played with it much http://yuilibrary.com/yui/docs/charts/charts-dualaxes.html

From memory there is some series support as well but afaik they might not support such complex radar chart types etc.

In reply to Ankit Agarwal

Re: Time for a new graph/chart library in Moodle?

by Darko Miletić -
Picture of Core developers Picture of Plugin developers

YUI chart sucks because it does not output chart as image. YUI2 uses flash and YUI3 SVG. Hence it is virtually impossible to export those to image and generate static report in PDF or something else. Any new chart library must have that otherwise it is fairly useless.

In reply to Darko Miletić

Re: Time for a new graph/chart library in Moodle?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Darko,

RGraph does output images (in *.png format). Also, from what I have seen, the types of charts that YUI produces are fairly limited.

The more I conduct my tests with RGraph, the more I like it. Anyone else?

Joseph

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Damyon Wiese -

Rgraph is not GPL,

It is Creative Commons Attribution Non-Commercial which is incompatible with the GPL (http://www.gnu.org/licenses/license-list.html#ccby). 

We would have to contact the copyright owner and get them to relicense. 

 

In reply to Damyon Wiese

Re: Time for a new graph/chart library in Moodle?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Damyon,

Thanks for this important piece of information. What is our next move, then? Are Moodle HQ ready to approach RGraph?

Joseph

In reply to Damyon Wiese

Re: Time for a new graph/chart library in Moodle?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Damyon (and others in this discussion),

Just noticed that RGraph is now released under the MIT license. Does this make it an "acceptable" chart library for inclusion in Moodle core?

I am planning to use RGraph in the Questionnaire module for its 2.6.3 version to be released any time soon.

I really wish Moodle HQ made up their minds to include a more current chart library (in moodle 2.7). Anyone interested please vote for MDL-35686.

Joseph

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Hubert Chathi -

FWIW, pChart 2 has an odd license.  According to the licensing page, if your application is non-commercial, then you can use the GPL 3 license.  If your application is commercial, then you need to pay for a license, even if your application can be distributed under the GPL.  AFAIK, this in unenforcable, because you could just get some non-commercial entity to redistribute the library to you under the terms of GPL 3, but it would go against the author's wishes.

pChart 1 is just straight GPL, but of course isn't developed any more.

As far as choosing a graphing library, one big decision is whether we want the rendering to be done in the browser via JavaScript, or on the server (or both).  Both have their advantages and disadvantages:

Rendering in the browser:

  • means that you can have more interactive graphs more easily (e.g. mouse-over data points to see their values, zoom in/out)
  • doesn't work if JavaScript is disabled, or in old browsers
  • doesn't work for PDF exports

Rendering on the server:

  • means you need to serve an image file separate from the HTML file, which means you either need to generate the image on-the-fly (which may mean executing the same query twice), or caching
  • is more compatible (doesn't need JavaScript, canvas, flash, SVG, etc; works for PDF exports)

As far as making a PDF export, is it sufficient to just use a bitmap image, or do you want it to be a vector image?  (AFAIK, since pChart is tied to GD, it can only create a bitmap, and the same is true for most of the graphing libraries I've seen.)

In reply to Hubert Chathi

Re: Time for a new graph/chart library in Moodle?

by Damyon Wiese -

Rendering in the browser != doesn't work for exports. It would just need to be factored in - you can render a canvas element to a png with javascript.

var canvas = document.getElementById("mycanvas");
var img = canvas.toDataURL("image/png");
In reply to Damyon Wiese

Re: Time for a new graph/chart library in Moodle?

by Hubert Chathi -

I'm not sure if I understand what you're trying to say here. Are you suggesting that you render the graph in the browser, export it to a PNG data URL, send that back to the server, and then have the server combine it into the PDF?  That seems like an odd way of doing things, and of course doesn't work if there is no browser involved (e.g. if you want to produce a PDF in a cron or web service call).

In reply to Hubert Chathi

Re: Time for a new graph/chart library in Moodle?

by Damyon Wiese -

No - I'm suggesting we can produce printable HTML versions of the reports (not PDF).  

Agree - this doesn't work for reports generated by cron.

 

In reply to Hubert Chathi

Re: Time for a new graph/chart library in Moodle?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hubert "As far as making a PDF export, is it sufficient to just use a bitmap image, or do you want it to be a vector image?"

Which Moodle activities currently need to output PDF exports?

Joseph

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Hubert Chathi -

I'm not aware of any activities in Moodle core that do PDF exports (nor am I aware of anything in Moodle core that generates PDFs in a cron, which I talk about in another post).  I'm just pointing out things to consider, should the functionality ever be needed later.  It is also done in some addons (e.g. Remote Learner's ELIS, which, I should note, uses pChart 1 (at least at the time that I was there), and, IIRC, just just embeds a bitmap image in the PDF).

In reply to Hubert Chathi

Re: Time for a new graph/chart library in Moodle?

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The book module (core from 2.4 onwards) does PDF export.

In reply to Davo Smith

Re: Time for a new graph/chart library in Moodle?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Davo,

Looking at the Book module on Moodle 2.4.1+ (Build: 20130118) I do not see any "PDF export" setting.

Joseph

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sorry - I take it back. It must have been a custom version of the plugin we did for a client (where I'd forgotten it wasn't standard functionality when I was asked to tweak it a bit).

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Darko Miletić -
Picture of Core developers Picture of Plugin developers

None of the core activities export PDF but few of contributed plugins do that and in the commercial module area it is rather frequent request from the clients. So having a chart library that can generate image in the server is really important. Relying on canvas and HTML5 is something too far in the future. Lots of institutions are still stuck on IE8.

In reply to Joseph Rézeau

Vastus: Time for a new graph/chart library in Moodle?

by Tõnis Tartes -

What about Google Charts integration? 

https://developers.google.com/chart/

In reply to Tõnis Tartes

Re: Vastus: Time for a new graph/chart library in Moodle?

by Simey Lameze -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Would be nice implement the Google charts library on moodle, unfortunatelly it's not possible to download and use it offline, making this a blocker for users from China, for example.
I've created the Report Graphic plugin (https://moodle.org/plugins/view/report_graphic) which read the logs and generate graphics using google charts.  

I've bumped the priority of the https://tracker.moodle.org/browse/MDL-35686 so we can discuss about that.

Thanks.

In reply to Simey Lameze

Re: Vastus: Time for a new graph/chart library in Moodle?

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

I am not keen on anything that embeds dependency on a major corporation or constant internet connectivity, and potentially excludes 1.4 billion of the worlds population.

In reply to Joseph Rézeau

Re: Time for a new graph/chart library in Moodle?

by Simey Lameze -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hello all, the time for the new chart library has arrived!

On the road map for Moodle 3.2 we had the mission of find a new charting library, create an Chart API that was easy to work and replace existing existing charts. Our previous library (Graphlib) was outdated. The generated graphs were not dynamic and the API was very complex, being really hard to create a new chart. 

We have investigated many libraries, such: Chart.js, Highcharts, CanvasJS, Chartist, n3, Google Charts, Flot/jQuery, D3, Plotly.js/D3, C3/D3, nvd3/D3, dimple-js/D3, dc-js/D3, metricsgraphicsjs/D3 and ECharts.

We’ve choosen Chart.js considering its popularity (Github stars, contributors, Stackoverflow questions), license, maturity, and relative simplicity to create new charts.

The new library and the new core_chart is already integrated on moodle 3.2 master branch and more information can be found on https://tracker.moodle.org/browse/MDL-54987.

Any feedback and suggestions are very welcome.

In reply to Simey Lameze

Re: Time for a new graph/chart library in Moodle?

by Dan Poltawski -

Hi Simey,

(I am sure its coming, but) It would be great to have some dev docs on the basics (maybe with some 'hello world style' examples) - so people know how to start using them smile