C#图表控件删除条形图条之间的空间 [英] c# chart control remove spaces between bars in bar chart

查看:449
本文介绍了C#图表控件删除条形图条之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与C#.NET图表控件,看起来像下面做了一个柱状图:



正如你可以看到有每对线图上的红色和蓝色条之间的空间。 ?!有没有办法消除这些空格



在此先感谢



编辑:



下面是从设计师

  chartArea1.Name =ChartArea1的佳句; 
this.CHRT_DPS_HPS.ChartAreas.Add(chartArea1);
legend1.Name =Legend1;
this.CHRT_DPS_HPS.Legends.Add(legend1);
this.CHRT_DPS_HPS.Location =新System.Drawing.Point(3,271);
this.CHRT_DPS_HPS.Name =CHRT_DPS_HPS;
series1.ChartArea =ChartArea1;
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
series1.Color = System.Drawing.Color.Red;
series1.Legend =Legend1;
series1.MarkerBorderWidth = 0;
series1.Name =DPS;
series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;
series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
series2.ChartArea =ChartArea1;
series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
series2.Legend =Legend1;
series2.MarkerBorderWidth = 0;
series2.Name =HPS;
series2.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;
series2.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
this.CHRT_DPS_HPS.Series.Add(系列1);
this.CHRT_DPS_HPS.Series.Add(系列2);
this.CHRT_DPS_HPS.Size =新System.Drawing.Size(1199,300);
this.CHRT_DPS_HPS.TabIndex = 1;
this.CHRT_DPS_HPS.Text =CHRT_DPS_HPS;
title1.Name =标题1;
title1.Text =DPS表;
this.CHRT_DPS_HPS.Titles.Add(TITLE1);


解决方案

您需要设置一个自定义属性的图表类型。



使用此为每个系列(我的代码指定系列零):

  chart1.Series [0] [PointWidth] =1; 



替换名称和或一系列指标零。



顺便说一句 - 因为它在这里和那里有它的局限性一样多 - 微软图表是一个相当有能力的图表库!你只需要阅读文档。在这种情况下,这种图表类型有可以利用特殊的自定义属性。



这曾在我的测试应用程序。让我知道,如果它不与你的工作,我将进行进一步的故障排除。



由于我是新的,试图获得代表,请记住我的答案,如果响应它是正确的。谢谢你。


I have a bar chart made with the c# .net chart control that looks like the following:

As you can see there is a space between each pair of red and blue bars on the chart. Is there a way to remove those spaces?

Thanks in advance!

EDIT:

Here are the lines from the designer

 chartArea1.Name = "ChartArea1";
            this.CHRT_DPS_HPS.ChartAreas.Add(chartArea1);
            legend1.Name = "Legend1";
            this.CHRT_DPS_HPS.Legends.Add(legend1);
            this.CHRT_DPS_HPS.Location = new System.Drawing.Point(3, 271);
            this.CHRT_DPS_HPS.Name = "CHRT_DPS_HPS";
            series1.ChartArea = "ChartArea1";
            series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
            series1.Color = System.Drawing.Color.Red;
            series1.Legend = "Legend1";
            series1.MarkerBorderWidth = 0;
            series1.Name = "DPS";
            series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;
            series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            series2.ChartArea = "ChartArea1";
            series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;
            series2.Legend = "Legend1";
            series2.MarkerBorderWidth = 0;
            series2.Name = "HPS";
            series2.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;
            series2.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            this.CHRT_DPS_HPS.Series.Add(series1);
            this.CHRT_DPS_HPS.Series.Add(series2);
            this.CHRT_DPS_HPS.Size = new System.Drawing.Size(1199, 300);
            this.CHRT_DPS_HPS.TabIndex = 1;
            this.CHRT_DPS_HPS.Text = "CHRT_DPS_HPS";
            title1.Name = "Title1";
            title1.Text = "DPS Chart";
            this.CHRT_DPS_HPS.Titles.Add(title1);

解决方案

You need to set a custom property for that chart type.

Use this for each series (my code specifies series zero):

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

Replace the zero with the name and or indices of your series.

By the way - as much as it does have its limitations here and there - Microsoft Charting is quite a capable charting library! You just have to read the documentation. In this case, this chart type has special custom properties you can utilize.

This worked in my test application. Let me know if it does not work with yours and I will perform further troubleshooting.

As I am new and trying to gain rep, please mark my response as the answer if it is correct. Thank you.

这篇关于C#图表控件删除条形图条之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