c# - 在图表控件中添加一个按钮

标签 c# asp.net

我想要一个放置在图表内的按钮,用于将图表导出到 Excel 文件。 我弄乱了 MapAreas,但我不知道如何将 map 区域设置为图像或控件。有没有不同的方法来实现这个功能?该按钮需要以某种方式附加到图形上。

最佳答案

您需要了解 ASP.NET 图表控件只是一个图像,当您创建 MapAreas 时,您基本上是在此图像上指定可点击点,因此(据我所知)MapArea 不能有自定义背景图片或自定义控件。

改为使用自定义图例:

来源:

    <asp:Chart ID="Chart1" runat="server" OnClick="Chart1_Click1">
        <Series>
            <asp:Series YValuesPerPoint="2" IsVisibleInLegend="false" Name="Series1" ChartType="Column">
                <Points>
                    <asp:DataPoint AxisLabel="Product 1" YValues="100" />
                    <asp:DataPoint AxisLabel="Product 2" YValues="300" />
                </Points>
            </asp:Series>
        </Series>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1">
            </asp:ChartArea>
        </ChartAreas>
        <Legends>
            <asp:Legend Title="Export options:">
                <CustomItems>
                    <asp:LegendItem
                    Name="Export To Excel" 
                    PostBackValue="Export From Legend"  
                    Color="Green">
                    </asp:LegendItem>
                </CustomItems>
            </asp:Legend>
        </Legends>
    </asp:Chart>

代码隐藏:

protected void Chart1_Click1(object sender, ImageMapEventArgs e)
{
    if (e.PostBackValue == "Export From Legend")
    {
       //Handle the exporting to Excel
    }
}

最终结果:

enter image description here

关于c# - 在图表控件中添加一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11905153/

相关文章:

c# - Autofac 参数传递和 Autowiring

c# - 在服务器上加载报表失败 - Crystal Reports

c# - .NET 4 的路由问题

c# - 如何反序列化同一对象中具有重复属性名称的 JSON

ASP.NET View 状态使 iPad 浏览器崩溃

c# - ASP.Net 异步 HTTP 文件上传处理程序

java - 验证用户从文本框输入的内容#

c# - RTF - 围绕一个词框?

asp.net - FileUpload 控件中仅显示文件名

javascript - 将输入键绑定(bind)到 asp 网络链接按钮转发器