通过向series1描点的方式加载数据
前端页面
<dxc:ChartControl Name="chart2" BorderThickness="0" HorizontalAlignment="Left" Background="#F0F8FF">
<dxc:XYDiagram2D EnableAxisXNavigation="True">
<!--X轴-->
<dxc:XYDiagram2D.AxisX>
<dxc:AxisX2D Name="axisX2">
<dxc:AxisX2D.DateTimeScaleOptions>
<dxc:ContinuousDateTimeScaleOptions />
</dxc:AxisX2D.DateTimeScaleOptions>
<dxc:AxisX2D.Label>
<dxc:AxisLabel TextPattern="{}{A:mm:ss}" />
</dxc:AxisX2D.Label>
</dxc:AxisX2D>
</dxc:XYDiagram2D.AxisX>
<!--Y轴-->
<dxc:XYDiagram2D.AxisY>
<dxc:AxisY2D Interlaced="True">
<dxc:AxisY2D.Title>
<dxc:AxisTitle Content="实际值" />
</dxc:AxisY2D.Title>
</dxc:AxisY2D>
</dxc:XYDiagram2D.AxisY>
<!--series1-->
<dxc:LineSeries2D Name="series1" ArgumentScaleType="DateTime" DisplayName="Iac1">
<dxc:LineSeries2D.LineStyle>
<dxc:LineStyle Thickness="2" />
</dxc:LineSeries2D.LineStyle>
</dxc:LineSeries2D>
</dxc:XYDiagram2D>
<!-- 图例 -->
<dxc:ChartControl.Legend>
<dxc:Legend
HorizontalPosition="Left"
VerticalPosition="TopOutside"
Orientation="Horizontal" />
</dxc:ChartControl.Legend>
</dxc:ChartControl>
后端绑定数据
//数据库中读取数据
DataSet ds = SQLiteHelper.ExecuteDataSet(SQLiteHelper.LocalDbConnectionString, "select * from history_data", CommandType.Text);
//转成DataTable接受
DataTable dataTableMain = ds.Tables[0];
//遍历数据表,向series1描点
foreach (DataRow dr in dataTableMain.Rows){
var dateTime = Convert.ToDateTime(dr["absTime"]).ToString("HH:mm:ss");
double value = Convert.ToDouble(dr["Uac"].ToString());
series1.Points.Add(new SeriesPoint(dateTime, value));
}
//absTime和Uac是数据库中history_dat表的两个字段