Aura 구성 요소에서 Chart.js 사용하기
Chart.js 라이브러리 업로드
Aura 프레임워크에서 타사 라이브러리를 로드할 때 필요한 모든 라이브러리를 정적 리소스에 업로드해야 합니다.
먼저 다음과 같이 Chart.min.js와 Chart.min.css를 추출하여 압축해 둡니다.
(필요하다면 다른 모든 라이브러리도 추가하십시오)
그런 다음 영업 포스에서
設定 > カスタムコード > 静的リソース > 新規
에서 정적 리소스를 업로드합니다.ファイル
는 위에서 만든 압축 파일을 지정합니다.Aura 구성 요소 샘플
Chart.js 설명서 에 있는 샘플 코드를 Aura 컴퍼넌트로 재현해 보았습니다.
ChartjsExample.cmp
<aura:component access="global" implements="flexipage:availableForAllPageTypes" >
<!-- External Libraries -->
<!-- グラフの初期化処理には js ファイルの読み込み完了を待つ必要があるので、 -->
<!-- js ファイルに対する ltng:require にのみ afterScriptsLoaded ハンドラーを指定する -->
<ltng:require styles="{!$Resource.ChartJSAsset + '/css/Chart.min.css'}" />
<ltng:require scripts="{!$Resource.ChartJSAsset + '/js/Chart.min.js'}"
afterScriptsLoaded="{!c.onAfterScriptsLoaded}"/>
<!-- User Inteface -->
<div>
<div class="slds-box slds-theme_default">
<div class="chart-container" >
<canvas aura:id="canvas" ></canvas>
</div>
</div>
</div>
</aura:component>
ChartjsExampleController.js
({
onAfterScriptsLoaded : function(c, e, h) {
// cnavas 要素の取得には aura:id 属性をキーとして、コンポーネントに対し .find 関数を利用する
const ctx = c.find('canvas').getElement().getContext('2d');
const myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
}
})
Reference
이 문제에 관하여(Aura 구성 요소에서 Chart.js 사용하기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hrk623/items/3b898180d3fc6aade285텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)