0

我正在尝试绘制折线图,​​但我无法弄清楚如何在 C# 中绘制具有不同数据量的图表。

示例:假设您有一个包含两列十行的 .csv 文件。第一列总是有数据(即日期时间),但第二列只有四行数据(其他六行数据为零)。如果没有这种图表,我如何绘制这个图表?我想要一个连续的图表,间隔相同,但点彼此相连。

谢谢!

这是图表的图像:http: //i.stack.imgur.com/hFcE4.png

我的代码:

public MainForm()
{
     InitializeComponent();

     setupChart();
}

private void cmdLoadData_Click(object sender, EventArgs e)
{
     //I read the .csv file with a try/catch using a streamReader and save the data in
     //a class named Measurement that has two variables: _time and _measure.
     //The Measurement created is add to a List of Measurements.

     //I pass the List of Measurements as a DataSource to the DataGrid
     grdMeasurements.DataSource = _measurementList;

     //I pass the List of Measurements as a DataSource to the Chart.
     chartLineMatching.DataSource = _measurementList;
     chartLineMatching.DataBind();
}

public void setupChart()
{       
      chartLineMatching.Series.Clear();
      chartLineMatching.Titles.Clear();

      Series dataSerie = new Series("Series1", 200);
      dataSerie.XValueMember = "Time";
      dataSerie.XValueType = ChartValueType.DateTime;
      chartLineMatching.ChartAreas[0].AxisX.LabelStyle.Format = "dd/MM HH:mm";
      dataSerie.YValueMembers = "Value5";
      dataSerie.ChartType = SeriesChartType.Line;
      chartLineMatching.ChartAreas[0].AxisY.LabelStyle.Format = "{0;0}" + "°";
      dataSerie.BorderWidth = 2;
      dataSerie.Color = System.Drawing.Color.Blue;
      chartLineMatching.Series.Add(dataSerie);
      chartLineMatching.Series[0].YAxisType = AxisType.Secondary;

      chartLineMatching.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
      chartLineMatching.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;
      chartLineMatching.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
      chartLineMatching.ChartAreas[0].AxisY2.Interval = 4;
      chartLineMatching.ChartAreas[0].AxisY2.LabelStyle.Format = "{0;0}" + "%";

      chartLineMatching.ChartAreas[0].AxisY.Interval = 10;
      chartLineMatching.ChartAreas[0].AxisX.Interval = 0.5;
}
4

1 回答 1

0

听起来您正试图跳过值列中具有“0”的数据点。如何做到这一点取决于您用于从 csv 数据创建图表的代码。如果不显示任何代码,我们将无法真正帮助您。

但基本上,您需要通过过滤器传递数据,该过滤器将删除您想要跳过的点,然后从过滤后的数据集中创建图形。

于 2013-06-05T23:24:35.413 回答