Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the axis divider line colors in Microsoft Chart Controls (column chart)

Tags:

.net

charts

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();
    }
}
like image 604
Nathan Ridley Avatar asked Mar 11 '10 22:03

Nathan Ridley


People also ask

How do I change the color of one grid in an Excel chart?

Select the worksheets for which you want to change the gridline color. Click File > Excel > Options. In the Advanced category, under Display options for this worksheet, make sure that the Show gridlines check box is selected. In the Gridline color box, click the color you want.

How do you color code a bar graph in Excel?

Select the bar chart or column chart, then click Kutools > Charts > Color Chart by Value. Then in the popped-out dialog, set the value range and the relative color as you need.

How do I change the color of my bar graph in Powerpoint?

Use the Chart Styles button to quickly change the color or style of the chart. Click the chart you want to change. In the upper-right corner, next to the chart, click Chart Styles. Click Color and pick the color scheme you want, or click Style and pick the option you want.

How do I change the axis range in Powerpoint?

In the Format Axis dialog box, click Scale, and under Value axis scale, modify any of the following options: To change the number at which the vertical (value) axis starts or ends, for the Minimum or Maximum option, type a different number in the Minimum box or the Maximum box.


2 Answers

Never mind, found the answer:

area.Axes[n].MajorGrid.LineColor = Color.Whatever;
like image 73
Nathan Ridley Avatar answered Sep 20 '22 02:09

Nathan Ridley


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>
like image 39
Simon_Weaver Avatar answered Sep 21 '22 02:09

Simon_Weaver