Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<script src="https://www.amcharts.com/lib/4/themes/animated.js"></script>

<table>
  <colgroup>
    <col style="width:50%">
    <col style="width:50%">
  </colgroup>  
  <tbody>
     <tr>
    <td><div id="pivotContainer"></div></td>
    <td><div id="chartContainer"></div></td>
  </tr>
  </tbody>
</table>





              
            
!

CSS

              
                #chartContainer {
  width: 800px;
  height: 500px;
}

              
            
!

JS

              
                var pivot = new WebDataRocks({
    container: "#pivotContainer",
    toolbar: true,
    height: 580,
    width: 700,
    report: {
        dataSource: {
            data: getData()
        },
        "slice": {
            "reportFilters": [{
                "uniqueName": "Date.Month"
            }],
            "rows": [{
                    "uniqueName": "Country"
                }                
            ],
            "columns": [
              {
                    "uniqueName": "Product Category"
                },
              {
                "uniqueName": "Measures"
            }],
            "measures": [{
                    "uniqueName": "Profit",
                    "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() {
        createGaugeChart();
    }
});

am4core.useTheme(am4themes_animated);

// creating chart instance
var chart;


function createGaugeChart() {
    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.names = labels;
    result.data = data;
    return result;
}

var gauge;

function drawChart(rawData) {
    var processed_data = prepareDataFunction(rawData);
    names = processed_data.names;
    values = processed_data.data;
  console.log(names);
  var dataSet = anychart.data.set(values);
   var palette = anychart.palettes.distinctColors().items(['#64b5f6', '#1976d2', '#ef6c00', '#ffd54f', '#455a64', '#96a6a6', '#dd2c00', '#00838f', '#00bfa5', '#ffa000']);
var makeBarWithBar = function (gauge, radius, i, width, without_stroke) {
    var stroke = '1 #e5e4e4';
    if (without_stroke) {
        stroke = null;
        gauge.label(i)
                .text(names[i] + ', <span style="">' + values[i] + '$</span>')// color: #7c868e
                .useHtml(true);
        gauge.label(i)
                .hAlign('center')
                .vAlign('middle')
                .anchor('right-center')
                .padding(0, 10)
                .height(width / 2 + '%')
                .offsetY(radius + '%')
                .offsetX(0);
    }

    gauge.bar(i).dataIndex(i)
            .radius(radius)
            .width(width)
            .fill(palette.itemAt(i))
            .stroke(null)
            .zIndex(5);
    gauge.bar(i + 100).dataIndex(5)
            .radius(radius)
            .width(width)
            .fill('#F5F4F4')
            .stroke(stroke)
            .zIndex(4);

    return gauge.bar(i)
};

anychart.onDocumentReady(function () {
    gauge = anychart.gauges.circular();
    gauge.data(dataSet);
    gauge.fill('#fff')
            .stroke(null)
            .padding(0)
            .margin(100)
            .startAngle(0)
            .sweepAngle(270);
    var axis = gauge.axis().radius(100).width(1).fill(null);
    axis.scale()
            .minimum(0)
            .maximum(100)
            .ticks({interval: 1})
            .minorTicks({interval: 1});
    axis.labels().enabled(false);
    axis.ticks().enabled(false);
    axis.minorTicks().enabled(false);
    makeBarWithBar(gauge, 100, 0, 17, true);
    makeBarWithBar(gauge, 80, 1, 17, true);
    makeBarWithBar(gauge, 60, 2, 17, true);
    makeBarWithBar(gauge, 40, 3, 17, true);
    makeBarWithBar(gauge, 20, 4, 17, true);
    gauge.margin(50);
    gauge.title().text('Revenue' +
            '<br/><span style="color:#929292; font-size: 12px;">by countries</span>').useHtml(true);
    gauge.title()
            .enabled(true)
            .hAlign('center')
            .padding(0)
            .margin([0, 0, 20, 0]);
    gauge.container('chartContainer');
    gauge.draw();
});

}

function updateChart(rawData) {
    gauge.dispose();
    gauge = null;
    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