簡體   English   中英

C#WinForms圖表配置

[英]C# WinForms Charts configuration

我正在嘗試在C#WinForms條形圖中繪制文件的字節數。 這樣,X軸的值將為0-255(如果大於零),而Y軸將根據文件的長度和字節分布而變化。 代碼如下:

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

結果圖

問題:

  1. 這很好用,但是顯示圖表的方式並不符合我的喜好。 我希望每個欄都盡可能多地填充空間(即沒有邊距/邊框)。 根據我在其他地方閱讀的內容,建議使用PointWidth或PixelPointWidth,但這些方法均無效。
  2. 有沒有辦法消除顯示的內部黑色網格線? 理想情況下,我希望底部的X軸編號保持不變,但要刪除網格線。

為了消除差距:

series["PointWidth"] = "1";

要刪除網格線:

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

更新:

我認為您的問題是您為每個數據點創建了一個新系列。 這樣您還可以獲得“色彩效果”。 只需創建一個系列,將其添加到圖表區域,然后將所有數據點添加到該系列。

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?
    }
}
  1. PointWidth屬性是一個相對值,請嘗試類似series["PointWidth"] = 1.25

  2. 黑線稱為MajorGrid,使用chartArea.MajorGrid.Enabled = False

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM