William Labadie
William Labadie

Reputation: 11

OxyPlot C#: Setting the position of the outside labels of a pie chart

I have been working with OxyPlot to generate a multi layered pie chart, but I am having a hard time trying to place the outside label right beside the line that links it to the related slice. Currently, the top left label that displays "57%" is placed right on top of the said line.

enter image description here

Here is the code to generate it:

private static Image GenerateEmailsBreakdownPieChart(List<ScanResult> scanResults, PdfDocument pdfDoc, out string pieChartPath, out Exception occuredEx)
        {
            PlotModel model = new PlotModel
            {
                DefaultFont = "Helvetica"
            };

            pieChartPath = string.Empty;
            occuredEx = null;
            Image image = null;
            try
            {
                Dictionary<string, VulnerabilityRiskDetails> detailedDict = GetDetailedScanDictionary(scanResults);
                PieSeries outerSeries = new PieSeries { Title = "RiskLvls", StartAngle = 0, Diameter = 0.8, StrokeThickness = 2.0, InnerDiameter = 0.5, InsideLabelPosition = 0.3 };
                PieSeries innerSeries = new PieSeries { Title = "VulnerabilityTypes", StartAngle = 0, Diameter = 0.5, TickLabelDistance = 0, OutsideLabelFormat = "", TickHorizontalLength = 0, TickRadialLength = 0 };
                foreach (var item in detailedDict)
                {
                    if (item.Value.totalAmount <= 0)
                    {
                        continue;
                    }
                    innerSeries.Slices.Add(new PieSlice(item.Key, item.Value.totalAmount) { Fill = item.Value.backgroundColor });
                    if (item.Value.lowRiskAmount > 0)
                    {
                        outerSeries.Slices.Add(new PieSlice(ScanResx.LowRisk, item.Value.lowRiskAmount) { IsExploded = false, Fill = item.Value.backgroundColor });
                    }
                    if (item.Value.midRiskAmount > 0)
                    {
                        outerSeries.Slices.Add(new PieSlice(ScanResx.MedRisk, item.Value.midRiskAmount) { IsExploded = true, Fill = item.Value.backgroundColor });
                    }
                    if (item.Value.highRiskAmount > 0)
                    {
                        outerSeries.Slices.Add(new PieSlice(ScanResx.HighRisk, item.Value.highRiskAmount) { IsExploded = false, Fill = item.Value.backgroundColor });
                    }
                }
                model.Series.Add(innerSeries);
                model.Series.Add(outerSeries);
                image = ConvertOxyPlotChartToiTextImage(model, "chart.svg", pdfDoc, out pieChartPath);
            }
            catch (Exception ex)
            {
                occuredEx = ex;
            }
            return image;
        }

I would like to place the label right beside the aforementioned line, just like the right ones on the image.

Upvotes: 1

Views: 192

Answers (0)

Related Questions