Tips for enlarging a chart in Highcharts within a Bootstrap modal when clicking on a thumbnail chart in Angular 6

My goal is to have Highcharts render to different div IDs. When I click on a thumbnail chart, the same chart should expand in a Bootstrap modal. I used the Hello Angular 6 StackBlitz editor for a demo, but since it's not saving properly, I'll share the HTML, TS, and package JSON files here. See the code below:

app.component.html

<div class="col-md-4 " (click)="openModal()" style="" id="chart1"></div>
<div (click)="openModal()" style="" id="chart2"></div>


<div class="backdrop" [ngStyle]="{'display':display}"></div>
<div class="modal" tabindex="-1" role="dialog"  [ngStyle]="{'display':display}">


  <div class="modal-dialog" role="document">


    <div class="modal-content">


      <div class="modal-header">


        <button type="button" class="close" aria-label="Close" (click)="onCloseHandled()"><span aria-hidden="true">&times;</span></button>


        <h4 class="modal-title">Model Title</h4>


      </div>


      <div class="modal-body">


        <p>Model body text</p>


      </div>


      <div class="modal-footer">


        <button type="button" class="btn btn-default" (click)="onCloseHandled()" >Close</button>


      </div>


    </div><!-- /.modal-content -->


  </div><!-- /.modal-dialog -->


</div><!-- /.modal !-->

app.component.ts

import { Component } from '@angular/core';
import * as Highcharts from 'highcharts';
import * as Exporting from 'highcharts/modules/exporting';
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
  display:none;
   public chartdata=[{"chartid":"chart1"},{"chartid":"chart2"}];
  openModal(){


       this.display=block; 


    }
    onCloseHandled(){


       this.display='none'; 


    }
  name = 'Angular 6';
  ngOnInit() {
    this.chartFunc('chart1');
    this.chartFunc('chart2');
  }

  chartFunc(chartId) {
    Highcharts.chart(chartId, {
      chart: {
        type: "spline"
      },
      title: {
        text: "Monthly Average Temperature"
      },

      series: [
        {
          name: 'Tokyo',
          data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }
      ]
    });
  }
}

package.json

{
  "name": "hello-angular-6",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
    "@angular/common": "6.0.0",
    "@angular/compiler": "6.0.0",
    "@angular/core": "6.0.0",
    "@angular/forms": "6.0.0",
    "@angular/platform-browser": "6.0.0",
    "@angular/platform-browser-dynamic": "6.0.0",
    "@angular/router": "6.0.0",
    "core-js": "2.5.5",
    "highcharts": "^7.1.1",
    "rxjs": "6.1.0",
    "zone.js": "0.8.26"
  },
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.10.0",
    "@angular/cli": "~7.0.2",
    "@angular/compiler-cli": "~7.0.0",
    "@angular/language-service": "~7.0.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.1"
  }
}

Answer №1

