Asp.net + chart.customizelegend没有影响 [英] Asp.net + chart.customizelegend not having impact

查看:61
本文介绍了Asp.net + chart.customizelegend没有影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我被要求为办公室放置一些图形,而客户端有一个问题,在图表的传说。



做了一些研究之后,我发现了这个MS文件:

Chart.CustomizeLegend事件(System.Web.UI.DataVisualization.Charting ) [ ^ ]



据说告诉我们如何自定义图表图例项



尽管我的尝试,我似乎根本无法影响所说的物品。



我的尝试:



标记

Hi everyone,

I was asked to put a number of graphics together for the office, and the "client" has a problem with the rectangles used within the chart's legend.

After doing some "research", I came across this MS document:
Chart.CustomizeLegend Event (System.Web.UI.DataVisualization.Charting)[^]

Which supposedly tells us how to "customize the chart legend items".

Despite my attempts, I cannot seem to affect said items at all.

What I have tried:

Markup:

<asp:Chart ID="PieChart" runat="server" Width="365px" OnCustomizeLegend="PieChart_CustomizeLegend">...



代码背后


Code Behind:

protected void PieChart_CustomizeLegend(object sender, CustomizeLegendEventArgs e)
{
    foreach (LegendItem lgItem in e.LegendItems)
    {
        lgItem.MarkerStyle = MarkerStyle.Diamond;
    }
}





你碰巧知道我错过了什么吗?



感谢您的输入。



Would you happen to know what is it that I am missing?

Thanks for your input.

推荐答案

您好,



请原谅我没有给你更多时间来提出一些想法;在这之后,我会解释我做了什么来得到我需要的东西并留下一个我无法找到任何问题的问题。



总而言之,定制传奇项目并不像我预期的那样直截了当。我必须采取以下步骤:



1 )图表的图例必须设置为:LegendItemOrder =SameAsSeriesOrder,否则结果没有组织。



2 )修改了CustomizeLegend事件,如下所示:

Hi there,

Please forgive me for not giving you all more time to come up with some ideas; here after, I'll explain what I did to get what I needed and leave all a question I was not able to find anything about.

All in all, customizing legend items was not as straight forward as I expected. I had to take the following steps:

1) Chart's legend has to be set to : LegendItemOrder="SameAsSeriesOrder", otherwise the result is all unorganized.

2) Modified the CustomizeLegend event as follows:
protected void PieChart_CustomizeLegend(object sender, CustomizeLegendEventArgs e)
        {
            foreach (LegendItem lgItem in e.LegendItems)
            {
                if (!string.IsNullOrEmpty(lgItem.Name))
                {
                    LegendItem cstItem = new LegendItem();
                    cstItem.ImageStyle = LegendImageStyle.Marker;
                    cstItem.MarkerColor = lgItem.Color;
                    cstItem.Name = lgItem.Name;
                    cstItem.MarkerStyle = MarkerStyle.Diamond;
                    cstItem.MarkerSize = 15;
                    ((Chart)sender).Legends[0].CustomItems.Add(cstItem);
                }
            }
           
            ((Chart)sender).Series[0].IsVisibleInLegend = false;

            ((Chart)sender).CustomizeLegend -= PieChart_CustomizeLegend;
        }



请注意,在事件内设置系列 IsVisibleInLegend 属性,而不是在标记中。如果在那里完成,传说中不会有任何内容。



此外,我注意到,不知何故我无法解释, CustomizeLegend 事件开始被解雇三次,给出了不受欢迎的结果,因此取消了订阅。


Note that set the series IsVisibleInLegend property inside the event and not in the markup. If done in there, nothing will be drawn in the legend.

Moreover, I noticed that, somehow I cannot explain, the CustomizeLegend event was begin fired three times, giving undesired results, thus the un-subscription.


这篇关于Asp.net + chart.customizelegend没有影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