简体   繁体   English

Angular5的Canvas JS问题

[英]Canvas JS issue with Angular5

 import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; import * as CanvasJS from 'canvasjs'; @Component({ selector: 'app-canvas-js', templateUrl: './canvas-js.component.html', styleUrls: ['./canvas-js.component.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. 我尝试使用Angular5在Canvas JS官方网站上给出的示例。 Tried with npm install. 尝试使用npm install。 But on build of angular application, giving build error as: | 但是在构建角度应用程序时,给出如下构建错误: export ColumnChart from '../charts/column'; 从'../charts/column'导出ColumnChart; | | export StackedColumnChart from '../charts/stacked_column'; 从'../charts/stacked_column'导出StackedColumnChart;

Not getting how to solve this issue. 没有得到如何解决这个问题。 Using v1.8.0 of Canvas JS. 使用的是Canvas JS v1.8.0。

CanvasJS doesn't have official npm package published yet. CanvasJS尚未发布官方的npm软件包。 The package that you are using through npm is not an official one but from a third party. 通过npm使用的软件包不是官方软件包,而是第三方软件包。

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'). 您可以将CanvasJS库(canvasjs.min.js)保存在项目的源文件夹(“ src / app”或“ src / app / assets / js”或“ src / app / lib”)中,然后使用以下方式将其导入到您的应用中从'./canvasjs.min'中将*作为CanvasJS导入(路径可能会根据'./assets/js/canvasjs.min'或'./lib/canvasjs.min'等文件位置而有所不同)。

Here is a sample project showing how to import CanvasJS Charts in your Angular 5 App. 这是一个示例项目,显示了如何在Angular 5 App中导入CanvasJS图表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM