You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 22:04:55