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

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…