Bar / Bar Chart Does Not Show Bars Down

I am trying to plot a histogram using a C # .NET Chart control ( System.Windows.Forms.DataVisualization.Charting ).

I configured it as a column table. Data is extracted through a histogram object using the NMath libraries, so it performs all sorting in bins, etc. Everything looks great until I switch the y axis to the log scale. To make things even show up, I set the DataPoint of any bin with 0 elements to have a y value of 0.001 instead of 0. Then I set the minimum of the y axis to 0.1, and max to something above the biggest bin. As a result, all the columns start with a y value of 1, not at least. In any bunker with 0 elements there is a column that continues down (to 0.001). Screenshot is available here.

A code that sets min / max / intervals on the axis below.

double ymin = FindMinimumYValue(); double mag = Math.Floor(Math.Log10(ymin)); ymin = Math.Pow(10, mag); yAxis.Minimum = ymin; double ymax = FindMaximumYValue(); mag = Math.Ceiling(Math.Log10(ymax)); ymax = Math.Pow(10, mag); yAxis.Maximum = ymax; yAxis.Interval = 1; yAxis.MajorGrid.Interval = 1; yAxis.MajorTickMark.Interval = 1; yAxis.MinorGrid.Interval = 1; yAxis.MinorTickMark.Interval = 1; 

I probably don't set the property on the axis I need, but is there any way that all columns expand upward from the minimum on the y axis, even if that minimum is less than 1?

ETA: If I delete DataPoints with 0 samples from the series, I no longer get downward bars between 0.1 and 1. But all the other bars still start at 1 and go up, rather than starting at the minimum.

ETA again: I think I can use a chart of type RangeColumn and specify the min and max y values ​​for each bin. This does not seem very elegant, since I will need to switch between the RangeColumn and Column types when the user switches the axis to log mode and vice versa or continues to adjust the minimum y value for RangeColumn data points (from 0 to 0.1 and back). And this seems like a workaround, not a solution.

+7
c # charts histogram
source share
2 answers

I started changing it to a RangeColumn chart RangeColumn and simply set the minimum and maximum range if necessary.

0
source share

A workaround would be to add a datapoint with a Y value of 0 for each x value.

  Series = chart1.Series.Add("Test"); Axis yAxis = chart1.ChartAreas[0].AxisY; yAxis.IsLogarithmic = true; double ymin = 0.1; yAxis.Minimum = ymin; double ymax = 100; yAxis.Maximum = ymax; Series.Points.Add(new DataPoint(1, 3)); Series.Points.Add(new DataPoint(1, 0)); Series.Points.Add(new DataPoint(2, 3)); Series.Points.Add(new DataPoint(2, 0)); Series.Points.Add(new DataPoint(3, 4)); Series.Points.Add(new DataPoint(3, 0)); Series.Points.Add(new DataPoint(4, 5)); Series.Points.Add(new DataPoint(4, 0)); 
+1
source share

All Articles