C# WinForms Charts configuration

不羁的心 提交于 2019-12-12 06:22:05

问题


I am trying to plot a file's byte count over a C# WinForms bar graph. As such, the X-axis will have values 0-255 (if greater than zero) and the Y-axis varies upon the length of the file and the byte distribution. The code is as follows:

        for (int i = 0; i < byteDistribution.Count; i++)
        {
            if (byteDistribution[i] > 0)
            {
                Series series = new Series(i.ToString());

                series.Points.AddXY(i, byteDistribution[i]);
                // PointWidth has no affect?
                series.SetCustomProperty("PointWidth", "1");
                this.crtBytes.Series.Add(series);
            }

Questions:

  1. This works well but the way the chart is shown is not to my liking. I would like each bar to fill in as much space as possible (ie. no margin / border). From what I've read elsewhere it was suggested to use PointWidth or PixelPointWidth but none of these approaches is working.
  2. Is there a way to remove the inner black grid lines from showing? Ideally, I would like the bottom X-axis numbering to remain just the same, but remove the grid lines.

回答1:


For removing the gaps:

series["PointWidth"] = "1";

For removing the gridlines:

chartArea.AxisX.MajorGrid = new FChart.Grid {Enabled = false};
chartArea.AxisY.MajorGrid = new FChart.Grid { Enabled = false };

UPDATE:

I think your problem is that you create a new series for each data point. So you also get the "color effect". Just create ONE series, add it to the chart area and add all data points to this series.

Series series = new Series();
this.crtBytes.Series.Add(series);
series.SetCustomProperty("PointWidth", "1");

for (int i = 0; i < byteDistribution.Count; i++)
{
    if (byteDistribution[i] > 0)
    {
        series.Points.AddXY(i, byteDistribution[i]);
        // PointWidth has no affect?
    }
}



回答2:


  1. PointWidth property is a relative amount, try something like series["PointWidth"] = 1.25.

  2. The black lines are called MajorGrid, use chartArea.MajorGrid.Enabled = False.



来源:https://stackoverflow.com/questions/33892373/c-sharp-winforms-charts-configuration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!