我在下面的代码实现图表列时遇到问题:
string CmdString = " SELECT convert(varchar,avg(DATEDIFF(second,[DateOuverture],[DateCloture]))/(86400)) + 'D:'+
convert(varchar,avg(DATEDIFF(second,[DateOuverture],[DateCloture]))%(86400)/3600) + 'H:'+
convert(varchar,avg(DATEDIFF(second,[DateOuverture],[DateCloture]))% 3600)/60)+'M:'+convert(varchar,avg(DATEDIFF(second,[DateOuverture],[DateCloture]))%60) +'S' as Time,A FROM table group by A";
SqlCommand myCommand = new SqlCommand(CmdString, con);
myCommand.Connection.Open();
SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
Chart4.Series["Series1"].Points.DataBindXY(myReader, "A",myReader,"Time" );
示例:
Time(9D:1H:25M:47S,13D:0H:56M:27,15D:0H:8M:24S)
A(MAMMO,SCINTIGRAPHIE,STANDARD)
我希望在XvalueMemeber
中显示A,在YValueMemeber
答案 0 :(得分:0)
您应该更具体,也许可以发布一些代码。
无论如何,这是我绑定Chart
的方式。
要获取Chart
的数据源,您需要填写DataSet
,然后从其中一个DataTable中获取数据。
// by index:
DataTable firstTable = dataSet.Tables[0];
// or by name:
DataTable firstTable = dataSet.Tables["Table1"];
DataView dv = firstTable.DefaultView;
然后将Chart与DataView绑定:
Chart Chart1 = new Chart();
Chart1.Series["Series1"].ChartType = SeriesChartType.Column;
// Some other initialization for the Chart...
Chart1.Series["Series1"].Points.DataBindXY(dv, "X_COLUMN", dv, "Y_COLUMN");
- 编辑 -
您可以尝试将时间转换从整数秒数量移动到字符串(DD:HH:...),从查询级别移动到代码级别,在Chart.Customize
EventHandler中。
protected void Chart1_Customize(object sender, EventArgs e)
{
foreach (var label in Chart1.ChartAreas[0].AxisY.CustomLabels)
{
int secondsAmount = int.Parse(label.Text);
string timeString = "";
// Insert the conversion logic here and get the timeString...
label.Text = timeString; // with format DD:HH:MM:SS
}
}
这样,整数值用于获取图表上条形(或线条,或其他......)的比例大小,然后可见标签从秒数转换为更多&# 34;人性可以理解"。