gpt4 book ai didi

c# - Visual Studio、图表、轴 x 点名称

转载 作者:行者123 更新时间:2023-12-02 07:59:34 25 4
gpt4 key购买 nike

我正在创建一个小程序,通过图表显示每月的总销售总额,我需要通过我的 SQL 响应名称(2012'7, 2012')调用 X 轴点(1,2,3,4,5) 8, 2012'9),但找不到如何执行此操作。

enter image description here

代码:

        sqlQuery = "SELECT YEAR(`importdate`) as 'Year', MONTH(`importdate`) as 'Month', SUM(`price`) as 'Sum' FROM `wagon` GROUP BY MONTH(`importdate`), YEAR(`importdate`) ORDER BY YEAR(`importdate`), MONTH(`importdate`) ASC LIMIT 12";

MySqlConnection sqlConnection = new MySqlConnection(sqlParams);
MySqlCommand sqlCommand = new MySqlCommand(sqlQuery, sqlConnection);

chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.Gainsboro;
chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Gainsboro;

try
{
sqlConnection.Open();

MySqlDataReader sqlReader = sqlCommand.ExecuteReader();

if (sqlReader.HasRows)
{
while (sqlReader.Read())
{
string Sum = sqlReader["Sum"].ToString();
if (Sum.Contains(",")) Sum = Sum.Replace(",", ".");

string serieName = "Series1";
// string serieName = sqlReader["Year"].ToString() + '\'' + sqlReader["Month"].ToString();
// chart1.Series.Add(sqlReader["Year"].ToString() + '\'' + sqlReader["Month"].ToString());

// chart1.Series[serieName].ChartArea = "ChartArea1";

chart1.Series[serieName].Points.AddY(Sum);


chart1.Series[serieName].ChartType = SeriesChartType.Line;
chart1.Series[serieName].IsValueShownAsLabel = true;
//sqlReader["Year"].ToString() + '"' + sqlReader["Month"].ToString()
}
}
}

最佳答案

如果我没猜错的话,你可以使用这个:

Chart1.ChartAreas(0).AxisX.CustomLabels.Add(0.5, 1.5, "1");
Chart1.ChartAreas(0).AxisX.CustomLabels.Add(1.5, 2.5, "2");
Chart1.ChartAreas(0).AxisX.CustomLabels.Add(2.5, 3.5, "3");
Chart1.ChartAreas(0).AxisX.CustomLabels.Add(3.5, 4.5, "4");
Chart1.ChartAreas(0).AxisX.CustomLabels.Add(4.5, 5.5, "5");

前两个数字决定这些标签的传播范围。第三是标签本身。

关于c# - Visual Studio、图表、轴 x 点名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14187176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com