Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change type dynamically #251

Open
manvfx opened this issue Jan 11, 2018 · 3 comments
Open

How to change type dynamically #251

manvfx opened this issue Jan 11, 2018 · 3 comments

Comments

@manvfx
Copy link

manvfx commented Jan 11, 2018

I want change type highcharts with click button.
for example:

html file:

<button (click)="barChart()"></button>

ts file:

import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material';
import { ChartDialogComponent } from '../../misc/dialogs/chart-dialog/chart-dialog.component';
import { Chart } from 'angular-highcharts';

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

  chartTitle : string;
  chartType : string;

  constructor() { }

  ngOnInit() {
  }


  chart = new Chart({
      chart: {
        type: this.chartType
      },
      title: {
        text: 'title'
      },
      credits: {
        enabled: false
      },
      series: [{
        name: 'Line 1',
        data: [1, 2, 3]
      }],      
    });
  
  barChart(){
    console.log('bar chart');
    debugger;
    if (this.chart.options.chart.type === 'line') {
        this.chart.options.chart.type = 'bar'
        debugger;
    } else {
        this.chart.options.chart.type = 'line'
    }
  }
}

@bheda91
Copy link

bheda91 commented Jan 23, 2018

There is option to update anything in chart, for that you have to store chart instance variable from onload event of chart.

In HTML,
<chart [options]="chartOptions" (load)="saveInstance($event.context)"></chart>

How to load chart instance

Using that instance, you may use like below

saveInstance(chartInstance) { 
     this.chartInstance = chartInstance
}

updateChartType() {
    this.chartInstance.update({
      chart: {
        type: chartType // Anything you want
      }
    });
}

How to update chart

Hope this will help you!

@satyendrasinghpanwar
Copy link

@bheda91 - update methods throws error when we change chart type

@bheda91
Copy link

bheda91 commented Aug 29, 2018

@satyendrasinghpanwar Can you please tell me which error you get? And if possible, show me your code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants