Histogram Series Does Not Bin Properly

Hi,


I encountered two issues while using sfchart with histogram series. The first problem is that there is a large space between the left edge of the sfchart object and the y-axis of the histogram shown in the screenshot. The second issue is that the histogram is binning all objects in my Viewmodel to one bin on the x-axis instead of putting them to the correct bins based on their x-value. 

Here is my xaml code:

            <sfchart:SfChart Grid.Column="0" Grid.Row="2" Margin="160,10,10,10" HorizontalAlignment="Left">

                <sfchart:SfChart.DataContext>

                    <local:Model/>

                </sfchart:SfChart.DataContext>

                <sfchart:SfChart.PrimaryAxis>

                    <sfchart:NumericalAxis Interval="1" Header="DBE" Minimum="-5" Maximum="10" />

                </sfchart:SfChart.PrimaryAxis>

                <sfchart:SfChart.SecondaryAxis>

                    <sfchart:NumericalAxis Interval="1" Header="Frequency"/>

                </sfchart:SfChart.SecondaryAxis>

                <sfchart:HistogramSeries x:Name="histogram" HistogramInterval="0.5" Interior="#FF757CBB" ItemsSource="{Binding Data}" XBindingPath="x_val" YBindingPath="frequency" ShowNormalDistributionCurve="False">

                </sfchart:HistogramSeries>

            </sfchart:SfChart>


Note that here I added data points by doing the following, but both points are grouped into the same bin although I specified that HistogramInterval="0.5"

            Data.Add(new Model() { x_val = 5 });

            Data.Add(new Model() { x_val = 3 });

screenshot.PNG


1 Reply

YP Yuvaraj Palanisamy Syncfusion Team June 28, 2021 12:14 PM UTC

Hi Sam shen, 
 
Greetings from Syncfusion. 
 
We have analysed your query and you can resolve the reported problem “Histogram series is not rendered properly when X-value is unordered” by sorting the data based on X-value with the help of IsSortData and SortBy property of chart series. 
 
<sfchart:HistogramSeries x:Name="histogram"  
                         SortBy="X"  
                         IsSortData="True" 
                         HistogramInterval="0.5"  
                         Interior="#FF757CBB"  
                         ItemsSource="{Binding Data}"  
                         XBindingPath="XValue"  
                         YBindingPath="YValue"  
                         ShowNormalDistributionCurve="False"> 
 
</sfchart:HistogramSeries> 
 
For more detail, please refer the below link. 
 
Please let us know if you have any concern. 
 
Regards, 
Yuvaraj. 


Loader.
Up arrow icon