我正在尝试绘制折线图但是我有问题要弄清楚如何在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;
}
答案 0 :(得分:0)
听起来您正试图跳过值列中包含“0”的数据点。如何执行此操作取决于您用于从csv数据创建图表的代码。没有显示任何代码,我们无法真正帮助您。
但基本上你需要通过过滤器传递数据,过滤器会删除你想要跳过的点,然后从过滤的数据集中创建图形。