Chart control change axis color

2019-09-14 22:35发布

问题:

This is my Chart control Graph:

I want to remove axis black lines from the left side and add blue line as a frame for all the graph like at the button. I have search for all the properties and try to change color but the default color still remained

回答1:

if you want to customize a chart you could draw your own dynamically:

Example in VB.net:

 Const GraphHeight As Integer = 100
    Const GraphWidth As Integer = 200
    Dim cIMG As New Bitmap(GraphWidth, GraphHeight)
    Dim G As Graphics = Graphics.FromImage(cIMG)
    Dim red As Integer = 0
    Dim pnts(4) As Point
    pnts(0) = New Point(0, GraphHeight - 0)
    pnts(1) = New Point(50, GraphHeight - 80)
    pnts(2) = New Point(100, GraphHeight - 50)
    pnts(3) = New Point(150, GraphHeight - 40)
    pnts(4) = New Point(200, GraphHeight - 20)
    G.DrawLines(Pens.Blue, pnts)
    PictureBox1.Image = cIMG

Example in C#:

const int GraphHeight = 100;
const int GraphWidth = 200;
Bitmap cIMG = new Bitmap(GraphWidth, GraphHeight);
Graphics G = Graphics.FromImage(cIMG);
int red = 0;
Point[] pnts = new Point[5];
pnts(0) = new Point(0, GraphHeight - 0);
pnts(1) = new Point(50, GraphHeight - 80);
pnts(2) = new Point(100, GraphHeight - 50);
pnts(3) = new Point(150, GraphHeight - 40);
pnts(4) = new Point(200, GraphHeight - 20);
G.DrawLines(Pens.Blue, pnts);
PictureBox1.Image = cIMG;

you could use a loop to draw the grid

Example



回答2:

I know this old post but to answer the OP question.

Changes the line color and line style

Chart1.ChartAreas(0).AxisY.LineColor = Color.Blue
Chart1.ChartAreas(0).AxisY.LineDashStyle =ChartDashStyle.Dot

If want to remove the tick marks you use this code

Chart1.ChartAreas(0).AxisY.MajorTickMark.Enabled = False
Chart1.ChartAreas(0).AxisY.MinorTickMark.Enabled = False


标签: c# .net charts