There are four types of axis: primary category axis, primary value axis, secondary category axis, and secondary value axis.
You can get or set the style, line style, tick position, tick label’s position/spacing, format, numberFormatLinked, crosses, orientation,title, and gridline for these four axis using the following code.
You can get or set the gridline’s color, width and visibility.
Logarithmic Axes: SpreadJS supports logarithmic scales for the value axis.
Axis Label Position: SpreadJS supports set label position for axis as below enum type GC.Spread.Sheets.Charts.TickLabelPosition.
high
low
nextToAxis
none
Axis Orientation: SpreadJS supports setting the orientation of an axis
Display Unit: The Display Unit property allows you to display units like Million/Trillions as the value axis display instead of the actual large numbers. This feature is useful to conserve space and makes it easier to read.
Date axis: SpreadJS supports using a date axis with the below properties. You can adjust the date unit and date unit scale.
baseUnit
majorUnit
majorUnitScale
minorUnit
minorUnitScale
Crosses: SpreadJS supports set axis crosses as number type or below axis crosses enum type GC.Spread.Sheets.Charts.AxisCrossPoint.
automatic
maximum
minimum
import { Component, NgModule, enableProdMode } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { SpreadSheetsModule } from '@mescius/spread-sheets-angular';
import GC from '@mescius/spread-sheets';
import "@mescius/spread-sheets-shapes";
import '@mescius/spread-sheets-charts';
import './styles.css';
@Component({
selector: 'app-component',
templateUrl: 'src/app.component.html'
})
export class AppComponent {
spread: GC.Spread.Sheets.Workbook;
hostStyle = {
width: '100%',
height: '100%',
overflow: 'hidden',
float: 'left'
};
initSpread($event: any) {
this.spread = $event.spread;
let spread = this.spread;
let sheet = spread.getActiveSheet();
sheet.suspendPaint();
sheet.setValue(0, 1, "Apple");
sheet.setValue(0, 2, "Banana");
sheet.setValue(0, 3, "Pear");
sheet.setValue(1, 0, "People1");
sheet.setValue(2, 0, "People2");
sheet.setValue(3, 0, "People3");
for (let r = 1; r <= 3; r++) {
for (let c = 1; c <= 3; c++) {
sheet.setValue(r, c, parseInt(<any>(Math.random() * 100)));
}
}
let dataArray = [
["Month", 'Fund Income', 'Stock Income', 'Bank Interest Income'],
["Jan", 100, 2, 9],
["Feb", -96, 15, 10],
["Mar", 53, 88, 8],
["Apr", -15, 150, 1],
["May", 77, -52, 20],
["Jun", 20, 66, 6],
["Jul", 60, 2, 9],
["Aug", -26, 15, 30],
["Sep ", 23, 78, 8],
["Oct", -15, 100, 21],
["Nov", 57, -52, 3],
["Dec", 30, 55, 16],
];
sheet.setArray(0, 6, dataArray);
sheet.getRange(1, 7, 12, 3).formatter("$#,##0.00");
//add chart
let Charts = GC.Spread.Sheets.Charts;
let columnChart = sheet.charts.add('columnChart', Charts.ChartType.columnClustered, 10, 100, 400, 350);
let lineChart = sheet.charts.add('lineChart', GC.Spread.Sheets.Charts.ChartType.line, 420, 100, 400, 350);
let orientationChart = sheet.charts.add('orientationChart', Charts.ChartType.columnClustered, 830, 100, 400, 350, 'A1:D4');
let series = columnChart.series();
series.add({
chartType: Charts.ChartType.columnClustered,
axisGroup: Charts.AxisGroup.primary,
name: "Sheet1!$A$2",
xValues: "Sheet1!$B$1:$D$1",
yValues: "Sheet1!$B$2:$D$2"
});
series.add({
chartType: Charts.ChartType.columnClustered,
axisGroup: Charts.AxisGroup.primary,
name: "Sheet1!$A$3",
xValues: "Sheet1!$B$1:$D$1",
yValues: "Sheet1!$B$3:$D$3"
});
series.add({
chartType: Charts.ChartType.lineMarkers,
axisGroup: Charts.AxisGroup.secondary,
name: "Sheet1!$A$4",
xValues: "Sheet1!$B$1:$D$1",
yValues: "Sheet1!$B$4:$D$4"
});
let axes = columnChart.axes();
axes.primaryCategory.style.color = 'orange';
axes.primaryCategory.title.color = 'orange';
axes.primaryCategory.title.text = 'Primary Category Axis';
axes.primaryValue.style.color = 'red';
axes.primaryValue.title.color = 'red';
axes.primaryValue.title.text = 'Primary Value Logarithmic Axis';
axes.primaryValue.title.fontSize = 16;
axes.primaryValue.scaling = {
logBase: 2
};
axes.secondaryCategory.visible = true;
axes.secondaryCategory.style.color = 'green';
axes.secondaryCategory.title.color = 'green';
axes.secondaryCategory.title.text = 'Secondary Category Axis';
axes.secondaryCategory.title.fontSize = 16;
axes.secondaryValue.style.color = 'blue';
axes.secondaryValue.title.color = 'blue';
axes.secondaryValue.format = 'General';
axes.secondaryValue.title.text = 'Secondary Value Axis';
let columnChartTitle = columnChart.title();
columnChartTitle.text = "Product Sales";
columnChart.title(columnChartTitle);
columnChart.axes(axes);
series = lineChart.series();
series.add({
chartType: Charts.ChartType.line,
axisGroup: Charts.AxisGroup.primary,
name: "Sheet1!$H$1",
xValues: "Sheet1!$G$2:$G$13",
yValues: "Sheet1!$H$2:$H$13"
});
series.add({
chartType: Charts.ChartType.columnClustered,
axisGroup: Charts.AxisGroup.secondary,
name: "Sheet1!$I$1",
xValues: "Sheet1!$G$2:$G$13",
yValues: "Sheet1!$I$2:$I$13"
});
series.add({
chartType: Charts.ChartType.columnClustered,
axisGroup: Charts.AxisGroup.secondary,
name: "Sheet1!$J$1",
xValues: "Sheet1!$G$2:$G$13",
yValues: "Sheet1!$J$2:$J$13"
});
axes = lineChart.axes();
axes.primaryCategory.crossPoint = 6;
axes.primaryCategory.tickLabelSpacing = 2;
axes.secondaryValue.visible = false;
lineChart.axes(axes);
let series1 = lineChart.series().get(0);
series1.smooth = true;
lineChart.series().set(0, series1);
let lineChartTitle = lineChart.title();
lineChartTitle.text = "First Half Financial Income";
lineChart.title(lineChartTitle);
let axes2 = orientationChart.axes();
let orientationChartTitle = orientationChart.title();
orientationChartTitle.text = "Product Sales(reverse order)";
orientationChart.title(orientationChartTitle);
axes2.primaryValue.scaling = {
orientation: GC.Spread.Sheets.Charts.AxisOrientation.maxMin
};
orientationChart.axes(axes2);
sheet.resumePaint();
}
}
@NgModule({
imports: [BrowserModule, SpreadSheetsModule],
declarations: [AppComponent],
exports: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
enableProdMode();
// Bootstrap application with hash style navigation and global services.
platformBrowserDynamic().bootstrapModule(AppModule);
<!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/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- Polyfills -->
<script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script>
<script src="$DEMOROOT$/en/angular/node_modules/zone.js/fesm2015/zone.min.js"></script>
<!-- SystemJS -->
<script src="$DEMOROOT$/en/angular/node_modules/systemjs/dist/system.js"></script>
<script src="systemjs.config.js"></script>
<script>
// workaround to load 'rxjs/operators' from the rxjs bundle
System.import('rxjs').then(function (m) {
System.import('@angular/compiler');
System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators));
System.import('$DEMOROOT$/en/lib/angular/license.ts');
System.import('./src/app.component');
});
</script>
</head>
<body>
<app-component></app-component>
</body>
</html>
<div class="sample-tutorial">
<gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)">
<gc-worksheet></gc-worksheet>
</gc-spread-sheets>
</div>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
(function (global) {
System.config({
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
},
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'core-js': 'npm:core-js/client/shim.min.js',
'zone': 'npm:zone.js/fesm2015/zone.min.js',
'rxjs': 'npm:rxjs/dist/bundles/rxjs.umd.min.js',
'@angular/core': 'npm:@angular/core/fesm2022',
'@angular/common': 'npm:@angular/common/fesm2022/common.mjs',
'@angular/compiler': 'npm:@angular/compiler/fesm2022/compiler.mjs',
'@angular/platform-browser': 'npm:@angular/platform-browser/fesm2022/platform-browser.mjs',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/fesm2022/platform-browser-dynamic.mjs',
'@angular/common/http': 'npm:@angular/common/fesm2022/http.mjs',
'@angular/router': 'npm:@angular/router/fesm2022/router.mjs',
'@angular/forms': 'npm:@angular/forms/fesm2022/forms.mjs',
'jszip': 'npm:jszip/dist/jszip.min.js',
'typescript': 'npm:typescript/lib/typescript.js',
'ts': './plugin.js',
'tslib':'npm:tslib/tslib.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',
'@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-angular': 'npm:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
"node_modules/@angular": {
defaultExtension: 'mjs'
},
"@mescius/spread-sheets-angular": {
defaultExtension: 'mjs'
},
'@angular/core': {
defaultExtension: 'mjs',
main: 'core.mjs'
}
}
});
})(this);