Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet"/>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.1.1/Chart.min.js"></script>


<table>
  
  <tr>
    <td><div class="pivot-container">
<div id="wdr-component"></div>
</div></td>
        <td><div class="chart-container">
    <canvas id="polar-chart"></canvas>
</div></td>
  </tr>
</table>



              
            
!

CSS

              
                .chart-container {
  position: relative;
  height: 40vh;
  width: 40vw;
}
canvas {
  width: '400px';
  height: '400px';
}
              
            
!

JS

              
                var pivot = new WebDataRocks({
    container: "#wdr-component",
    toolbar: true,
    height: 580,
    width: 900,
    report: {
        dataSource: {
            data: getData()
        },
        "slice": {
            "reportFilters": [{
                "uniqueName": "Date.Month"
            }],
            "rows": [{
                    "uniqueName": "Country"
                },
                {
                    "uniqueName": "Product Category"
                }
            ],
            "columns": [{
                "uniqueName": "Measures"
            }],
            "measures": [{
                    "uniqueName": "Profit",
                    "aggregation": "sum"
                },
                {
                    "uniqueName": "Budgeted Expenses",
                    "aggregation": "sum"
                },
                {
                    "uniqueName": "Actual Expenses",
                    "aggregation": "sum"
                }
            ],
            "expands": {
                "rows": [{
                        "tuple": [
                            "Country.France"
                        ]
                    },
                    {
                        "tuple": [
                            "Country.Spain"
                        ]
                    }
                ]
            }

        },
        "conditions": [{
                "formula": "#value > 15000",
                "measure": "Profit",
                "format": {
                    "backgroundColor": "#9CCC65",
                    "color": "#000000",
                    "fontFamily": "Arial",
                    "fontSize": "12px"
                }
            },
            {
                "formula": "#value > 3000",
                "measure": "Actual Expenses",
                "format": {
                    "backgroundColor": "#F44336",
                    "color": "#000000",
                    "fontFamily": "Arial",
                    "fontSize": "12px"
                }
            }
        ]
    },
    reportcomplete: function() {
        createPolarChart();
    }
});

var chart;

function createPolarChart() {
    webdatarocks.getData({
        "slice": {
            "rows": [{
                "uniqueName": "Country",
                "sort": "asc"
            }],
            "columns": [{
                "uniqueName": "Measures"
            }],
            "measures": [{
                "uniqueName": "Profit",
                "aggregation": "sum"
            }]
        },
    }, drawChart, updateChart);
}

function prepareDataFunction(rawData) {
    var result = {};
    var labels = [];
    var data = [];
    for (var i = 0; i < rawData.data.length; i++) {
        var record = rawData.data[i];
        if (record.c0 == undefined && record.r0 !== undefined) {
            var _record = record.r0;
            labels.push(_record);
        }
        if (record.c0 == undefined & record.r0 == undefined) continue;
        if (record.v0 != undefined) {
            data.push(!isNaN(record.v0) ? record.v0 : null);
        }
    }
    result.labels = labels;
    result.data = data;
    return result;
}

function drawChart(rawData) {
    var data = prepareDataFunction(rawData);
    var data_for_charts = {
        datasets: [{
            data: data.data,
            backgroundColor: [
                "#FF6384",
                "#4BC0C0",
                "#FFCE56",
                "#E7E9ED",
                "#36A2EB",
                "#9ccc65",
                "#b3e5fc"

            ]
        }],
        labels: data.labels
    };
    options = {
        responsive: true,
        legend: {
            position: 'right',
        },
        title: {
            display: true,
            fontSize: 18,
            text: 'Profit by Countries'
        },
        scale: {
            ticks: {
                beginAtZero: true
            },
            reverse: false
        },
        animation: {
            animateRotate: false,
            animateScale: true
        }
    };
    var ctx = document.getElementById("polar-chart").getContext("2d");
    chart = new Chart(ctx, {
        data: data_for_charts,
        type: 'polarArea',
        options: options
    });
}

function updateChart(rawData) {
    chart.destroy();
    drawChart(rawData);
}

