Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

異なるラベルを持つ円グラフ

円グラフのスライスには、凡例に表示されるものとは独立したラベルを設定できます。

Pie.cs
ScottPlot.Plot myPlot = new();

// 円グラフを作成する
double[] values = [6, 8, 10];
var pie = myPlot.Add.Pie(values);
pie.ExplodeFraction = 0.1;
pie.SliceLabelDistance = 0.5;

// スライスと凡例に異なるラベルを設定する
double total = pie.Slices.Select(x => x.Value).Sum();
for (int i = 0; i < pie.Slices.Count; i++)
{
    pie.Slices[i].LabelFontSize = 20;
    pie.Slices[i].Label = $"{pie.Slices[i].Value}";
    pie.Slices[i].LegendText = $"{pie.Slices[i].Value} " +
        $"({pie.Slices[i].Value / total:p1})";
}

// 不要なプロット要素を非表示にする
myPlot.Axes.Frameless();
myPlot.HideGrid();

myPlot.SavePng("demo.png", 400, 300);
このレシピは、円グラフカテゴリに含まれる多数のレシピのうちの1つです