我想要一个放置在图表内的按钮,用于将图表导出到 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
}
}
最终结果:
关于c# - 在图表控件中添加一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11905153/