Xamarin.表格:改变图表的字体大小和字体颜色

本文关键字:字体 颜色 表格 改变 Xamarin | 更新日期: 2023-09-27 17:58:39

大家好。我目前正在创建一个Xamarin.Forms可移植应用程序。我能够使用OxyPlot显示图表。但我想通过设计让它更美观

你知道我该如何更改PlotModel标题和每个PieSlice标签的颜色和字体大小吗。我应该添加什么代码?如果你能建议我在我的图表中还能添加什么,我将不胜感激。非常感谢。

这是我的代码:

 public PieViewModel()
    {
        modelP1 = new PlotModel { Title = "Pie Sample1"};
        dynamic seriesP1 = new PieSeries { StrokeThickness = 2.0, InsideLabelPosition = 0.8, AngleSpan = 360, StartAngle = 0 };
        seriesP1.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = false, Fill = OxyColors.PaleVioletRed });
        seriesP1.Slices.Add(new PieSlice("Americas", 929) { IsExploded = true });
        seriesP1.Slices.Add(new PieSlice("Asia", 4157) { IsExploded = true });
        seriesP1.Slices.Add(new PieSlice("Europe", 739) { IsExploded = true });
        seriesP1.Slices.Add(new PieSlice("Oceania", 35) { IsExploded = true });
        modelP1.Series.Add(seriesP1);
        this.SalesModel = modelP1;
    }

Xamarin.表格:改变图表的字体大小和字体颜色

据我所知,OxyPlot不支持单个PieSlice标签的单独样式。但是,您可以共同更改所有字体和文本颜色。所有需要设置的属性都可以从PlotModel类中找到:

  • 标题颜色(OxyColor)
  • TitleFont(字符串)

  • LegendTextColor(OxyColor)
  • LegendTitleColor(OxyColor)
  • LegendFont(字符串)
  • LegendTitleFont(字符串)

Font属性的类型为String,需要您要使用的字体系列的名称。

环顾PlotModel类,您会发现许多其他样式选项。