[英]Use Ternary Option with Chart.js and AngularJs
Hello I am very new to front-end development and I am utilizing Chart.js and Angular-Charts. 您好,我是前端开发的新手,我正在使用Chart.js和Angular-Charts。 I currently have a problem in which the X-axis labels are too long however in the JSON object I am being returned I have a property for short or long names... What I am trying to figure out if there is a way to perform a ternary operation based upon the length of the string and make a decision on which property to use:
我目前遇到一个问题,其中X轴标签太长,但是在返回的JSON对象中,我有一个简短或长名称的属性...我试图找出是否有一种方法可以执行根据字符串的长度进行三元运算,并决定要使用的属性:
HTML: 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"/>
I figured I could do something like this: 我想我可以做这样的事情:
chart-labels="profile['detail']['freq-graph']['long-labels'].length<20 ?profile['detail']['freq-graph']['short-labels':profile['detail']['freq-graph']['long-labels']]"
You have a missing bracket. 您缺少一个括号。
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.