• Great plugin, martynasma, really great.

    I am trying to set a really simple widget, starting from the default “Zooming to Countries Map”, which will have next to each country name the count of posts published for that country (the categories are the country names, I have a travel blog :)).

    I am trying to include some PHP code to dynamically get the post count by category, but actually I don’t know if it’s possible to add php code in it, since neither the simplest echo uses to work, as you can see in my code below:

    var map = AmCharts.makeChart("chartdiv", {
    	"type": "map",
            "theme": "none",
    	"pathToImages": "http://www.amcharts.com/lib/3/images/",
    
    	"dataProvider": {
         "map": "worldLow",
         "getAreasFromMap": true,
          "areas": [{"id": "US","title":"United States ("+<?php echo '16' ?>+")"}]
    	},
    	"areasSettings": {
    		"autoZoom": true,
          	"color": "#0063be",
          	"rollOverColor": "#ffb511",
    		"rollOverOutlineColor": "#ffffff",
          	"selectedColor": "#ffb511",
          	"outlineThickness": 2
    	},
    	"smallMap": {}
    });

    Could you please help me to achieve what I need?

    Thank you

    https://ww.wp.xz.cn/plugins/amcharts-charts-and-maps/

Viewing 1 replies (of 1 total)
  • Plugin Author martynasma

    (@martynasma)

    Hi there.

    Sorry for not getting back to you. Somehow I missed your post.

    No, you can’t use PHP code in the chart’s code. That would be extremely insecure.

    One solution would be to add a code to your theme or some custom plugin that would output your data as a JavaScript. I.e. it could produce something like that:

    <script>
    var counts = {
      "US": 16
    };
    </script>

    Then your map code could refer to this variable:

    "areas": [{
      "id": "US",
      "title":"United States ("+ counts["US"] +")"
    }]

    I hope this helps.

Viewing 1 replies (of 1 total)

The topic ‘PHP function into the main Javascript’ is closed to new replies.