使用 asp.net 在图表中的 YvalueMemeber 中实现自定义值
Implement custom value in YvalueMemeber in chart using asp.net
我在下面的代码中实现图表列时遇到问题:
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
中显示时间
你应该更具体一些,也许 post 你的一些代码。
反正我是这样绑定的Chart
.
要获取 Chart
的数据源,您需要填充 DataSet
,然后从其中一个数据表中获取数据。
// 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");
- 编辑 -
您可以尝试在 Chart.Customize
EventHandler.
内将时间转换从整数秒数移动到字符串 (DD:HH:...),从查询级别移动到代码级别
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
}
}
这样,整数值用于获取图表上条形图(或线条,或其他...)的比例大小,然后可见标签从秒数转换为更多"humanly understandable".
我在下面的代码中实现图表列时遇到问题:
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
你应该更具体一些,也许 post 你的一些代码。
反正我是这样绑定的Chart
.
要获取 Chart
的数据源,您需要填充 DataSet
,然后从其中一个数据表中获取数据。
// 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");
- 编辑 -
您可以尝试在 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
}
}
这样,整数值用于获取图表上条形图(或线条,或其他...)的比例大小,然后可见标签从秒数转换为更多"humanly understandable".