Home > Net >  C # chart, I read two values from a MSSQL database, respectively, a time, a humidity, x does not dis
C # chart, I read two values from a MSSQL database, respectively, a time, a humidity, x does not dis

Time:02-27

Private void seekSql ()
{
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 Humidity=new List (a);
List NumList=new List (a);
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 List1 List List2)
{
List XData=https://bbs.csdn.net/topics/list1;
List YData=https://bbs.csdn.net/topics/list2;
//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 Format

What 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 read

CodePudding user response:

reference 1st floor by_ love reply:
. If you don't write chart1 ChartAreas [r]. "ChartArea1 AxisX. LabelStyle. The Format

What is the effect?

Should be able to read out normal?

Or try "} {0: D this?"


I have a try
  •  Tags:  
  • C#