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

OxyPlot中FunctionSeries标题未显示问题咨询

问题描述

我在WinForms项目中使用OxyPlot编写了如下代码:

using OxyPlot;
using OxyPlot.Series;
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var myModel = new PlotModel { Title = "Example 1" };
            myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
            this.plotView1.Model = myModel;
        }
    }
}

运行后生成的图表中,FunctionSeries的“cos(x)”标题未显示,但按照官方示例操作时,示例中的系列标题正常显示,请问如何解决该问题?

解决方案

系列标题是显示在图例中的,你的代码未启用PlotModel的图例功能,所以标题无法展示。只需给PlotModel添加图例相关配置即可:

修改后的代码如下:

using OxyPlot;
using OxyPlot.Series;
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var myModel = new PlotModel { 
                Title = "Example 1",
                // 启用图例并设置显示位置
                LegendPosition = LegendPosition.TopRight,
                // 设置图例在图表区域外部,避免遮挡内容
                LegendPlacement = LegendPlacement.Outside
            };
            myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
            this.plotView1.Model = myModel;
        }
    }
}
  • LegendPosition:可自定义图例位置,可选值包括TopLeft、BottomRight等
  • LegendPlacement:控制图例是嵌入图表区域还是显示在外部,按需选择即可

你也可以通过WinForms设计器操作:选中plotView1后,在属性面板中找到Model对应的配置项,手动开启图例功能。

内容的提问来源于stack exchange,提问作者Bo Hu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 03:12:47