To accomplish this task, you can follow these steps and utilize the official Highcharts wrapper for Angular, highcharts-angular (https://github.com/highcharts/highcharts-angular):

  1. Start by creating chart and modal components
  2. Set up a chart service to handle the chart options
  3. Initialize the chart in both the chart and modal components using the data stored in the chart service
  4. For updating charts in both components, use Observables and set updateFromInput = true.

Check out the demo:

Explore the API reference for more details:

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

How can we limit the CSS properties that can be used in an interpolated manner by defining a restricted TS type for CSS props based on emotions?

When dealing with emotions, how can we specify a restricted TS type for the css prop to only allow certain css properties to be interpolated? For instance, consider the following scenario: // This is considered valid css = {{ color: 'white', ...

Encountering an issue when attempting to convert data to JSON in Angular 13, as the content type 'text/plain;charset=UTF-8' is not supported. This problem arises after sending data from

I've been attempting to submit a form using the following method: saveBuildcompany(): void { // @ts-ignore // @ts-ignore console.log(this.group?.value); let data2=this.group.value; let serializedForm = JSON.stringify(data2) ...

M.E.A.N - Suite for setting up and defining backend boundaries consisting of MongoDB, Express.js, Angular2, node.js

Seeking knowledge on how the frameworks and platforms Angular 2 and Express.js collaborate in the 'mean' approach is my main query. I am interested in understanding where the client-side ends and the server-side begins. After delving into this t ...

Transforming XML API data into JSON format using Angular framework

Currently, I am utilizing a service to connect to an API that returns data in XML format instead of JSON. The service looks like this: import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import 'rxjs/ ...

Trigger the D3 component to re-render in React after a state change occurs in the parent component

My React project consists of two components written in TypeScript. The first component contains menus, and I am using conditional rendering to display different content based on user selection. <Menu.Item name="graph" active={activeItem ...

What is the best way to incorporate websocket functionality for message push notifications with Django Rest Framework as the server-side backend and Angular 2

My goal is to incorporate websocket for sending push notifications to clients. I'm utilizing django-rest framework as the backend and angular2 as the frontend. I am aware that Django only supports the HTTP protocol, and I have been unabl ...

Storing a value in the store while dispatching an action is resulting in an undefined return

Is there a recommended method for passing a value into my store to update the current value? I've attempted the following code but encountered an issue where setSelectedCourseContentUid is being set as undefined in my component: setSelectedCourseCo ...

Functionality not functioning within Shadow DOM

After creating and exporting an Angular Element as a single script tag (user-poll.js), using the element on a host site is simple. Just include the following two lines: <user-poll></user-poll> <script src="path/to/user-poll.js"></sc ...

Is it possible for an object to receive notifications when a component object undergoes changes in Angular 2/4?

When working with Angular components, it's possible to pass a variable or object as @Input(). The component will be notified whenever the value of this input changes, which is pretty cool... I'm currently developing an application that features ...

Troubleshooting CORS policy problems in an Ionic Angular application

I am attempting to run the following function in my Ionic Angular application, where cloudFunctionUrl represents a cloud function within my Firebase project: import { HttpClient } from '@angular/common/http'; private http: HttpClient like(post) ...

Passing a service into a promise in Angular 2 using TypeScript

Is there a way to pass a service into a promise? I am currently working on a promise that will only resolve once all the http requests are complete. However, I am facing an issue where this.jiraService is undefined. Is there a method to pass it to the co ...

What are some ways to enhance the design of Material Input Text boxes and make them more compact?

I have been developing an Angular application using Material UI v7, but I am finding that the input controls are not as compact as I would like them to be. I have attempted to customize them without success. Can someone provide guidance on how to achieve m ...

What is the best way to specify parameter names and types for a TypeScript function that can take either one or two arguments?

Looking to create a function with two different calling options: function visit(url: string, options: Partial<VisitOptions>): void function visit(options: Partial<VisitOptions> & {url:string}): void I'm exploring the most effective w ...

Exploring the automatic type inference functionality of Typescript for generic classes

Although it may seem simple, I am struggling to pinpoint the cause of this error. I have been searching for a solution for quite some time, but I have yet to find one. class MyClass<T > { property: T = 5 // Error Here: Type '5' is not as ...

How to Unsubscribe from an Angular 2 Subscription Automatically After a Timeout

I am looking for a way to disregard the response from my API in case it takes too long to fetch. Currently, I am using this.http.get(mysqlUrl).subscribe() to retrieve the response. However, I would like to terminate that subscription if it exceeds a dur ...

How to implement postprocessing in React with React three fiber using EffectComposer and Passes like OutlinePass from the three.js addons

Struggling with the R3F -postprocessing library, I decided to turn to raw threejs classes: After delving into tutorials on extending third party libraries for R3F, I was able to configure the renderPass and outlinePass using TypeScript. Check out this hel ...

Large data sets may cause the Highchart Bar to not display properly

Currently, I am working on a web project that displays traffic usage in chart mode using Highchart Bar. The issue I am facing is that there are no errors thrown when running this code. <script type="text/javascript"> $(function () { $(&apos ...

Excluding node modules when not included in tsconfig

Within my Angular project, there is a single tsconfig file that stands alone without extending any other tsconfigs or including any additional properties. Towards the end of the file, we have the following snippet: "angularCompilerOptions": { ...

The vertical lines separating the buttons are not evenly centered

I need help to center a vertical line between my buttons in the middle of the header. Currently, the line goes up and my disconnect button is not aligned properly. Can you assist me in creating a responsive design? Thank you. https://i.sstatic.net/XIeiQ4E ...

Navigating to Angular component following Jersey and Spring SAML Security Single Sign-On verification

I have a project in progress that utilizes Angular for the front end and Jersey integrated with Spring SAML Security for Single Sign-On (SSO) authentication. My attempt involved initiating the app from Angular (http://localhost:4200), which then makes an ...