SpreadJS supports sunburst chart. Use the GC.Spread.Sheets.Charts.ChartType.sunburst property to get the chart type.
You can add a sunburst chart to Spread and change its style using the chart API.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import './styles.css';
import { AppFunc } from './app-func';
// import { App } from './app-class';
// 1. Functional Component sample
ReactDOM.render(<AppFunc />, document.getElementById('app'));
// 2. Class Component sample
// ReactDOM.render(<App />, document.getElementById('app'));
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
import '@mescius/spread-sheets-shapes';
import '@mescius/spread-sheets-charts';
export function AppFunc() {
const initSpread = (spread) => {
let sheets = spread.sheets;
spread.suspendPaint();
// custom sheets style
_setSheet(sheets);
_setData(sheets[0], 'sunburstChart');
initSunburst(sheets[0], GC.Spread.Sheets.Charts.ChartType.sunburst, 'sunburstChart');
_setData(sheets[1], 'customStyle');
let customSunburstChart = initSunburst(sheets[1], GC.Spread.Sheets.Charts.ChartType.sunburst, 'customStyle Chart');
// custom sunburst chart style
_setChartArea(customSunburstChart);
_setTitle(customSunburstChart);
_setDataPoints(customSunburstChart);
spread.resumePaint();
}
const _setSheet = (sheets) => {
let columnWidths = [20, 70, 100, 80, 120];
for (let i = 0; i < sheets.length; i++) {
sheets[i].options.gridline.showHorizontalGridline = false;
sheets[i].options.gridline.showVerticalGridline = false;
sheets[i].getRange(1, 1, 17, 4)
.hAlign(GC.Spread.Sheets.HorizontalAlign.center)
.setBorder(new GC.Spread.Sheets.LineBorder('black', GC.Spread.Sheets.LineStyle.thin), { all: true });
sheets[i].getRange(1, 1, 1, 4).font('bold normal 10pt Arial');
for (let j = 0; j < columnWidths.length; j++) {
sheets[i].setColumnWidth(j, columnWidths[j]);
}
}
}
const initSunburst = (sheet, chartType, chartName) => {
sheet.resumePaint();
return sheet.charts.add(chartName, chartType, 450, 0, 400, 400, "B2:E18");
}
const _setChartArea = (chart) => {
let area = chart.chartArea();
area.backColor = '#fff';
area.backColorTransparency = 0;
area.color = '#000'
chart.chartArea(area)
}
const _setTitle = (chart) => {
let title = chart.title();
title.text = 'World Population';
chart.title(title);
}
const _setDataPoints = (chart) => {
let dataPoints = chart.series().dataPoints();
let fillColors = ['#4472c4', '#a5a5a5', '#ffc000', '#ed7d31'];
fillColors.forEach(function (color, index) {
let dataPoint = dataPoints.get(index);
dataPoint.fillColor = color;
dataPoint.transparency = 0; // 0~1
dataPoints.set(index, dataPoint);
})
}
const _setData = (sheet, sheetName) => {
sheet.name(sheetName);
sheet.suspendPaint();
let dataArray = [
['Region', 'Subregion', 'country', 'Population'],
['Asia', 'Southern', 'India', 1354051854],
[, , 'Pakistan', 200813818],
[, , 'Bangladesh', 166368149],
[, , 'Others', 170220300],
[, 'Eastern', 'China', 1415045928],
[, , 'Japan', 127185332],
[, , 'Others', 111652273],
[, 'South-Eastern', , 655636576],
[, 'Western', , 272298399],
[, 'Central', , 71860465],
['Africa', 'Eastern', , 433643132],
[, 'Western', , 381980688],
[, 'Northern', , 237784677],
[, 'Others', , 234512021],
['Europe', , , 742648010],
['Others', , , 1057117703]
];
sheet.setArray(1, 1, dataArray);
}
return (<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
<Worksheet />
<Worksheet />
</SpreadSheets>
</div>
</div>);
}
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
import '@mescius/spread-sheets-shapes';
import '@mescius/spread-sheets-charts';
const Component = React.Component;
export class App extends Component {
constructor(props) {
super(props);
this.spread = null;
}
render() {
return (<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
<Worksheet />
<Worksheet />
</SpreadSheets>
</div>
</div>);
}
initSpread(spread) {
let sheets = spread.sheets;
spread.suspendPaint();
// custom sheets style
this._setSheet(sheets);
this._setData(sheets[0], 'sunburstChart');
this.initSunburst(sheets[0], GC.Spread.Sheets.Charts.ChartType.sunburst, 'sunburstChart');
this._setData(sheets[1], 'customStyle');
let customSunburstChart = this.initSunburst(sheets[1], GC.Spread.Sheets.Charts.ChartType.sunburst, 'customStyle Chart');
// custom sunburst chart style
this._setChartArea(customSunburstChart);
this._setTitle(customSunburstChart);
this._setDataPoints(customSunburstChart);
spread.resumePaint();
}
_setSheet(sheets) {
let columnWidths = [20, 70, 100, 80, 120];
for (let i = 0; i < sheets.length; i++) {
sheets[i].options.gridline.showHorizontalGridline = false;
sheets[i].options.gridline.showVerticalGridline = false;
sheets[i].getRange(1, 1, 17, 4)
.hAlign(GC.Spread.Sheets.HorizontalAlign.center)
.setBorder(new GC.Spread.Sheets.LineBorder('black', GC.Spread.Sheets.LineStyle.thin), { all: true });
sheets[i].getRange(1, 1, 1, 4).font('bold normal 10pt Arial');
for (let j = 0; j < columnWidths.length; j++) {
sheets[i].setColumnWidth(j, columnWidths[j]);
}
}
}
initSunburst(sheet, chartType, chartName) {
sheet.resumePaint();
return sheet.charts.add(chartName, chartType, 450, 0, 400, 400, "B2:E18");
}
_setChartArea(chart) {
let area = chart.chartArea();
area.backColor = '#fff';
area.backColorTransparency = 0;
area.color = '#000'
chart.chartArea(area)
}
_setTitle(chart) {
let title = chart.title();
title.text = 'World Population';
chart.title(title);
}
_setDataPoints(chart) {
let dataPoints = chart.series().dataPoints();
let fillColors = ['#4472c4', '#a5a5a5', '#ffc000', '#ed7d31'];
fillColors.forEach(function (color, index) {
let dataPoint = dataPoints.get(index);
dataPoint.fillColor = color;
dataPoint.transparency = 0; // 0~1
dataPoints.set(index, dataPoint);
})
}
_setData(sheet, sheetName) {
sheet.name(sheetName);
sheet.suspendPaint();
let dataArray = [
['Region', 'Subregion', 'country', 'Population'],
['Asia', 'Southern', 'India', 1354051854],
[, , 'Pakistan', 200813818],
[, , 'Bangladesh', 166368149],
[, , 'Others', 170220300],
[, 'Eastern', 'China', 1415045928],
[, , 'Japan', 127185332],
[, , 'Others', 111652273],
[, 'South-Eastern', , 655636576],
[, 'Western', , 272298399],
[, 'Central', , 71860465],
['Africa', 'Eastern', , 433643132],
[, 'Western', , 381980688],
[, 'Northern', , 237784677],
[, 'Others', , 234512021],
['Europe', , , 742648010],
['Others', , , 1057117703]
];
sheet.setArray(1, 1, dataArray);
}
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- SystemJS -->
<script src="$DEMOROOT$/en/react/node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('$DEMOROOT$/en/lib/react/license.js').then(function () {
System.import('./src/app');
});
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: 100%;
height:100%;
overflow: hidden;
float: left;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#app {
height: 100%;
}
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true,
react: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@mescius/spread-sheets-shapes': 'npm:@mescius/spread-sheets-shapes/index.js',
'@mescius/spread-sheets-charts': 'npm:@mescius/spread-sheets-charts/index.js',
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js',
'react': 'npm:react/umd/react.production.min.js',
'react-dom': 'npm:react-dom/umd/react-dom.production.min.js',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'jsx'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);