없음는 Interval
는 Axis
속성입니다 만 한있을 수 있습니다.
그림 눈금 선 및 레이블로이 제한을 해결할 수 있습니다.
당신이 GridLine
표시 할 위치의 당신이 DataPoints
의 인덱스를 즉, 정지 점의 목록을 가정 해 봅시다 :
List<int> stops = new List<int>();
을 몇 가지 테스트 번호 stops.AddRange(new[] { 12, 23, 42, 52, 82 });
를 추가 한 후에 우리가 PostPaint
를 코딩 할 수 있습니다 Chart
의 이벤트를 그리는 이벤트 :
private void chart_PostPaint(object sender, ChartPaintEventArgs e)
{
Graphics g = e.ChartGraphics.Graphics;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
ChartArea ca = chart.ChartAreas[0];
Font font = ca.AxisX.LabelStyle.Font;
Color col = ca.AxisX.MajorGrid.LineColor;
int padding = 10; // pad the labels from the axis
double aymin = ca.AxisY.Minimum;
double aymax = ca.AxisY.Maximum;
int y0 = (int)ca.AxisY.ValueToPixelPosition(aymin);
int y1 = (int)ca.AxisY.ValueToPixelPosition(aymax);
foreach (int sx in stops)
{
int x = (int)ca.AxisX.ValueToPixelPosition(chart.Series[0].Points[sx].XValue);
using (Pen pen = new Pen(col))
g.DrawLine(pen, x, y0, x, y1);
string s = chart.Series[0].Points[sx].XValue + "";
if (ca.AxisX.LabelStyle.Format != "") s = string.Format(ax.LabelStyle.Format, s);
SizeF sz = g.MeasureString(s, font, 999);
g.DrawString(s, font, Brushes.Black, (int)(x - sz.Width/2) , y0 + padding);
}
}
원본을 끄고 난 후에 0
![enter image description here](https://i.stack.imgur.com/XtIMZ.png)
참고 : 대부분의 코드
- 그냥 간단한 준비 및 참조입니다 123,194,358,등
ChartArea ca = chart.ChartAreas[0];
ca.AxisX.MajorGrid.Enabled = false;
ca.AxisX.MajorTickMark.Enabled = false;
ca.AxisX.LabelStyle.Enabled = false;
..이는 결과이다. 실제 그림은 내 목록에 DataPoint
인덱스을 저장 한
좌표를 얻을 수있는이 방법과 서너 줄 이상 ...입니다. 사용자 지정 GridLines
이 DataPoints
과 독립적 이도록하려면 Values
을 저장하고 목록을으로 변경하고 의 두 가지 참조를 중지 값 sx
에 직접 액세스 할 수 있습니다.
변화를 맞게 패딩 값 ..
우리는 그들이 실제로 Auto
로 설정하는 경우에도, 자유롭게 축 '최소값과 최대 값을 액세스 할 수 있습니다. 이는 우리가 Paint
이벤트에 있기 때문입니다. 그렇지 않으면 우리는
- 뿐만 아니라
Black
라벨 브러시 동적을 자유롭게 있습니다 .. ChartArea
에 RecalculateAxesScale()
를 호출해야 할 것입니다 ..
출처
2017-03-30 10:48:27
TaW
아니요, 간격은 축 속성이며 하나만있을 수 있습니다. – TaW
문제를 해결 했습니까? – TaW