繁体   English   中英

使用zedGraph在C#中绘制图形

[英]Draw a Graph in C# using zedGraph

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

问题是ZedGraph以一种奇怪的方式处理文本类型的比例。 因此,如果您同时具有两种文本类型,则几乎不可能正确显示数据。

但你可以稍微欺骗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();

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM