C#WinForms图表配置 [英] C# WinForms Charts configuration

查看:74
本文介绍了C#WinForms图表配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在C#WinForms条形图上绘制文件的字节数。这样,X轴的值将为0-255(如果大于零),而Y轴将根据文件的长度和字节分布而变化。代码如下:

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

问题:


  1. 这很好,但是显示图表的方式不符合我的喜好。
    我希望每个栏都尽可能多地填充空间(即没有
    的边距/边框)。从我在其他地方阅读过的内容,建议
    使用PointWidth或PixelPointWidth,但是这些方法都无法使
    正常工作。

  2. 是否有一种方法可以删除内部从
    显示的黑色网格线?理想情况下,我希望底部X轴编号保持不变,但删除网格线。


推荐答案

消除差距:

series["PointWidth"] = "1";

删除网格线:

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

更新:

我认为您的问题是为每个数据点创建一个新系列。这样您还可以获得色彩效果。只需创建一个系列,将其添加到图表区域,然后将所有数据点添加到该系列。

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?
    }
}

这篇关于C#WinForms图表配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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