【发布时间】:2017-07-11 10:36:52
【问题描述】:
我想做什么: 我有多个具有不同创建日期的文件。 X 轴 = 日期,Y 轴 = 0-100 之间的值。我想创建一个折线图,显示用 X 标记的每一天的所有值 -> 例如(2017 年 7 月 10 日 = 50 和 60 -> 在 2017 年 7 月 10 日在 50 和 60 显示 X)
这已经完成了,代码就是这个:
for (int i=0; i< orderedList.Count(); i++)//iterating through Files
{
int max_col = 0, max_rows = 0;
double[][] temp = FileManager.ReadCSV(orderedList[i].FullName.ToString(),ref max_rows, ref max_col); //reading the file to a double[][]
chartGraphic.Series[0].Points.AddXY(orderedList[i].CreationTime.Date, 100-Statistics.Prozent_NIO(temp, 1)); //adding the point to the Chart -> Prozent_NIO returns the y-value
}
我正在使用带有 Series[0] ChartType = points 的图表
现在我想在 Series1 中为每个现有的 X 值(日期)标记点。 Y 值应该是该特定日期的 series[0] 的所有现有 Y 值的平均值。 系列1ChartType = Line
示例:
系列[0]点是:
X 值 = 10.07.2017 Y 值 = 10;20;30
X 值 = 11.07.2017 Y 值 = 50;60;
所以 Series1 点数应该是:
X 值 = 10.07.2017 Y 值 = 20(10、20、30 的平均值)
X 值 = 11.07.2017 Y 值 = 55(50,60 的平均值)
虽然 Series[0] 仅显示标记点(ech 之间没有连接),但 Series1 将在每个点之间画一条线。
我已经研究过,但找不到具体的答案...
我尝试了什么:
double temp_average=0;
double temp_number=0;
for (int i=0; i< orderedList.Count(); i++)// (FileInfo file in orderedList)
{
int max_col = 0, max_rows = 0;
double[][] temp = FileManager.ReadCSV(orderedList[i].FullName.ToString(),ref max_rows, ref max_col); chartGraphic.Series[0].Points.AddXY(orderedList[i].CreationTime.Date, 100-Statistics.Prozent_NIO(temp, 1));
if (i != 0)
{
if (orderedList[i].CreationTime.Date == orderedList[i - 1].CreationTime.Date) //times are similar -> add value to temp_averge and count number up
{
temp_average += Convert.ToDouble(chartGraphic.Series[0].Points[i - 1].YValues);
temp_number++;
}
else //Times different -> add last y value then calculate average and reset the variables
{
temp_average += Convert.ToDouble(chartGraphic.Series[0].Points[i - 1].YValues); //add last point
temp_number++;
chartGraphic.Series[1].Points.AddXY(orderedList[i - 1].CreationTime.Date, temp_average / temp_number); // add point in series 1
temp_average = 0;
temp_number = 0;*/
}
}
}
但这不起作用,它说我无法将 double[] 转换为 double =/
编辑: 我也尝试使用 FinancialFormula,但这个并没有真正通过平均值,它只是预测我使用的进一步趋势:
chartGraphic.Series.Add("TrendLine");
chartGraphic.Series["TrendLine"].ChartType = Graph.SeriesChartType.Line;
chartGraphic.Series["TrendLine"].Color = Color.Red;
chartGraphic.DataManipulator.IsStartFromFirst = true;
chartGraphic.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, "Linear, 1, false, false", chartGraphic.Series[0], chartGraphic.Series["TrendLine"]);
这是当前图表的示例。现在我想做的是一条显示每个 X 值(日期)平均值的线,红线(趋势)是我的尝试,但这只是预测下一个值,这也很好,但不是我想要的。我需要通过点的平均值画一条线->考虑到 100 上有 2 个点和 90 上有 2 个点,红线的起点应该更高,它应该在 95 而不是 ~92 的位置
【问题讨论】:
-
系列[0] 点是:X 值 = 10.07.2017 Y 值 = 10;20;30 X 值 = 11.07.2017 Y 值 = 50;60; 是这两点吗?还是3?还是6?? - 你能发布一张到目前为止的图表吗?
-
对不起,这些是总共 2 个 x 值,第一个是 X 值(10.07.2017 -> 一个日期)有 3 个 Y 值(10 和 20 和 30),第二个 X 值(11.07 .2017) 有 2 个 Y 值(50 和 60)我会在几秒钟内添加一个图像!
-
我上传了当前Graph的图片
标签: c# charts average linechart