How to show bar graph with margin in bar


https://www.nevron.com/Forum/Topic13159.aspx
Print Topic | Close Window

By shweta jain - 4 Years Ago
hello,

I am using bar series like attached image, but due to large no of values, it is looking like an area.
Issue - bar chart loooking like an area.
I want to show bars which should be thinner with a margin that divides the bars.
How can update chart with thinner bar  with a margin that divides the bars?
By Nevron Support - 4 Years Ago
Hi Shweta,

You can control the bar width using the WidthPercent property:

NChart chart = nChartControl1.Charts[0];

NBarSeries bar = new NBarSeries();
bar.DataLabelStyle.Visible = false;
bar.BorderStyle.Width = new NLength(0);
bar.EnableXPixelSnapping = false;
bar.WidthPercent = 50;
chart.Series.Add(bar);

for (int i = 0; i < 1000; i++)
{
bar.Values.Add(i);
}
this will only work in the case the bar series is operating in categorical mode (e.g. you do not supply the xvalues). In case you provide xvalues you need to use BarWidthMode in combination with LogicalBarWidth or BarWidth depending on the mode:

NChart chart = nChartControl1.Charts[0];

NBarSeries bar = new NBarSeries();
bar.DataLabelStyle.Visible = false;
bar.BorderStyle.Width = new NLength(0);
bar.EnableXPixelSnapping = false;
bar.UseXValues = true;
bar.BarWidthMode = BarWidthMode.Logical;
bar.LogicalBarWidth = 0.5f;

chart.Series.Add(bar);

for (int i = 0; i < 1000; i++)
{
bar.Values.Add(i);
bar.XValues.Add(i);
}

Note that in both cases we would advise you to disable x pixel snapping. 
We hope this helps - let us know if you have any questions.