javascript - Canvas JS issue with Angular5 - Stack Overflow

import { Component, OnInit, ViewChild, ElementRef } from '@angularcore';import * as CanvasJS

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import * as CanvasJS from 'canvasjs';

@Component({
  selector: 'app-canvas-js',
  templateUrl: './canvas-jsponent.html',
  styleUrls: ['./canvas-jsponent.scss']
})
export class CanvasJsComponent implements OnInit {
canvasChartData: any;
  canvasChartDataCopy: number[];
  canvasChart: any;
  canvasChartContext: any;

  constructor() { }

  ngOnInit() {
  let dataPoints = [];
	let y = 0;		
	for ( var i = 0; i < 10000; i++ ) {		  
		y += Math.round(5 + Math.random() * (-5 - 5));	
		dataPoints.push({ y: y});
	}
	let chart = new CanvasJS.Chart("canvasjsContainer", {
		zoomEnabled: true,
	  animationEnabled: true,
		exportEnabled: true,
		title: {
			text: "Performance Demo - 10000 DataPoints"
		},
		subtitles:[{
			text: "Try Zooming and Panning"
		}],
		data: [
		{
			type: "line",                
			dataPoints: dataPoints
		}]
	});
		
	chart.render();
}
}
<div id="canvasjsContainer" style="height: 400px; width: 80%; margin: 10%;"></div>

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import * as CanvasJS from 'canvasjs';

@Component({
  selector: 'app-canvas-js',
  templateUrl: './canvas-js.ponent.html',
  styleUrls: ['./canvas-js.ponent.scss']
})
export class CanvasJsComponent implements OnInit {
canvasChartData: any;
  canvasChartDataCopy: number[];
  canvasChart: any;
  canvasChartContext: any;

  constructor() { }

  ngOnInit() {
  let dataPoints = [];
	let y = 0;		
	for ( var i = 0; i < 10000; i++ ) {		  
		y += Math.round(5 + Math.random() * (-5 - 5));	
		dataPoints.push({ y: y});
	}
	let chart = new CanvasJS.Chart("canvasjsContainer", {
		zoomEnabled: true,
	  animationEnabled: true,
		exportEnabled: true,
		title: {
			text: "Performance Demo - 10000 DataPoints"
		},
		subtitles:[{
			text: "Try Zooming and Panning"
		}],
		data: [
		{
			type: "line",                
			dataPoints: dataPoints
		}]
	});
		
	chart.render();
}
}
<div id="canvasjsContainer" style="height: 400px; width: 80%; margin: 10%;"></div>

I tried the sample given in official website of Canvas JS with Angular5. Tried with npm install. But on build of angular application, giving build error as: | export ColumnChart from '../charts/column'; | export StackedColumnChart from '../charts/stacked_column';

Not getting how to solve this issue. Using v1.8.0 of Canvas JS.

Share Improve this question asked Jun 26, 2018 at 4:37 CodeManCodeMan 1131 gold badge2 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

CanvasJS doesn’t have official npm package published yet. The package that you are using through npm is not an official one but from a third party.

You can save CanvasJS library (canvasjs.min.js) in source folder of your project (‘src/app’ or ‘src/app/assets/js’ or ‘src/app/lib’) and import it to your app using import * as CanvasJS from './canvasjs.min' (path may vary based on file location like ‘./assets/js/canvasjs.min’ or ‘./lib/canvasjs.min’).

Here is a sample project showing how to import CanvasJS Charts in your Angular 5 App.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745476727a4629380.html

相关推荐

  • javascript - Canvas JS issue with Angular5 - Stack Overflow

    import { Component, OnInit, ViewChild, ElementRef } from '@angularcore';import * as CanvasJS

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信