我在 WinForms 中使用 LiveCharts。我不使用 WPF 的原因是因为我不想在 WPF 中重写 GUI,所以我想看看我是否可以让 LiveCharts 在 WinForms 中工作。
我将 LiveCharts 控件作为图像保存到 PDF,因此标题需要在图表本身上。
我找不到在图表上添加标题的任何功能。我尝试过的是以下内容:
VisualElement title = new VisualElement();
title.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
title.VerticalAlignment = System.Windows.VerticalAlignment.Top;
title.X = 0.5;
title.Y = maxYVal;
TextBlock titleText = new TextBlock();
titleText.Text = chartName;
var newTitleFont = HelperFunctions.NewTypeFaceFromFont(titleFont);
titleText.FontFamily = newTitleFont.FontFamily;
titleText.FontStyle = newTitleFont.Style;
titleText.FontSize = titleFont.Size;
title.UIElement = titleText;
cartChart.VisualElements.Add(title);
上面的代码只是在图表本身上添加了一个标签(在y轴范围内)。标题需要是独立的(在 y 轴上方)。任何想法?