简体   繁体   English

Kendo图表列多行标签

[英]Kendo Chart Column Multi-Line Labels

I recently inherited a project that makes extensive use of Kendo charts, with a request to add some information to column labels. 我最近继承了一个项目,该项目广泛使用Kendo图表,并要求向列标签添加一些信息。 The labels currently contain an integer and a percentage, and the revision would add an additional percentage value. 标签当前包含一个整数和一个百分比,修订版将添加一个附加的百分比值。 Since the labels are getting a little long, they need to be split across multiple lines. 由于标签会变长,因此需要将它们分成多行。

So a column label that currently reads: 因此,当前显示的列标签为:

3, 0.00% 3、0.00%

would now read 现在会读

3 3

0.00% 0.00%

9.99% 9.99%

The code is arranged MVC style, so the code determining each label looks similar to the following: 该代码采用MVC样式排列,因此确定每个标签的代码与以下内容类似:

.Labels(labels => labels.Visible(true).Position(ChartBarLabelsPosition.OutsideEnd)
                        .Template("#= value #, #= kendo.format('{0:P}', dataItem.GetPercent)#"))
                        .Tooltip(t => t.Template("#=series.name#: #= value #, #= kendo.format('{0:P}', dataItem.GetPercent)#").Visible(true));

It seems like this should be a simple thing, but I can't find the syntax for properly working line breaks into the labels. 看来这应该是一件简单的事情,但是我找不到正确地将换行符插入标签的语法。 Kendo does seem to attempt to interpret <br /> entries, but these disrupt the flow of the chart and cause all following label values to be displayed below the entire chart rather than in place just above the column. Kendo似乎确实试图解释<br />条目,但是这些中断了图表的流程,并导致所有随后的标签值显示在整个图表下方,而不是显示在列上方。 Some forum posts I have searched assert that this is not currently possible in Kendo, but also mention that it 'will be possible in 2014' (most of these are older posts though, and since I don't know much about kendo, I could be misunderstanding which labels they are referring to). 我搜索过的一些论坛帖子断言,剑道目前无法做到这一点,但同时提到“在2014年将成为可能”(尽管其中大多数是较早的帖子,由于我对剑道了解不多,我可以误解了他们指的是哪个标签)。

Can anyone provide me with the proper syntax for inserting a line break into this type of label (from code) or a possible workaround if the functionality is not currently supported? 谁能为我提供用于在此类型的标签中插入换行符的正确语法(来自代码),或者如果当前不支持该功能,则可以采用解决方法?

Thank you! 谢谢!

UPDATE I have found the <tspan> workaround, which does help a little but still looks pretty bad since my charts are resized dynamically with the page (so, for a stacked bar chart, the widths and starting positions of each column are not static). 更新我发现了<tspan>解决方法,虽然确实有所帮助,但仍然看起来很糟糕,因为我的图表随页面动态调整大小(因此,对于堆积的条形图,每列的宽度和起始位置不是静态的) 。 The <tspan> tag respects the y coordinate of each label but not its x coordinate, so that has to be set individually for each column; <tspan>标记遵守每个标签的y坐标,而不考虑其x坐标,因此必须为每一列分别设置; if left unset, the labels for all columns will appear at the leftmost side of the chart where the y axis values are. 如果未设置,则所有列的标签将显示在y轴值所在的图表的最左侧。 Since the charts are dynamic, there is no "correct" static value to put there and I have been unable to find a way to fetch a column's starting position from within the template code. 由于图表是动态的,因此这里没有“正确的”静态值,因此我无法找到一种从模板代码中获取列的起始位置的方法。 Is there any way to correct this such that the <tspan> workaround becomes a viable option? 有什么办法可以纠正此问题,以使<tspan>解决方法成为可行的选择?

(Workaround found here ) (在此处找到解决方法)

From 2014-Q2 versions, Telerik / KendoUI finaly implemented the \\n See the documentation: 从2014年第二季度开始,Telerik / KendoUI最终实现了\\ n请参阅文档:

The text can be split into multiple lines by using line feed characters ("\\n"). 通过使用换行符(“ \\ n”),可以将文本分成多行。

http://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/chart#configuration-categoryAxis.title.text http://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/chart#configuration-categoryAxis.title.text

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

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