winform OxyPlot 显示图例
时间: 2023-05-28 13:02:08 浏览: 502
winform OxyPlot 的图例可以通过以下步骤来显示:
1. 定义一个 `PlotModel` 对象,并通过 `PlotModel.LegendPosition` 属性设置图例的位置(如顶部、底部等)。
```csharp
var plotModel = new PlotModel
{
LegendPosition = LegendPosition.Bottom
};
```
2. 在 `PlotModel` 对象中添加一个或多个 `Series` 对象。每个 `Series` 对象可以通过 `Series.Title` 属性来定义该系列的标题,该标题将在图例中显示。
```csharp
var series1 = new LineSeries
{
Title = "Series 1",
MarkerType = MarkerType.Circle,
MarkerSize = 4,
Color = OxyColors.Blue
};
var series2 = new LineSeries
{
Title = "Series 2",
MarkerType = MarkerType.Square,
MarkerSize = 6,
Color = OxyColors.Red
};
plotModel.Series.Add(series1);
plotModel.Series.Add(series2);
```
3. 在 WinForms 中创建一个 `PlotView` 控件,并将其 `Model` 属性设置为上面创建的 `PlotModel` 对象。这将显示包含系列标题的图例。
```csharp
var plotView = new PlotView
{
Model = plotModel
};
this.Controls.Add(plotView);
```
这样就可以在 WinForms 应用程序中使用 OxyPlot 显示带有图例的图表。
阅读全文
相关推荐












