Angular - Issue with highcharts-angular / bootstrap causing charts to not resize to fit parent container width

I'm currently utilizing Angular in conjunction with bootstrap and Highcharts / Highcharts-angular

My issue lies in the fact that when I adjust the size of the grids, the charts do not expand to 100% width.

Below is the code snippet:

app.component.html

<button (click)="changeGrid(12)">1 Column</button>
<button (click)="changeGrid(6)">2 Columns</button>
<button (click)="changeGrid(4)">3 Columns</button>

<div class="container-fluid">
    <div class="row">
        <div class="col-md-{{grid}}" *ngFor="let item2 of items">

            <div class="card">

                 <div class="card-body">
                                    
                    <highcharts-chart style="width:100% !important; display:block;"
                        [Highcharts]="Highcharts"
                        [constructorType]="item2.options.constructorType"
                        [(update)]="updateFlag"
                        [oneToOne]="oneToOneFlag"
                        [options]="item2.options">
                    </highcharts-chart>
                </div>

            </div>

    </div>
</div>

app.component.ts

import { Component, OnInit } from '@angular/core';
import { HighchartsService } from 'hc.service';

import * as Highcharts from "highcharts/highstock";
import HStockTools from "highcharts/modules/stock-tools";

HStockTools(Highcharts);

export class AppComponent {

  Highcharts: typeof Highcharts = Highcharts;
  chart: Highcharts.Chart | null | undefined;
  data: any;
  updateFlag = false;
  oneToOneFlag: boolean = true;
  chartTypes = [];
  options: any;
  grid: undefined;



loadData() {
  this.data = this.hcService.data();
}

changeGrid(grid: any) {
  this.data[0].layout.gridcols = grid;
  this.updateFlag = true;
}

The issue here is that the charts are not expanding to 100% width along with the grid / card / parent elements.

Is there a way to rectify this within the provided code?

Answer №1

<div class="container">
  <highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions"
  style="width: 100%; height: 400px; display: block;"
  ></highcharts-chart>
</div>

To adjust the width of the container to fit the chart, you can modify the width in the CSS style.

/* .container {
  width: 100%;
  height:400px;
  display: block;
} */
.container {
  width: 600px;
  height:400px;
  display: block;
}

Take a look at the live demo: Demo

For more information, check out the documentation here: https://github.com/highcharts/highcharts-angular#online-examples

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for concealing a Div in an HTML document with the help of Angular

I need a solution to hide a div that contains only titles, while the div with the actual content is located in a different section <div> <b>Delivery Info\</b> <div class="custom-control">Delivery ID: </div ...

Pause and anticipate the subscription within the corresponding function

Is there a way to make an If-Else branch wait for all REST calls to finish, even if the Else side has no REST calls? Let's take a look at this scenario: createNewList(oldList: any[]) { const newList = []; oldList.forEach(element => { if (eleme ...

What are the best ways to quickly avoid changing routes in Angular?

My routing logic includes: this.route.paramMap .pipe(switchMap((parameters) => of(parameters))) .subscribe((params: Params) => { if (params.has("id")) { // Send request to server } if (params.has("block")) ...

React TypeScript: Handling OnChange Events for Different Input Types

I am confronted with multiple input fields: <label> <span className="codes__input-label">Count</span> <input type="number" value={this.state.count} onChange={this.onInputChange} /> </label> ...

Sharing Angular 4 components in my project - collaboration at its finest

I have been working on an Angular project that consists of a variety of UI components. I would like to make these components available for use in other Angular projects and share them within the npm community. All of the components are located in a shared ...

Generating a d.ts file for images in Typescript using automation techniques

Currently, I am working on a React application that utilizes TypeScript and webpack. I am aware that in TypeScript, when importing an image file, it is necessary to create a d.ts file in the current directory and include the following code: // index.d.ts ...

Put off the assessment of JSX

As I was working with a function that returns JSX to React components, I realized the need to include some state variables of the components in the JSX as well. Each component might require changing the JSX or its values. Take a look at the code snippet be ...

Why won't my Angular app hit a breakpoint while debugging?

I'm relatively new to the world of Visual Studio Code and Angular applications with a C# Web API back-end. My issue lies in hitting breakpoints within my Angular app using VS Code, even though I can hit them without any problems in C#! Running both a ...

I desire to exclude the final attribute of the object and instead assign its value to the preceding property

I am dealing with an object structure like the one below: let a = { title: { value:"developer" } publishedOn:{ month:{ value:"jan" } year:{ value:"2000" } } and I need to transform it into the followin ...

Encountering issues when attempting to activate npm start command in Ubuntu operating system

Recently delving into the world of Angular2, I've been working on setting up an AngularJS 2.0 project on Ubuntu. I made sure to install npm in the root directory of my Angular2 app. However, when I attempt to run npm start, I encounter the following e ...

Testing reactive streams with marble diagrams and functions

Upon returning an object from the Observable, one of its properties is a function. Even after assigning an empty function and emitting the object, the expectation using toBeObservable fails due to a non-deep match. For testing purposes, I am utilizing r ...

Leveraging the power of literal types to choose a different type of argument

My API is quite generic and I'm looking for a typed TypeScript client solution. Currently, my code looks like this: export type EntityTypes = | 'account' | 'organization' | 'group' export function getListByVa ...

How to fill an HTML template using ngFor without using a JSON array

Is there a way to fill the HTML with basic JSON like below: { "id": 34, "name": "Tip 33", "description": "Tip description 33", "created_at": "2018-01-26 18:59:19", "updated_at": "2018-01-26 18:59:19" } The code i tried using was: < ...

Troubleshooting Puppeteer compatibility issues when using TypeScript and esModuleInterop

When attempting to use puppeteer with TypeScript and setting esModuleInterop=true in tsconfig.json, an error occurs stating puppeteer.launch is not a function If I try to import puppeteer using import * as puppeteer from "puppeteer" My questi ...

The Open AI API is currently inaccessible due to a missing API

After using OpenAI in numerous projects for some time, I decided to create a new apiKey for my latest project. However, upon initializing OpenAI, I encountered the following error: Unhandled Runtime Error Error: The OPENAI_API_KEY environment variable is ...

Mapping an array in Typescript using Angular to instantiate a class

I have received data from a web API that resembles the structure below. I am looking for guidance on how to properly map the product array into individual Products. My main objective is to convert the eating_time values into JavaScript datetime format. Cu ...

Issue with form array patching causing value not to be set on material multiple select

When attempting to populate a mat-select with multiple options using an array of ids from Firestore, I encountered an issue. The approach involved looping through the array, creating a new form control for each id, and then adding it to the formArray using ...

Error encountered in the auth service Observable for the Metronic Angular 8 login page. The issue persists when utilizing the same source code in the default component, where it functions

Issue with Observable in Metronic Theme Angular 8 I have encountered an error while using the auth service in another component of the Metronic Theme for Angular 8. The same service works without any errors in the default logic component. this.auth ...

Angular validation to ensure future dates are not selected

I am interested in exploring Angular's datepicker functionality and implementing date validation to restrict the selection of future or past dates. For example, if today's date is 17/12/2020, users should only be able to select the current date ( ...

What should be done in the absence of any subscriptions?

Incorporating a generic HTTP service to encapsulate certain HTTP behaviors is part of our system. In case of an error, we include the error in a BehaviorSubject. I am contemplating on whether there is a method to display this error only if no one is subsc ...