简体   繁体   中英

Xamarin.Forms: Changing Font Size and Font Color of a Chart

Good Day Everyone. I'm currently creating a Xamarin.Forms Portable Application. I was able to display a Chart using OxyPlot. But I want to make it more presentable by designing it.

Do you know how am I going to change the color and font size of the PlotModel Title and the Label per PieSlice. What code should I add? And if you can suggest what more can I add to my Chart, that would be highly appreciated. Thanks a lot.

Here's my code:

 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;

    }

As far as I know, OxyPlot doesn't support individual styling for single PieSlice labels. However, you can change the font and text color for all of them collectively. All the properties you need to set can be found from the PlotModel class:

  • TitleColor (OxyColor)
  • TitleFont (String)

AND

  • LegendTextColor (OxyColor)
  • LegendTitleColor (OxyColor)
  • LegendFont (String)
  • LegendTitleFont (String)

The Font properties are of type String and need the name of the font family you want to use.

Look around the PlotModel class and you'll find many other styling options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM