我有一个根据所选时间范围构建图表的功能。 onClick函数确定存储过程和数据源参数,使得DataBind()和调用showChartSum()函数 Stored procidure output in case of week range 需要将d_date设置为AxisX,将其他值设置为AxisY 代码:
public void showChartSum()
{
DataTable dt_data;
DataView dv_data;
string error_message;
int range_id;
chart_sum.Visible = true;
chart_avg.Visible = false;
range_id = int.Parse(rbl_display02.SelectedValue);
dv_data = (DataView)sds_report.Select(new DataSourceSelectArguments());
dt_data = dv_data.ToTable("DTData", false, "d_date", "tip", "deposit", "compensation", "salary");
if (dt_data.Rows.Count > 0)
{
dt_data = validateMaxChartInput(dt_data);
chart_sum.DataSource = dt_data;
chart_sum.Series["series_tip"].XValueMember = "d_date";
chart_sum.Series["series_tip"].YValueMembers = "tip";
chart_sum.Series["series_deposit"].XValueMember = "d_date";
chart_sum.Series["series_deposit"].YValueMembers = "deposit";
chart_sum.Series["series_compensation"].XValueMember = "d_date";
chart_sum.Series["series_compensation"].YValueMembers = "compensation";
chart_sum.Series["series_compensation"].Color = Color.Red;
chart_sum.Series["series_salary"].XValueMember = "d_date";
chart_sum.Series["series_salary"].YValueMembers = "salary";
chart_sum.Series["series_salary"].Color = Color.SaddleBrown;
//chart_sum.ChartAreas[0].AxisX.Interval = 1;
switch (range_id)
{
case 1:
//chart_sum.ChartAreas[0].AxisX.LabelStyle.Format = "dd/M/yyyy";
chart_sum.ChartAreas[0].AxisY.Interval = 500;
break;
case 2:
//chart_sum.ChartAreas[0].AxisX.LabelStyle.Format = "M/yyyy";
chart_sum.ChartAreas[0].AxisY.Interval = 2000;
break;
case 3:
//chart_sum.ChartAreas[0].AxisX.LabelStyle.Format = "yyyy";
chart_sum.ChartAreas[0].AxisY.Interval = 4000;
break;
}
chart_sum.ChartAreas[0].AxisX.LabelStyle.Angle = 90;
chart_sum.DataBind();
}
else
{
error_message = "הנתונים עבור הטווח הנבחר לא קיימים במערכת";
this.Page.Form.Controls.Add(fn.createCustomMessage(error_message));
pnl_chart.Visible = false;
}
}
日期值不是基于数据源,而是根据指定的间隔自动生成。 Chart image 当我将时间间隔评为TaW的sagested时,我会在一周的情况下得到以下输出(除了前导和结束标签之外的罚款) 在月份的情况下,标签以两周的间隔产生 请告知如何在数据源中显示的图表AxisX上显示日期,而不是自动生成的值。