function getData() {
    return [{
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 455,
            "Actual Expenses": 250,
            "Budgeted Expenses": 55,
            "Date": "2015-02-14T07:34:08",
            "Price Per Unit": 45
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 156,
            "Actual Expenses": 501,
            "Budgeted Expenses": 55,
            "Date": "2015-02-14T07:34:08",
            "Price Per Unit": 48
        },
        {
            "Country": "Spain",
            "Product Category": "Entertainment equipment",
            "Profit": 455,
            "Actual Expenses": 302,
            "Budgeted Expenses": 75,
            "Date": "2016-01-11T07:28:30",
            "Price Per Unit": 95
        },
        {
            "Country": "Spain",
            "Product Category": "Entertainment equipment",
            "Profit": 455,
            "Actual Expenses": 205,
            "Budgeted Expenses": 75,
            "Date": "2016-01-11T07:28:30",
            "Price Per Unit": 14
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 236,
            "Actual Expenses": 63,
            "Budgeted Expenses": 55,
            "Date": "2017-11-27T06:52:07",
            "Price Per Unit": 45
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 355,
            "Actual Expenses": 140,
            "Budgeted Expenses": 55,
            "Date": "2017-11-27T06:52:07",
            "Price Per Unit": 43
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 354,
            "Actual Expenses": 88,
            "Budgeted Expenses": 65,
            "Date": "2017-10-13T05:34:44",
            "Price Per Unit": 45
        }, {
            "Country": "USA",
            "Product Category": "Sports equipment",
            "Profit": 354,
            "Actual Expenses": 170,
            "Budgeted Expenses": 65,
            "Date": "2017-10-13T05:34:44",
            "Price Per Unit": 45
        },
        {
            "Country": "France",
            "Product Category": "Sports equipment",
            "Profit": 354,
            "Actual Expenses": 230,
            "Budgeted Expenses": 55,
            "Date": "2014-11-20T07:16:26",
            "Price Per Unit": 45
        },
        {
            "Country": "France",
            "Product Category": "Sports equipment",
            "Profit": 354,
            "Actual Expenses": 160,
            "Budgeted Expenses": 25,
            "Date": "2018-12-18T01:26:57",
            "Price Per Unit": 22
        },
        {
            "Country": "France",
            "Product Category": "Sports equipment",
            "Profit": 352,

            "Actual Expenses": 180,

            "Date": "2015-09-12T05:29:36",
            "Price Per Unit": 89
        },
        {
            "Country": "France",

            "Product Category": "Entertainment equipment",
            "Profit": 654,

            "Actual Expenses": 190,
            "Budgeted Expenses": 23,

            "Date": "2016-06-13T11:43:37",
            "Price Per Unit": 78
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 355,
            "Actual Expenses": 140,
            "Budgeted Expenses": 55,
            "Date": "2015-10-03T05:41:44",
            "Price Per Unit": 23
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 770,
            "Actual Expenses": 177,
            "Budgeted Expenses": 23,
            "Date": "2014-04-28T06:05:53",
            "Price Per Unit": 15
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 770,
            "Actual Expenses": 200,
            "Budgeted Expenses": 45,
            "Date": "2014-06-13T03:03:22",
            "Price Per Unit": 44
        },
        {

            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 770,

            "Actual Expenses": 300,
            "Budgeted Expenses": 55,

            "Date": "2015-07-28T12:04:26",
            "Price Per Unit": 22
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 770,
            "Actual Expenses": 140,
            "Budgeted Expenses": 55,
            "Date": "2014-12-31T10:21:58",
            "Price Per Unit": 45
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 550,

            "Actual Expenses": 120,
            "Budgeted Expenses": 55,

            "Date": "2017-09-09T07:11:20",
            "Price Per Unit": 88
        },
        {

            "Country": "France",
            "Product Category": "Entertainment equipment",
            "Profit": 655,
            "Actual Expenses": 88,
            "Budgeted Expenses": 45,
            "Date": "2014-06-15T12:41:23",
            "Price Per Unit": 35
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 354,
            "Actual Expenses": 90,
            "Budgeted Expenses": 55,
            "Date": "2017-12-08T11:25:50",
            "Price Per Unit": 74
        },
        {
            "Country": "France",
            "Product Category": "Cameras",
            "Profit": 322,
            "Actual Expenses": 30,
            "Budgeted Expenses": 55,
            "Date": "2018-03-18T04:39:25",
            "Price Per Unit": 41
        },
        {
            "Country": "France",
            "Product Category": "Cameras",
            "Profit": 322,
            "Actual Expenses": 140,
            "Budgeted Expenses": 55,
            "Date": "2014-11-18T11:59:17",
            "Price Per Unit": 44
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 774,
            "Actual Expenses": 220,
            "Budgeted Expenses": 123,
            "Date": "2016-08-06T03:38:09",
            "Price Per Unit": 99
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 436,
            "Actual Expenses": 130,
            "Budgeted Expenses": 123,
            "Date": "2014-07-16T08:27:06",
            "Price Per Unit": 36
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 655,
            "Actual Expenses": 70,
            "Budgeted Expenses": 123,
            "Date": "2019-02-01T01:16:28",
            "Price Per Unit": 98
        },
        {
            "Country": "USA",
            "Product Category": "Entertainment equipment",
            "Profit": 455,
            "Actual Expenses": 140,
            "Budgeted Expenses": 123,
            "Date": "2019-02-01T01:16:28",
            "Price Per Unit": 105
        },

        {
            "Country": "Australia",
            "Product Category": "Entertainment equipment",
            "Profit": 1500,
            "Actual Expenses": 140,
            "Budgeted Expenses": 123,
            "Date": "2019-02-01T01:16:28",
            "Price Per Unit": 105
        },

        {
            "Country": "Italy",
            "Product Category": "Entertainment equipment",
            "Profit": 5000,
            "Actual Expenses": 140,
            "Budgeted Expenses": 123,
            "Date": "2019-02-01T01:16:28",
            "Price Per Unit": 105
        },

        {
            "Country": "Sweden",
            "Product Category": "Entertainment equipment",
            "Profit": 3405,
            "Actual Expenses": 140,
            "Budgeted Expenses": 123,
            "Date": "2019-02-01T01:16:28",
            "Price Per Unit": 105
        }
    ]
}
              
            
!
999px

Console