使用zedGraph在C#中绘制图形

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

3
问题在于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();

Gacek,你能帮我回答这个问题吗?http://stackoverflow.com/questions/10222782/zedgraph-smoothly-move-y2axis-with-chart-line 谢谢。 - amaranth
哇,抱歉,我已经超过一年没有使用ZedGraph了,我记不清了很多东西...但是我会尝试查看。 - Gacek

1

我在我的项目中没有完全这样做,但是我根据某些条件更改颜色。您应该很容易修改它。查看 stochfit.sourceforge.net 中的svn存储库中的绘图类。您还可以查看我存储库中的zedgraph版本,修复了一些图像捕获和缩放错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接