Question

I'm trying to create pyramid chart similar to this http://www.highcharts.com/demo/pyramid in rCharts, however it gives me an error even though the output looks fine

h1 <- Highcharts$new()
h1$chart(type = "pyramid")
h1$series(name='Unique users', data=list(
  list('Website visits',   15654),
  list('Downloads',       4064),
  list('Requested price list', 1987),
  list('Invoice sent',    976),
  list('Finalized',    84)
  ))

Here is an output

(function ($) {
    $(function () {
        var chart = new Highcharts.Chart({
            "dom": "chartee4502dd16c",
                "width": 800,
                "height": 400,
                "credits": {
                "href": null,
                    "text": null
            },
                "exporting": {
                "enabled": false
            },
                "title": {
                "text": null
            },
                "yAxis": {
                "title": {
                    "text": null
                }
            },
                "chart": {
                "type": "pyramid",
                    "renderTo": "chartee4502dd16c"
            },
                "series": [{
                "name": "Unique users",
                    "data": [
                    [
                        "Website visits",
                    15654],
                    [
                        "Downloads",
                    4064],
                    [
                        "Requested price list",
                    1987],
                    [
                        "Invoice sent",
                    976],
                    [
                        "Finalized",
                    84]
                ]
            }],
                "id": "chartee4502dd16c"
        });
    });
})(jQuery);

Am I doing a mistake somewhere or is pyramid chart just not supported by rCharts? Thanks.

Was it helpful?

Solution

@Ondkloss is right on the money here. All that you need to do is to add the funnel script to your page. There is a quick and easy way to do that in rCharts without hacking at config.yml. You can use the addAssets method to inject a javascript asset in the head.

library(rCharts)
h1 <- Highcharts$new()
h1$addAssets(jshead = "http://code.highcharts.com/modules/funnel.js")

Now run the same code you ran previously and you should get a nice pyramid chart.

h1$chart(type = "pyramid")
h1$series(name='Unique users', data=list(
  list('Website visits',   15654),
  list('Downloads',       4064),
  list('Requested price list', 1987),
  list('Invoice sent',    976),
  list('Finalized',    84)
))

h1

Here is the final version of the chart. You can click here fpr a version that is editable online.

OTHER TIPS

From the Highcharts API (and as included in your demonstration) a Pyramid chart is "a reversed funnel chart without a neck", and a Funnel chart "requires that the modules/funnel.js file is loaded".

Judging from the config.yml for the Highcharts library in rCharts that specific module is not included:

highcharts:
  jshead:
    - js/jquery-1.9.1.min.js
    - js/highcharts.js
    - js/highcharts-more.js
    - js/exporting.js
  cdn:
    jshead:
      - "http://code.jquery.com/jquery-1.9.1.min.js"
      - "http://code.highcharts.com/highcharts.js"
      - "http://code.highcharts.com/highcharts-more.js"
      - "http://code.highcharts.com/modules/exporting.js"

There's not much between you and a modified rCharts to make it happen though, if you so desire.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top