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 :
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