在图表控件内添加一个按钮

3

我希望有一个按钮放在图表内部,用于将图表导出为Excel文件。我尝试过使用MapAreas,但无法确定如何将地图区域设置为图像或控件。是否有其他方法来实现这个功能?该按钮需要与图表相关联。

1个回答

0
你需要明白,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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接