JSFiddle - React, Tailwind, and code Playground
by kris rice
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"></script>
Slice of Pie
<div id='chart-container'>
<div id="pieChart" data-bind="ojComponent: {
component: 'ojChart',
type: 'pie',
series: pieSeriesValue,
animationOnDisplay: 'auto',
animationOnDataChange: 'auto',
styleDefaults: {threeDEffect: ko.toJS(threeDValue)},
hoverBehavior: 'dim'
}"
style="max-width:500px;width:100%;height:350px;">
</div>
<!-- 2d/3d toggle button -->
<div id="radioButtonset2" class="oj-buttonset-width-auto" aria-label="Choose only one setting." aria-controls="pieChart"
data-bind="ojComponent: {component: 'ojButtonset', checked: threeDValue, optionChange: threeDValueChange}">
<!-- ko foreach: threeDOptions -->
<label data-bind="attr: {for: id}"></label>
<input type="radio" name="threeD"
data-bind="value: value, attr: {id: id},
ojComponent: {component: 'ojButton', label: label}"/>
<!-- /ko -->
</div>
</div>
CSS
@import url('//rawgit.com/oracle/oraclejet/2.1.0/dist/css/alta/oj-alta-min.css');
JavaScript
require(['knockout',
'ojs/ojcore',
'jquery',
'ojs/ojknockout',
'ojs/ojcore',
'ojs/ojbutton',
'ojs/ojchart'
], function(ko, oj, $) {
'use strict';
function ChartModel(pieSeries) {
var self = this;
self.threeDValue = ko.observable('off');
self.sortingValue = ko.observable('descending');
self.pieSeriesValue = ko.observableArray(pieSeries);
/* toggle buttons*/
self.threeDOptions = [
{id: '2D', label: '2D', value: 'off', icon: 'oj-icon demo-2d'},
{id: '3D', label: '3D', value: 'on', icon: 'oj-icon demo-3d'}
];
self.threeDValueChange = function(event, data) {
self.threeDValue(data.value);
return true;
}
}
$(document).ready(function(){
$.getJSON("https://apex.oracle.com/pls/apex/orclcode/oraclecode/skillscount").
then(function(ret) {
var pieSeries=[];
$.each(ret.items, function(idx,skill) {
var nextEl= {"name" :skill.skill,"items": [skill.thecount]};
pieSeries.push(nextEl);
});
console.log(pieSeries)
ko.applyBindings(new ChartModel(pieSeries), document.getElementById('chart-container'));
});
});
});
//RequireJS configs (usually these come first in main.js, but they don't have to)
requirejs.config({
// Path mappings for the logical module names
paths: {
'knockout': '//cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min',
'jquery': '//cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min',
"jqueryui-amd": "//rawgit.com/jquery/jquery-ui/1.12.0/ui",
"promise": "//cdnjs.cloudflare.com/ajax/libs/es6-promise/3.2.1/es6-promise.min",
"hammerjs": "//cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min",
"ojdnd": "//rawgit.com/oracle/oraclejet/2.1.0/dist/js/libs/dnd-polyfill/dnd-polyfill-1.0.0.min",
"ojs": "//rawgit.com/oracle/oraclejet/2.1.0/dist/js/libs/oj/debug",
...