0
votes

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);
            }

Resultant chart

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.
2

2 Answers

2
votes

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?
    }
}
0
votes
  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.