Microsoft Chart 控制图例项目排序
我有一张包含 8 个系列的图表 - 将它们称为 S1 到 S8。它们在图表的系列列表中按顺序排列,并使用自定义图例项 (Legend.CustomItems) 呈现。一切工作正常,除了当图例换行到新行时图例中项目的显示方式似乎存在错误。
我希望这些项目按行显示:
S1 S2 S3 S4
S5 S6 S7 S8
不幸的是,当图例检测到它将需要两行时,它会在水平方向之前垂直填充,如下所示:
S1 S3 S5 S7
S2 S4 S6 S8
有什么方法可以正确排列项目吗?这是控件的错误吗?
var chart = new Chart();
// More chart setup
foreach(var s in chart.Series)
{
if (simpleLegend) chart.Legends[0].CustomItems.Add(s.Color, s.LegendText);
else
{
var legendItem = new LegendItem();
// Legend item customization
chart.Legends[0].CustomItems.Add(legendItem);
}
}
编辑
为了明确起见,问题在于图例项的布局,而不是顺序。根据图例项的长度,我最终可能会得到以下布局:
S1 S3 S5 S7 S8
S2 S4 S6
I've got a chart with 8 series - call them S1 through S8. They're in order in the chart's list of series, and they're presented using custom legend items (Legend.CustomItems). Everything works fine, except there seems to be a bug with how items are displayed in the legend when the legend wraps around to a new line.
I'd like the items to be displayed in rows:
S1 S2 S3 S4
S5 S6 S7 S8
Unfortunately, it seems like when the legend detects that it's going to take two rows, it fills in vertically before horizontally, like so:
S1 S3 S5 S7
S2 S4 S6 S8
Is there any way to get the items arranged properly? Is this a bug with the controls?
var chart = new Chart();
// More chart setup
foreach(var s in chart.Series)
{
if (simpleLegend) chart.Legends[0].CustomItems.Add(s.Color, s.LegendText);
else
{
var legendItem = new LegendItem();
// Legend item customization
chart.Legends[0].CustomItems.Add(legendItem);
}
}
EDIT
To make it clear, the issue is with the layout of the legend items, not the order. Depending on the length of the legend items, I may end up with this layout:
S1 S3 S5 S7 S8
S2 S4 S6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
CustomizeLegend
事件中排列它们。将
OnCustomizeLegend="Chart1_CustomizeLegend"
添加到图表标记中或将其绑定到后面的代码中。然后创建处理程序:或者您可以首先创建一些集合,并通过按所需顺序引用现有图例项目来填充它,然后清除
LegendItems
并立即插入所有项目。我认为你可以用一种对所有项目编号都有效的方式来编写它,但我把它留给你;)。详细信息:http://msdn.microsoft.com/en-us/library/ dd488245.aspx
(我知道这个问题已经有近 2 年历史了,但也许有同样问题的人(比如今天的我)会发现这很有帮助。)
You can arrange them in
CustomizeLegend
event.Add
OnCustomizeLegend="Chart1_CustomizeLegend"
to your Chart markup or bind it in code behind. Then create handler:Or you can create some collection first and fill it by referencing existing legend items in desired order, then clearing
LegendItems
and inserting all items at once. I think you can write it in a way it will be valid for all items number, but I leave it to you ;).More info: http://msdn.microsoft.com/en-us/library/dd488245.aspx
(I know this question is almost 2 years old but maybe someone with same problem (like me today) will find this helpful.)