如何在运行时设置ChartArea的BackImage?

问题描述 投票:5回答:3

任何人都知道为什么ChartArea.BackImage是string类型的属性?对于这种类型的Image属性来说,它是否更有意义?

或者换句话说,如何将ChartArea的背景图像设置为在运行时生成的图像(例如从GraphicPath对象)?

欢迎提出建议,谢谢。

c# asp.net charts mschart
3个回答
3
投票

使用NamedImage的解决方案

var chartBackImage = new Bitmap(1,1); //some bmp
chart1.Images.Add(new NamedImage("GiveSomeName", chartBackImage));
chart1.Areas[0].BackImage = Images[0].Name;
chart1.Areas[0].BackImageWrapMode = ChartImageWrapMode.Scaled; //extra

5
投票

正如MSDN在这里所述:ChartArea.BackImage Property。 BackImage属性是一个字符串值,表示图像文件的URL。

因此,要提供动态创建的图像,您需要创建图像(请查看以下有关使用System.Drawing命名空间中的对象来实现此目的的文章):Dynamic Image Generation with ASP.Net

哪个你可以:

1 - 存储到文件系统。

要么

2 - 设置HttpHandler以动态提供它。

见:Using HttpHandlers to serve image files

无论哪种方式,您都需要设置图像的路径,如下所示:

Chart.ChartAreas[0].BackImage = imagePath;

希望这可以帮助。


1
投票

同时设置图表和图表区域BackColor =“透明”以显示图像

<asp:Chart ID="Chart1" runat="server" BackColor="Transparent" >
    <Titles>
        <asp:Title Text="Bubble Chart"></asp:Title>
    </Titles>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1" BackColor="Transparent"></asp:ChartArea>
    </ChartAreas>
    <Legends>
        <asp:Legend LegendStyle="Table" Docking="Bottom" IsDockedInsideChartArea="false" Name="Legend1"></asp:Legend>
    </Legends>
</asp:Chart>
© www.soinside.com 2019 - 2024. All rights reserved.