【问题标题】:Draw a Graph in C# using zedGraph使用 zedGraph 在 C# 中绘制图形
【发布时间】:2010-01-14 19:23:10
【问题描述】:

我需要创建一个具有以下属性的图表:
X 轴代表学校名称。
Y 轴用于类名称。
在点 (x,y) 中,我需要放置一个点,它的颜色将代表学生人数(颜色越深表示学生人数越多)。
我正在使用 ZedGraph(使用该示例:http://zedgraph.org/wiki/index.php?title=Gradient-By-Value_Demo),但我不知道如何将点(并确定它的暗级)放在正确的位置(将其与学校名称和班级名称进行比较)。
另外,我不知道如何让 X 和 Y 轴显示学校名称和班级名称。
我怎样才能做到这一点? (不必在 zedGraph 中)。
非常感谢!

【问题讨论】:

    标签: c# graph zedgraph


    【解决方案1】:

    问题在于 ZedGraph 以一种有点奇怪的方式处理文本类型的比例。因此,当您同时拥有两种 Text 类型的比例时,几乎不可能正确显示数据。

    但是你可以骗ZG一点。

    整个技巧是使用隐藏比例的坐标显示数据,同时显示第二个假比例。

    string[] schools = { "A", "B", "C" };
    string[] classes = { "cl. 1", "cl. 2", "cl. 3" };
    
    var pane = zg1.GraphPane;
    Random x = new Random();
    
    // Hide the basic scale, show the second with text labels
    pane.X2Axis.Type = AxisType.Text;
    pane.X2Axis.IsVisible = true;
    pane.Y2Axis.Type = AxisType.Text;
    pane.Y2Axis.IsVisible = true;
    pane.XAxis.Scale.IsVisible = false;
    pane.YAxis.Scale.IsVisible = false;
    
    pane.X2Axis.Scale.TextLabels = schools;
    pane.Y2Axis.Scale.TextLabels = classes;
    
    // Main problem - synchronize the scales correctly            
    pane.XAxis.Scale.Min = -0.5;
    pane.XAxis.Scale.Max = schools.Count() - 0.5;
    pane.YAxis.Scale.Min = -0.5;
    pane.YAxis.Scale.Max = classes.Count() - 0.5;
    
    pane.YAxis.MajorGrid.IsZeroLine = false;
    
    // generate some fake data
    PointPairList list = new PointPairList();
       for(int i=0;i<schools.Count();i++)
          for (int j = 0; j < classes.Count(); j++)
          {
              list.Add(new PointPair(i, j, x.Next(30)));
          }
    
       var pointsCurve = pane.AddCurve("", list, Color.Transparent);
       pointsCurve.Line.IsVisible = false;
       // Create your own scale of colors.
       pointsCurve.Symbol.Fill = new Fill(new Color[] { Color.Blue, Color.Green, Color.Red });
       pointsCurve.Symbol.Fill.Type = FillType.GradientByZ;
       pointsCurve.Symbol.Fill.RangeMin = 0;
       pointsCurve.Symbol.Fill.RangeMax = 30;
       pointsCurve.Symbol.Type = SymbolType.Circle;
    
                pane.AxisChange();
                zg1.Refresh();
    

    【讨论】:

    【解决方案2】:

    我在我的项目中并没有这样做,但我确实根据一些标准更改了颜色。你应该很容易修改。在图形类中查看 stochfit.sourceforge.net 中的 svn depot。您可能还想查看我的仓库中的 zedgraph 版本,修复了一些图像捕获和缩放错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-06
      相关资源
      最近更新 更多