Search code examples
c#wpfchartsbindingpie-chart

WPF Charting Toolkit PieChart is invisible


I am trying to show a pie chart using the charting toolkit for WPF, but the pie chart itself is invisible. The legend is showing and hovering over the pie chart is showing me the right tooltips, but the pie chart is not showing.

XAML

            <DVC:Chart Grid.Row="0" Padding="0" Height="160" Name="stateChart" Background="White">
                <DVC:Chart.Series>
                    <DVC:PieSeries Name="stateChartPieSeries" Title="Incidence per State" ItemsSource="{Binding StatePieChartData}" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}" />
                </DVC:Chart.Series>
            </DVC:Chart>

C#

        public Dashboard() {
            InitializeComponent();
            model = new DashboardModel(filterReportSection.model);
            DataContext = model;

            // this would show the PieChart:
            //stateChartPieSeries.ItemsSource = model.StatePieChartData;
        }
        private IEnumerable statePieChartData;
        public IEnumerable StatePieChartData { get { return statePieChartData; } }

The resulting GUI: enter image description here

The problem seems to be connected to the Binding of ItemsSource, because setting the ItemsSource directly results in showing the PieChart again.


Solution

  • I solved it myself. It turned out, having empty data or a KeyValuePair with the value 0 in the pie chart data makes the pie chart not rendering but kinda appear invisible.

    Just clear your data of "empty" KeyValuePairs, which have a value of 0 and the pie chart should show up again.