6

See the chart below. I'm building the chart programatically, so no asp.net control syntax please.

bar chart example

How do I change the grid line colours that cross horizontally and vertically behind the bars? As you can see I've worked out how to change the actual axis colours, but the grid colours remain black.

public ActionResult RenderChart()
{
    var chart = new Chart();
    double[] yValues = { 65.62, 75.54, 60.45, 55.73, 70.42 };
    string[] xValues = { "Michelle", "Sarah", "Aliece", "Belinda", "Amanda" };
    var series = new Series
    {
        Name = "Default",
        ChartType = SeriesChartType.Column,
        CustomProperties = "DrawingStyle=Cylinder"
    };
    series.Points.DataBindXY(xValues, yValues);

    chart.BorderlineColor = Color.Silver;
    var area = new ChartArea("Test");
    area.AxisX.LineColor = Color.DarkGray;
    area.AxisY.LineColor = Color.DarkGray;

    chart.ChartAreas.Add(area);
    chart.Series.Add(series);
    series.IsValueShownAsLabel = true;

    series.Font = new Font(series.Font, FontStyle.Bold);
    chart.Width = 400;
    chart.Height = 300;

    using(var ms = new MemoryStream())
    {
        chart.SaveImage(ms, ChartImageFormat.Png);
        Response.ContentType = "image/png";
        Response.BinaryWrite(ms.ToArray());
        return new EmptyResult();
    }
}

3 Answers 3

17

Never mind, found the answer:

area.Axes[n].MajorGrid.LineColor = Color.Whatever;
4

You can also do it in the HTML like this

 <asp:Chart ID="chartOutstandingOrders" runat="server" Width="500" Palette="Bright">

            <Series>
                <asp:Series ChartType="Line" Name="seriesBackorder">
                </asp:Series>
            </Series>

            <ChartAreas>
                <asp:ChartArea Name="ChartArea1" BorderColor="#339966">
                    <AxisX LineColor="Gray">
                        <MajorGrid LineColor="LightGray" />
                    </AxisX>
                    <AxisY LineColor="Gray">
                        <MajorGrid LineColor="LightGray" />
                    </AxisY>
                </asp:ChartArea>
            </ChartAreas>

        </asp:Chart>
0

For MS Chart,background grid colour can be changed by following statement.

myChart.ChartAreas["xSeries"].AxisX.MajorGrid.LineColor = Color.Blue;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.