{
SqlConnection con=new SqlConnection ();
Con. The ConnectionString="server=. The database=test; Integrated security=SSPI ";
Try
{
Con. The Open ();
SqlCommand CMD=con. CreateCommand ();
Cmd.Com mandType=CommandType. Text;
//query data
Cmd.Com mandText="select top (500), humidity, datex from sht102 where which=2 and datex> '2021-2-1' order by datex ";
SqlDataReader Dr=CMD. ExecuteReader ();
//to build two lists to store we want drawing data, because the chart the received data is a List
List
List
String STR="";
While (Dr. Read ())
{
//note that the id of the data types in the database is System. The Integer,
//num data type is System. Double, but in some columns, num is null, so before operate
//to judge whether is empty
If (Dr [1] is DBNull)
{}
The else
{
DateTime tempdata=https://bbs.csdn.net/topics/(DateTime) Dr [1];
STR=tempdata. ToString (" MM - dd yyyy - HH: MM: ss ");
//numList. Add ((DateTime) tempdata);
NumList. Add (DateTime. Parse (STR));
}
Humidity. The Add ((float) Dr [0]);
}
//drawing function
DrawLines (humidity, numList);
Dr. Close ();//close to perform
}
The catch (Exception)
{
Console. WriteLine (" connection exception ");
Throw;
}
The finally
{
Con. The Close ();
}
}
Private void drawLines (List
{
List
List
//chart1 ChartAreas [0]. AxisX. LabelStyle. Format="HH: mm: ss";
//line color
Chart1. Series [0]. Color=Color. DeepSkyBlue;
//line thicknesses
Chart1. Series [0]. BorderWidth=1;
Center color//marked points
Chart1. Series [0]. MarkerColor=Color. DeepSkyBlue;
//marker point size
Chart1. Series [0]. MarkerSize=5;
//markers in type
Chart1. Series [0]. MarkerStyle=System. Windows, Forms, DataVisualization. Charting. MarkerStyle. Circle;
//bind data
"ChartArea1" chart1. ChartAreas [] AxisX. LabelStyle. Format="- dd yyyy - MM - HH: MM: ss".
Chart1. Series [0]. Points. DataBindXY (yData xData);
}
Private void button1_Click (object sender, EventArgs e)
{
SeekSql ();
}
Directly shows the X axis does not display the time - dd yyyy - MM - HH: MM: ss
CodePudding user response:
If don't write chart1 ChartAreas [r]. "ChartArea1" AxisX. LabelStyle. The FormatWhat is the effect?
Should be able to read out normal?
Or try "} {0: D this?"
CodePudding user response:
Chart1. ChartAreas [0]. AxisX. LableStyle. Format="- dd yyyy - MM - HH: MM: ss", too, did not understand, do not know much about the chart, from the SQL access time if there is a problem in the transformation process, the following is the effect of database readCodePudding user response: