2010-03-11 44 views
6

Xem biểu đồ bên dưới. Tôi đang xây dựng biểu đồ theo chương trình, vì vậy không có cú pháp điều khiển asp.net.Cách thay đổi màu đường kẻ chia trục trong Điều khiển biểu đồ Microsoft (biểu đồ cột)

bar chart example

Làm thế nào để thay đổi màu sắc dòng lưới đó chéo ngang và dọc phía sau quầy bar? Như bạn có thể thấy tôi đã làm việc ra làm thế nào để thay đổi màu sắc trục thực tế, nhưng màu sắc lưới vẫn còn màu đen.

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(); 
    } 
} 

Trả lời

15

Không sao, tìm thấy câu trả lời:

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

Bạn cũng có thể làm điều đó trong HTML như thế này

<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

Đối với MS Chart, màu nền lưới có thể được thay đổi bằng cách làm theo tuyên bố.

myChart.ChartAreas["xSeries"].AxisX.MajorGrid.LineColor = Color.Blue; 
Các vấn đề liên quan