Plot JSON-data

Together with the Plugin “WordPress Charts” the PRO version of the JSON Content Importer can plot data in many ways.

Example: https://api.wordpress.org/stats/plugin/1.0/downloads.php?slug=json-content-importer&limit=51 gives us the latest 50 numbers of the downloads of the free JCI plugin. The challenge is to display that data like this

Downloads of the free JSON Content Importer Plugin: Daily statistic of the last 50 days
[wp_charts title=”JCIDownloads” type=”line” colors=”#f00,#0f0,#00f,#96CE7F,#CEBC17,#CE4264″ width=”100%” datasets=”81,131,108,123,127,91,67,78,110,96,96,107,84,55,63,102,104,86,86,88,41,55,60,86,88,62,68,51,45,68,85,97,75,67,49,42,98,104,71,78,68,62,44,84,82,78,74,65,34,44,57″ labels=”1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51″ ]

For that we have to do this:

Install:
WordPress Charts

Create a new JCI-pro-template with:

url=https://api.wordpress.org/stats/plugin/1.0/downloads.php?slug=json-content-importer&limit=51

twig-code:

<a href="https://wordpress.org/plugins/json-content-importer/" target="_blank">Downloads of the free JSON Content Importer Plugin:</a> <a href="https://api.wordpress.org/stats/plugin/1.0/downloads.php?slug=json-content-importer&limit=51" target="_blank">Daily statistic of the last 50 days</a><br>{%set no = 0 %}
{% for dat,nodl in _parent %}{%set no = (_parent | length)-1 %}{% endfor %}
[wp_charts title="JCIDownloads"  type="line" colors="#f00,#0f0,#00f,#96CE7F,#CEBC17,#CE4264" width="100%" {% set lab = "" %}{% set  ds = "" %} {% for dat,nodl in _parent %}
{% set  del = "" %} {%if loop.index < no %}{% set  del= "," %}{% endif %} {%if loop.index <= no %}
{% set ds = ds~ nodl ~ del %}
{% set lab = lab ~ loop.index ~ del %}
{% endif %}
 {% endfor %} datasets="{{ds}}" labels="{{lab}}" ]

Save that template and use it on a page by [jsoncontentimporterpro id=ID_OF_TEMPLATE ]

That’s it…