C#: How To Crosshatch A Bar In An ASP.Net Bar Chart

寵の児 提交于 2019-12-24 02:16:51

问题


I have an asp.net bar chart that I'm trying to add cross hatching to one of the bars. I cannot figure out how to do it.

I want to crosshatch the 4th bar (from the left) in the chart. I tried the following code below but it doesn't work.

Chart1.Series["Actual"].Points[3].Color = ColorTranslator.FromHtml("#ffffff");
Chart1.Series["Actual"].Points[3].BorderColor = ColorTranslator.FromHtml("#d0d0d0");
Chart1.Series["Actual"].Points[3].BackSecondaryColor = ColorTranslator.FromHtml("#d0d0d0");
Chart1.Series["Actual"].Points[3].BackHatchStyle = ChartHatchStyle.LightUpwardDiagonal;

Can you tell me how to do this please?

Andy


回答1:


EDIT:

Using code-behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        for (int x = 1; x <= 5; x++)
            Chart1.Series[0].Points.AddXY(x, 10 * x);

        Chart1.Series[0].Points[3].BackHatchStyle = ChartHatchStyle.Cross;
        Chart1.Series[0].Points[3].Color = Color.Orange;
    }

The BackHatchStyle should do it:

ASPX:

   <asp:Chart ID="Chart1" runat="server" Height="400px" Width="600px">
        <series>
            <asp:Series Name="Series1">
                <Points>
                    <asp:DataPoint XValue="1" YValues="10" />
                    <asp:DataPoint XValue="2" YValues="20" />
                    <asp:DataPoint XValue="3" YValues="30" />
                    <asp:DataPoint BackHatchStyle="WideUpwardDiagonal" Color="Red" XValue="4" YValues="40" />
                    <asp:DataPoint XValue="5" YValues="50" />
                </Points>
            </asp:Series>
        </series>
        <chartareas>
            <asp:ChartArea Name="ChartArea1">
            </asp:ChartArea>
        </chartareas>
    </asp:Chart>


来源:https://stackoverflow.com/questions/41880866/c-how-to-crosshatch-a-bar-in-an-asp-net-bar-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!