2

I want to have a beautiful legend. I read the documentation, but could not find this case.

I have PlotView in xaml

<oxy:PlotView  Model="{Binding ResidentsPhotoChartViewModel.ChartModel}" Style="{StaticResource PlotViewStyle}" />

PlotView Style

<Style x:Key="PlotViewStyle" TargetType="{x:Type oxy:PlotView}">
    <Setter Property="IsLegendVisible" Value="True" />
    <Setter Property="LegendOrientation" Value="Horizontal" />
    <Setter Property="LegendPosition" Value="BottomCenter" />
    <Setter Property="LegendTextColor" Value="White" />
</Style>

PlotModel in code

public PlotModel ChartModel
{
    get
    {
        return CreateModel(CreatePieSeries(_chartPieSlicesList));
    }
}


public ResidentsPhotoChartViewModel()
{
    _residentsWithPhotoSlice = CreatePieSlice(CLResources.DontHavePhoto, 0, OxyColors.LimeGreen);
    _residentsWithoutPhotoSlice = CreatePieSlice(CLResources.HavePhoto, 0, OxyColors.Red);

    _chartPieSlicesList = new List<PieSlice> { _residentsWithPhotoSlice, _residentsWithoutPhotoSlice };
}

private static PlotModel CreateModel(Series series)
{
    return new PlotModel
    {
        Series = {series},
        IsLegendVisible = true,
        LegendTitle = "LegendTitleFromModel",
    };
}

private static PieSeries CreatePieSeries(List<PieSlice> slices)
{
    return new PieSeries
    {
        Title = "SeriesTitle",
        StrokeThickness = StrokeThickness,
        InnerDiameter = InnerDiameter,
        Slices = slices
    };
}

I want to have something like this, but it doesn't look like it should.

Peter Neyens
  • 9,770
  • 27
  • 33
  • I guess you can't use a legend with `PieSeries`, because in the source code there is no functionality in the override Method `RenderLegend()` for rendering a legend for this class (see [link](https://github.com/ylatuya/oxyplot/blob/master/Source/OxyPlot/Series/PieSeries.cs)). But I might be wrong. – Sebastian Richter Aug 21 '15 at 07:51
  • @SebastianRichter is there anyway you can add a Legend on a Pie Chart in OxyPlot? – Jaycee Evangelista Jul 28 '16 at 06:23
  • @JayceeEvangelista I cant give you an answer. I didn't use Oxyplot for 6 months now. Many thinks have changed. I recommend that you create a `PlotModel` with a legend and at a `PieSeries` to it. Just browse the examples in the Github repo if you need help [link](https://github.com/oxyplot/oxyplot/tree/develop/Source/Examples/WPF/WpfExamples). – Sebastian Richter Jul 28 '16 at 10:17
  • @SebastianRichter Thanks Sir. – Jaycee Evangelista Jul 28 '16 at 11:49
  • @EugeneZarozhny Sir does your data comes from your Database? – Jaycee Evangelista Aug 02 '16 at 11:26
  • I'm late to the game here, but I'm using oxyplot for a pie chart for the first time myself and what I'm finding is that the "PieSeries" title gets added to the legend, but each individual "PieSlice" does not. In the case of a pie chart it would make more sense for the PieSlices to be in the legend, but I haven't figured out how to make that happen yet. – Matt Mar 15 '18 at 17:25

0 Answers0