Example demonstrates responsive feature of our angular charts that let you render charts seamlessly across devices & browsers. Charts automatically scales to fit it's container even when you change orientation of device.
/* app.component.ts */ import { Component } from '@angular/core'; import { RouterOutlet } from '@angular/router'; import { CommonModule } from '@angular/common'; import { CanvasJSAngularChartsModule } from '@canvasjs/angular-charts'; @Component({ selector: 'app-root', standalone: true, imports: [RouterOutlet, CommonModule, CanvasJSAngularChartsModule], templateUrl: './app.component.html', styleUrl: './app.component.css', }) export class AppComponent { chartOptions = { title: { text: 'Monthly Sales Data', }, theme: 'light2', animationEnabled: true, exportEnabled: true, axisY: { includeZero: true, valueFormatString: '$#,##0k', }, data: [ { type: 'column', //change type to bar, line, area, pie, etc yValueFormatString: '$#,##0k', color: '#01b8aa', dataPoints: [ { label: 'Jan', y: 172 }, { label: 'Feb', y: 189 }, { label: 'Mar', y: 201 }, { label: 'Apr', y: 240 }, { label: 'May', y: 166 }, { label: 'Jun', y: 196 }, { label: 'Jul', y: 218 }, { label: 'Aug', y: 167 }, { label: 'Sep', y: 175 }, { label: 'Oct', y: 152 }, { label: 'Nov', y: 156 }, { label: 'Dec', y: 164 }, ], }, ], }; }
/* app.component.html */ <div> <canvasjs-chart [options]="chartOptions" [styles]="{width: '100%', height: '360px'}"></canvasjs-chart> </div>
You can set the width & height of the chart using width & height properties. You can also set the width of dataPoints in column / bar, ohlc and candlestick charts by setting dataPointWidth property.