views:

320

answers:

1

How can i set a custom color as border color for the ASP.NET 3.5 chart control series in code behind(C#) ? I need a codebehind implementation of the following (which is in ASPX)

  <ChartAreas>
        <asp:ChartArea Name="ChartArea1" AlignmentOrientation="All"> 
        <AxisX>
        <MajorGrid LineColor="#EEEEEE" />
        <MinorGrid LineColor="#EEEEEE" />
        </AxisX>
        <AxisY>
        <MajorGrid LineColor="#EEEEEE" />
        <MinorGrid LineColor="#EEEEEE" />
        </AxisY>
        </asp:ChartArea>
    </ChartAreas>

I want to change the MajorGrid line color in my codebehind as RGB(125,135,111)

+1  A: 

Make sure you give your Charts an ID and runat="server"...

<asp:Chart ID="ChartTest" runat="server" Width="800px" Height="300px">
</asp:Chart>

Then you can directly access the LineColor properties:

ChartTest.ChartAreas[0].AxisY2.LineColor = Color.Black;

Or using a custom colour (from a Hex string):

Color customColour = System.Drawing.ColorTranslator.FromHtml("EEEEEE");
ChartTest.ChartAreas[0].AxisY2.LineColor = customColour
Anthony M. Powers
I am looking for applying a custom color
I edited the answer to show how to do this.
Matt Warren