Oxyplot绘图无图例问题求助:WinForm中cos(x)图例不显示
OxyPlot WinForm中cos(x)图例不显示的解决方法
OxyPlot的PlotModel默认不会显示图例,需要手动启用该功能。只需在创建PlotModel后添加图例相关配置即可:
修改后的代码:
private void button1_Click(object sender, EventArgs e) { Equatorial equ_2000 = Astronomy.Equator(corps, time, observateur, EquatorEpoch.J2000, Aberration.Corrected); Equatorial equ_ofdate = Astronomy.Equator(corps, time, observateur, EquatorEpoch.OfDate, Aberration.Corrected); Topocentric hor = Astronomy.Horizon(time, observateur, equ_ofdate.ra, equ_ofdate.dec, Refraction.Normal); labelHauteur.Text = hor.altitude.ToString("0.##"); labelAzimuth.Text = hor.azimuth.ToString("0.##"); var myModel = new PlotModel { Title = "Example 1" }; // 启用图例并设置显示位置为右侧 myModel.LegendPosition = LegendPosition.Right; // 也可以直接设置LegendIsVisible=true,结合位置设置体验更好 // myModel.LegendIsVisible = true; myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); plotView.Model = myModel; }
关键修改说明:
- 通过
LegendPosition指定图例的显示位置(支持Top、Bottom、Left、Right等枚举值) - 若仅需显示图例,直接设置
LegendIsVisible = true即可,无需指定位置
内容的提问来源于stack exchange,提问作者michastro
相关产品推荐
相关产品推荐

