C# 在图表控件中添加一个按钮
我希望在图表中放置一个按钮,将图表导出到excel文件。C# 在图表控件中添加一个按钮,c#,asp.net,C#,Asp.net,我希望在图表中放置一个按钮,将图表导出到excel文件。 我搞乱了MapAreas,但我不知道如何将MapArea设置为图像或控件。是否有其他方法来实现此功能?按钮需要以某种方式连接到图形。您需要了解ASP.NET图表控件只是一个图像,当您创建地图区域时,基本上是在该图像上指定可单击的点,因此(据我所知),地图区域不能有自定义背景图像或自定义控件 而是使用自定义图例: 来源: <asp:Chart ID="Chart1" runat="server" OnClick="Chart1
我搞乱了MapAreas,但我不知道如何将MapArea设置为图像或控件。是否有其他方法来实现此功能?按钮需要以某种方式连接到图形。您需要了解ASP.NET图表控件只是一个图像,当您创建地图区域时,基本上是在该图像上指定可单击的点,因此(据我所知),地图区域不能有自定义背景图像或自定义控件 而是使用自定义图例: 来源:
<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
}
}
最终结果:
<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
}
}