Skip to main content Skip to footer

Displaying Max Value in Histogram Chart

C1Chart2D has been a popular winform controls for a long time due to ability to present data in various Chart formats. From available chart formats, C1Chart2D can be used to create a Histogram Chart as well. Even though, C1Chart2D provides lot of features, it comes with few minor limitations as well. Once such limitation is the inability to display the highest data point in the Datatable (if there is just a single entry of it ) in the Histogram chart. Even adjusting the AxisX.Max property does not have any effect, as Max property does not control the automatic Interval generation. This blog explains how we can manipulate the C1Chart2D to display the highest value in the chart. Plotting data in the Histogram Chart Consider the following Data set for Series 0 where the charts type is set to Histogram : X Values : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20,21,22,23,24,25,26,27,28,29,30 Y values : 0,0,1,0,0,0,0,1,0,0,5,0,1,0,1,0,1,0,1,0,0,1,0,1,0, 15,0,0,1,33. Plotting the above data, generates the following output: Observe, that the highest value 33 is not displayed in the chart. Reason being, the last point is not within 3 standard deviations of the mean, so it is considered as an outlier and is thrown out of the interval generation calculations. Displaying the missing Datapoint Now, for example, if the customer has set the AxisX.Max property = 40. Then the following code just handles the situation :

private void Form1_Load(object sender, EventArgs e)  
{  
    double axismax = c1Chart1.ChartArea.AxisX.Max;  
    axismax = 40;  
    c1Chart1.ChartGroups[0].ChartData[0].Histogram.IntervalCreationMethod = C1.Win.C1Chart.IntervalMethodEnum.SemiAutomatic;  
    c1Chart1.ChartGroups[0].ChartData[0].Histogram.IntervalNumber = 10;  
    //7 intervals is what the automatic uses  
    c1Chart1.ChartGroups[0].ChartData[0].Histogram.IntervalStart = 0;  
    //never less than zero  
    c1Chart1.ChartGroups[0].ChartData[0].Histogram.IntervalWidth = (axismax - c1Chart1.ChartGroups[0].ChartData[0].Histogram.IntervalStart) / c1Chart1.ChartGroups[0].ChartData[0].Histogram.IntervalNumber;  
}

This can also be implemented through the designer as follows :

  1. Navigate to the ChartData.SeriesList property in the Properties Window and click the ellipsis button on SeriesList. Note : the Mean and Standard Deviation (StdDev). A 95% confidence interval includes 3 StdDev from the mean in each direction. To include the last data point in the intervals when the data is this scewed, it will be necessary to use Semi-Automatic interval creation. You can do this by opening the series Histogram property. Note the current values of the Interval Bounds and how the last data point lies outside the last interval boundary. Also note the AboveIntervalCount value is 2. This is because 2 data points lie above 3 StdDev from the mean.3. Open Y.Statistics and set PropertyGrid.Enabled to True.
  2. Change the IntervalCreateMethod property to SemiAutomatic.
  3. Chose a combination of IntervalNumber, IntervalStart and IntervalWidth such that: IntervalStart + IntervalNumber * IntervalWidth > Last Data Point Value For example, in the above case, IntervalNumber = 10, IntervalStart = 0, IntervalWidth = 4, results in histogram intervals from 0 to 40.

The last data point (33) now lies in one of the included intervals. The final output looks as follows : Refer to the attached samples(VB/C#) for the detailed implementation. Download Sample CS Download Sample VB

MESCIUS inc.

comments powered by Disqus