3D Stacked Column Interactive Chart in Angular using HighChart

In this article, we saw how to draw 3d Stacked Column Interactive charts in angular using HighChart. In the last article, we saw a 3D Column Column chart in HighChart. In this article, we can create a stacked column rotate(Interactive) chart. In this article, we have taken an example of the consumption of the fruit by category men and women.
For drawing the chart First, we need to install High chart node modules in our application.


npm install highcharts --save
npm install highcharts-angular --save

After installing module lets add a module in our app.module.ts file.

....
import { HighchartsChartModule } from 'highcharts-angular';
...
@NgModule({
imports:      [ ..., HighchartsChartModule],
....
})



After adding a module in the app.module file we can use it in our component to draw the chart. Let’s create app.component.ts file and add import highchat module using “import * as Highcharts from ‘highcharts’;” then assign options and values to the chart in this chart we need to chart type as “column” and adding series data we need to pass the categories fruits data and pass the stack name in json format to draw the data. In last article we show for 3D chart option enable we need to import “highcharts-3d” in our component. How to import “highcharts-3d” modules display in below code.


import highcharts3D from 'highcharts/highcharts-3d';
highcharts3D(Highcharts);

We need 3 parameters(alpha,beta,depth) to chnage the chart interactive chart.
Below is the full code for component and the html files.


import { Component, VERSION ,OnInit } from '@angular/core';
import * as Highcharts from 'highcharts';

declare var require: any;
const More = require('highcharts/highcharts-more');
More(Highcharts);

import Histogram from 'highcharts/modules/histogram-bellcurve';
Histogram(Highcharts);

import highcharts3D from 'highcharts/highcharts-3d';
highcharts3D(Highcharts);

import Cylinder from 'highcharts/modules/cylinder';
Cylinder(Highcharts);

const Exporting = require('highcharts/modules/exporting');
Exporting(Highcharts);

const ExportData = require('highcharts/modules/export-data');
ExportData(Highcharts);

const Accessibility = require('highcharts/modules/accessibility');
Accessibility(Highcharts);
import * as newdata from './data';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  implements OnInit{


  public activity;
  public xData;
  public label;
  options:any;

  public alpha:number;
  public beta:number;
  public depth:number;
  constructor() {
 

  this.alpha = 15;
  this.beta = 15;
  this.depth = 40;

    this.options = {
    chart: {
        type: 'column',
        options3d: {
            enabled: true,
            alpha: this.alpha,
            beta: this.beta ,
            viewDistance: 25,
            depth: this.depth
        }
    },

    title: {
        text: 'Total fruit consumption, grouped by gender'
    },

    xAxis: {
        categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'],
        labels: {
            skew3d: true,
            style: {
                fontSize: '16px'
            }
        }
    },

    yAxis: {
        allowDecimals: false,
        min: 0,
        title: {
            text: 'Number of fruits',
            skew3d: true
        }
    },

    tooltip: {
        headerFormat: '{point.key}
', pointFormat: '\u25CF {series.name}: {point.y} / {point.stackTotal}' }, plotOptions: { column: { stacking: 'normal', depth: 40 } }, series: [{ name: 'Jack', data: [5, 3, 4, 7, 2], stack: 'male' }, { name: 'Walter', data: [3, 4, 4, 2, 5], stack: 'male' }, { name: 'Jane', data: [2, 5, 6, 2, 1], stack: 'female' }, { name: 'Jill', data: [3, 0, 4, 4, 3], stack: 'female' }] }; } ngOnInit(){ Highcharts.chart('container', this.options); } onChange(val,type){ if(type == 'alpha'){ this.options.chart.options3d.alpha = val; } if(type == 'beta'){ this.options.chart.options3d.beta = val; } if(type == 'depth'){ this.options.chart.options3d.depth = val; } Highcharts.chart('container', this.options); } }


<h1 style="text-align:center">3D Interactive Stacked Chart in Angular</h1>
<div class="form-inline">
  <label for="email">Alpha:</label>
  <input type="number" class="form-control" [(ngModel)]="alpha" (ngModelChange)="onChange($event,'alpha')">
  <label for="pwd">Beta:</label>
  <input type="number" class="form-control" [(ngModel)]="beta" (ngModelChange)="onChange($event,'beta')">
   <label for="pwd">Depth:</label>
  <input type="number" class="form-control" [(ngModel)]="depth" (ngModelChange)="onChange($event,'depth')">
</div>
<div id="container"></div>




Below is the full embeded code for the 3D Stacked Column Interactive chart using Highchart you can easily used in your application.

Spread the love
  •  
  •  
  •  
  •  
  •  
  • 2
  •  
  •