问题描述
我有一个堆积的条形图,显示了两类信息.现在,我需要在小节的末尾显示小节的总数.我已经附上了一个模型,该模型显示了我要执行的操作-红色数字是我要添加的内容.
I've got a stacked bar graph that shows two categories of information. Now I have a requirement to show the total of the bars at the end of the bar. I've attached a mock-up showing what I'm trying to do -- the numbers in red are what I'm trying to add.
我在文档中找不到有关如何添加总计或如何添加注释(也可以使用)的任何内容.
I couldn't find anything in the documentation on how to add totals, or on how to add annotations (which would also work).
推荐答案
我设法通过在现有条形图的顶部添加总值的散点图来使其工作.
I managed to get this to work by adding a Scatter chart of total values on top of the existing bar chart.
http://michaelandlisa.us/Images/Forums/stacked_with_totals_scatter.png
我还将系列的颜色设置为透明",这样就不会出现该点,然后我分别将X和Y分别增大了15和12.我还将样式设置为粗体,并将格式设置为"{point.y:n0}".这是相关的MVC代码(其中total是一个对象列表):
I also set the color on the series to "transparent" so the point wouldn't show up, and then I bumped the X and Y by 15 and 12 respectively. I also set the style to Bold, and set the format to "{point.y:n0}". Here's the relevant MVC code (where totals is a List of object):
.DataSeries(series => series.Scatter()
.Data(totals)
.CollectionAlias("Total")
.Color("transparent")
.AddToLegend(false).DataPointText(dtp =>
{
dtp.Enabled(true);
dtp.Format("{point.y:n0}");
dtp.Style(s => s.FontWeight(FontWeight.Bold));
dtp.Color("red");
dtp.X(15);
dtp.Y(12);
}))
这篇关于带有总计的ShieldUI堆叠条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!