我在一个控制台应用程序中工作,并试图在C#控制台中绘制图表,但我无法将标记与X轴上的值对齐,我try 在星号中添加间距,但一无所获,您有什么 idea 吗?我应该用循环来做这个
理想情况下,我希望打印X轴上值的第二位数字上方的标记
这是存储在数组PHValues[]和Dates[]中作为参考的数据
Date, pH Level
10-21-2023, 12.3
10-22-2023, 11.9
10-23-2023, 13.6
10-24-2023, 11.9
10-25-2023, 10.8
这是我的代码:
static void DisplayChart(double[] pHValues, string[] dates, int count)
{
string message = "\nNo entries available for the graph. ";
if (count == 0)
{
DisplayContinueMessage(message);
return;
}
var distinctPhValues = pHValues.Distinct().OrderByDescending(x => x).ToArray();
foreach (var value in distinctPhValues)
{
//print pH values in the Y-axis
Console.Write($"{value:0.0}| ");
for (int i = 0; i < count; i++)
{
if (pHValues[i] == value)
{
Console.Write(" * ");
}
else
{
Console.Write(" ");
}
}
Console.WriteLine();
}
// Print dates on the X-axis
Console.WriteLine("----------------------");
Console.Write("Day| ");
for (int i = 0; i < count; i++)
{
Console.Write($"{dates[i].Substring(3, 2)} ");
}
Console.ReadLine();
}
这就是我得到的:
13.6| *
12.3| *
11.9| * *
10.8| *
0.0|
----------------------
Day| 21 22 23 24 25