简体   繁体   中英

C# Chart space between series

I tried to create Bar chart to represent my data with more series data. It seem to be good,but when i run my application the bar in each data series is too closed, so i want to modified my chart to space bar from each data series, but I can not solve this problem.

And this is my code to add 3 data Series to chart and

chart1.Series["S1"].Points.AddXY(1, 5);
chart1.Series["S1"].Points.AddXY(2, 6);
chart1.Series["S1"].Points.AddXY(3, 7);
chart1.Series["S1"].Points.AddXY(4, 2);
chart1.Series["S1"].Points.AddXY(5, 8);

chart1.Series["S2"].Points.AddXY(1, 5);
chart1.Series["S2"].Points.AddXY(2, 6);
chart1.Series["S2"].Points.AddXY(3, 7);
chart1.Series["S2"].Points.AddXY(4, 2);
chart1.Series["S2"].Points.AddXY(5, 8);

chart1.Series["S3"].Points.AddXY(1, 5);
chart1.Series["S3"].Points.AddXY(2, 6);
chart1.Series["S3"].Points.AddXY(3, 7);
chart1.Series["S3"].Points.AddXY(4, 2);
chart1.Series["S3"].Points.AddXY(5, 8);

and this is my chart https://www.img.in.th/image/TCy

Try reducing the value of the custom property PointWidth for each series as follows:

chart1.Series["S1"]["PointWidth"] = "0.5";
chart1.Series["S2"]["PointWidth"] = "0.5";
chart1.Series["S3"]["PointWidth"] = "0.5";

The default value for this property is 0.8. Lower values will make the bars narrower, which will result in more space between them. The maximum value of 1 will result in no space between each bar.

After binding the Data to the Chart Control, finally you can put the below code

chart1.AlignDataPointsByAxisLabel();

if you want to reduce the bar width you can use

chart1.Series[0]["PointWidth"]="0.3";
chart1.Series[1]["PointWidth"]="0.3";
chart1.Series[2]["PointWidth"]="0.3";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM