문제

zedgraph에서 각 지점과 XAxis 모두 함께?

만약 내가한다면

myPane.XAxis.Type = AxisType.Text;
myPane.XAxis.Scale.TextLabels = array_of_string;

나는 이와 같은 Xaxis에 라벨을 얻는다

Enter image description here

그리고 내가한다면

for (int i = 0; i < myCurve.Points.Count; i++)
{
    PointPair pt = myCurve.Points[i];
    // Create a text label from the Y data value
    TextObj text = new TextObj(
        pt.Y.ToString("f0"), pt.X, pt.Y + 0.1,
        CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
    text.ZOrder = ZOrder.A_InFront;
    text.FontSpec.Angle = 0;
    myPane.GraphObjList.Add(text);
}

나는 이렇게 곡선에 레이블을 얻는다

Alt text, Pointlabel.png

그러나 동시에 두 가지를 모두 수행하면 곡선의 레이블이 사라집니다.

두 종류의 라벨을 결합하는 방법이 있습니까?

도움이 되었습니까?

해결책

질문을 명확히 한 후 답을 변경했습니다. 라벨을 올바르게 배치하는 것을 기억하면됩니다.

<%
  System.Collections.Generic.List<ZedGraphWebPointPair> points = new System.Collections.Generic.List<ZedGraphWebPointPair>();
  for (int i = 0; i < 15; i++)
  {
    // Let's have some fun with maths
    points.Add(new ZedGraphWebPointPair
    {
      X = i,
      Y = Math.Pow(i - 10, 2) * -1 + 120
    });
  }

  System.Collections.Generic.List<string> XAxisLabels = new System.Collections.Generic.List<string>();

  TestGraph.CurveList.Add(new ZedGraphWebLineItem { Color = System.Drawing.Color.Red });
  TestGraph.XAxis.Scale.FontSpec.Size = 9;

  int j = 1;
  foreach (ZedGraphWebPointPair point in points)
  {
    // Add the points we calculated
    TestGraph.CurveList[0].Points.Add(point);

    // Add the labels for the points
    TestGraph.GraphObjList.Add(new ZedGraphWebTextObj
    {
      Location =
      {
        CoordinateFrame = ZedGraph.CoordType.XChartFractionYScale,
        // Make sure we position them according to the CoordinateFrame
        X = Convert.ToSingle(j) / points.Count - 0.05f,
        Y = Convert.ToSingle(point.Y) + 3f,
        AlignV = ZedGraph.AlignV.Top
      },
      Text = point.Y.ToString(),
      FontSpec = { Angle = 90, Size = 9, Border = { IsVisible = false } }
    });

    // Add the labels for the XAxis
    XAxisLabels.Add(String.Format("P{0}", j));

    j++;
  }

  TestGraph.RenderGraph += delegate(ZedGraphWeb zgw, System.Drawing.Graphics g, ZedGraph.MasterPane mp)
  {
    ZedGraph.GraphPane gp = mp[0];
    gp.XAxis.Type = ZedGraph.AxisType.Text;
    gp.XAxis.Scale.TextLabels = XAxisLabels.ToArray();
  };

%>

이 코드는이 그래프를 생성합니다.

ZedGraph sample

다른 팁

축 유형이 텍스트 인 경우 아래 코드는 포인트의 x 코디네이트를 더 쉽게 얻을 수 있습니다.)

for (int tPoint = 0; tPoint < curve.Points.Count; tPoint++)
{
    TextObj text = new TextObj(curve.Points[tPoint].Y.ToString(), curve.Points[tPoint].X, curve.Points[tPoint].Y + 10);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top