簡體   English   中英

將三元選項與Chart.js和AngularJs一起使用

[英]Use Ternary Option with Chart.js and AngularJs

您好,我是前端開發的新手,我正在使用Chart.js和Angular-Charts。 我目前遇到一個問題,其中X軸標簽太長,但是在返回的JSON對象中,我有一個簡短或長名稱的屬性...我試圖找出是否有一種方法可以執行根據字符串的長度進行三元運算,並決定要使用的屬性:

HTML:

<canvas canvas id="base" class="chart-horizontal-bar" height="400px"
                chart-labels="profile['detail']['freq-graph']['long-labels']"
                chart-data="[profile['detail']['freq-graph'].data]"
                chart-colours="['#008080']"
                chart-legend="false"/>

我想我可以做這樣的事情:

 chart-labels="profile['detail']['freq-graph']['long-labels'].length<20 ?profile['detail']['freq-graph']['short-labels':profile['detail']['freq-graph']['long-labels']]"

您缺少一個括號。

chart-labels="profile['detail']['freq-graph']['long-labels'].length < 20 ? profile['detail']['freq-graph']['short-labels'] : profile['detail']['freq-graph']['long-labels']"
//                                                                                                                      ^^^

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM