如何在ZedGraph中设置y2、y7等非主Y轴的字体与字号
解决方案
你调用AddYAxis方法时返回的索引值,可直接用于定位GraphPane的YAxisList集合中对应的额外Y轴实例,分别设置轴标题和刻度标签的字体属性即可,修改后的代码参考如下:
if (plotValue.Keys.Contains("DD_CurrentPrice")) { y2 = graphArea.AddYAxis("DD - Price"); // 设置y2轴标题字体 graphArea.YAxisList[y2].Title.FontSpec = new FontSpec("Cambria", 10.0f, Color.Black, false, false, false); // 设置y2轴刻度数值字体 graphArea.YAxisList[y2].Scale.FontSpec = new FontSpec("Cambria", 9.0f, Color.Black, false, false, false); curve = new LineItem("DD - Current Price", null, plotValue["DD_CurrentPrice"], Color.FromArgb(255, 198, 001), SymbolType.None) { YAxisIndex = y2 }; curve.Label.FontSpec = new FontSpec("Cambria", 10.0f, Color.Black, false, false, false); graphArea.CurveList.Add(curve); } if (plotValue.Keys.Contains("PD_MarkdownPrice") || plotValue.Keys.Contains("PD_CurrentPrice")) { y7 = graphArea.AddYAxis("PD - Price"); // 设置y7轴标题字体 graphArea.YAxisList[y7].Title.FontSpec = new FontSpec("Cambria", 10.0f, Color.Black, false, false, false); // 设置y7轴刻度数值字体 graphArea.YAxisList[y7].Scale.FontSpec = new FontSpec("Cambria", 9.0f, Color.Black, false, false, false); if (plotValue.Keys.Contains("PD_MarkdownPrice")) { curve = new LineItem("PD - Markdown Price", null, plotValue["PD_MarkdownPrice"], Color.FromArgb(045, 186, 030), SymbolType.None) { YAxisIndex = y7 }; curve.Label.FontSpec = new FontSpec("Cambria", 10.0f, Color.Black, false, false, false); graphArea.CurveList.Add(curve); } if (plotValue.Keys.Contains("PD_CurrentPrice")) { curve = new LineItem("PD - Current Price", null, plotValue["PD_CurrentPrice"], Color.FromArgb(011, 138, 000), SymbolType.None) { YAxisIndex = y7 }; curve.Label.FontSpec = new FontSpec("Cambria", 10.0f, Color.Black, false, false, false); graphArea.CurveList.Add(curve); } }
其中Title.FontSpec对应轴标题的字体样式,Scale.FontSpec对应轴刻度数值的字体样式,可根据需求调整字号、颜色等参数。
内容的提问来源于stack exchange,提问作者Leonard Chung
相关产品推荐
相关产品推荐

