buy now
log in
MindFusion

Q: I show 50 bars in a bar chart but they overlap each other. Although I set bar width to 3 and have their data in intervals of 3 at the axis, the bars still overlap. Why this happens. Here is my code:

 List xData = new List(50);
 List yData = new List(50);

 for (int i = 0; i < 150; i+=3)
 {

 xData.Add(double.Parse(i.ToString()));
 yData.Add(double.Parse((i + 5).ToString()));
 }

 series0.XData = xData;
 series0.YData = yData;
 series0.BarWidth = 3;

 

A: Your bars do not overlap each other in this case. There is no space between the bars and this makes them look as if they overlap. If you want to see each bar clearly you should decrease the BarWidth a little. This tells the control to split the remaining space between the two sides of the bar – right and left. In your case try:

 series0.BarWidth = 2.8;


In addition to this, you’d better make the first bar start at a value greater than zero – ideally at the half if its value. This will prevent the first bar from being drawn partly to the left of the Y-axis. The reason for this is that the value of each bar is considered to indicate the middle of the bar. This means that a bar with XData of 2 and value 3 will be drawn from 0.5 to 3.5. So try:

 
 xData.Add(double.Parse((i + 2).ToString())); 


Copyright © 2001-2024 MindFusion LLC. All rights reserved.
Terms of Use - Contact Us