青海省公路建设服务网站,天津做网站.都找津坤科技,深圳市造价信息网官网,网站开发所有工具多大LiveCharts#xff1a;
LiveCharts2预览版、内存管理不是很好#xff0c;长时间持续更新的情况下#xff0c;内存溢出#xff0c;慎用
数据加载量不能太大#xff08;1000点左右 开始卡#xff09;
第一步#xff1a;下载LiveChart NuGet包 第二步#xff1a;引用
LiveCharts2预览版、内存管理不是很好长时间持续更新的情况下内存溢出慎用
数据加载量不能太大1000点左右 开始卡
第一步下载LiveChart NuGet包 第二步引用 xmlns:lvcclr-namespace:LiveCharts.Wpf;assemblyLiveCharts.Wpf
第三步使用
折线图CartesianChart
XAML中使用
一个图表对应多个序列可以是多个折线图和多个柱状图
属性
PointGeometrySize折线图上的白点大小
LineSmoothness折线图圆滑曲线
ScalesYAt对齐到哪个Y轴因为可以写多个Y轴所以需要对应一下
CartesianChart设置坐标
AxisX设置X坐标 需要Labels数量和Values数量保持一致
AxisY纵坐标一般设置做大数值和最小数值
Separator设置步长
Sections设置预警线
lvc:CartesianChartlvc:CartesianChart.Serieslvc:LineSeries Values23, 11, 99, 70, 87, 87, 84, 91, 55, 27, 79, 70, 70, 10, 14, 24, 27, 89, 61, 39 StrokeOrange Fill#1F00 PointGeometrySize0 LineSmoothness0 Title折线图/lvc:ColumnSeries Values23, 11, 99, 70, 87, 87, 84, 91, 55, 27, 79, 70, 70, 10, 14, 24, 27, 89, 61, 39Title柱状图 ScalesYAt0 MaxColumnWidth20 FillGreen//lvc:CartesianChart.Serieslvc:CartesianChart.AxisXlvc:Axis Labelsa,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,vlvc:Axis.Separatorlvc:Separator Step1 StrokeRed StrokeDashArray3,3//lvc:Axis.Separator/lvc:Axis/lvc:CartesianChart.AxisXlvc:CartesianChart.AxisYlvc:Axis MinValue0 MaxValue100lvc:Axis.Separatorlvc:Separator Step20 StrokeGreen StrokeDashArray3,3 //lvc:Axis.Separatorlvc:Axis.Sectionslvc:AxisSection Value75 StrokeRed StrokeThickness1 //lvc:Axis.Sections/lvc:Axislvc:Axis MinValue0 MaxValue2 LabelFormatter{Binding YLableFormatter}lvc:Axis.Separatorlvc:Separator Step0.4 StrokeDashArray3,3 StrokeThickness0 //lvc:Axis.Separator/lvc:Axis/lvc:CartesianChart.AxisY/lvc:CartesianChart
显示结果 因为设置Y轴坐标的时候是double类型所以导致精度丢失需要设置LabelFormatter
C#处理精度丢失代码
// 保留两位小数
public Funcdouble, string YLableFormatter { get; set; } d d.ToString(0.00);
处理之后的效果 没有问题 C#中给表格赋值
XAML代码
lvc:CartesianChart Series{Binding SeriesList}/
C#赋值核心代码
public SeriesCollection SeriesList { get; set; } new SeriesCollection();// 可以使用C#进行动态赋值
SeriesList.Add(new LineSeries
{Values new ChartValuesdouble { 75, 14, 36, 33, 89, 76, 23, 21, 77, 90, 21, 22, 54, 90, 32, 47, 97, 81, 63, 21 },Title 压力,Stroke Brushes.Green,
});
效果图 环形图 Gauge
属性
Uses360Mode是否使用360度
From从多少开始
To到多少结束
Value值多少
lvc:Gauge Uses360ModeTrue From0 To100 Value85 /
显示效果 仪表盘AngularGauge
属性
Sections仪表警戒线
FromValue从多少位置开始
ToValue到多少位置结束
LabelsStep每一个的步长
TicksStep小格的步长
Wedge整个的角度
TicksForeground刻度线的颜色
Foreground字体颜色
SectionsInnerRadius环形圆角度
Value值
lvc:AngularGauge Grid.Row1 Grid.Column1 FromValue50 ToValue250 LabelsStep50 TicksStep25 Wedge270 TicksForegroundWhiteForegroundWhite FontWeightBold FontSize16 SectionsInnerRadius0.5 Value180lvc:AngularGauge.Sectionslvc:AngularSection FromValue50 ToValue200 FillOrange /lvc:AngularSection FromValue200 ToValue260 FillRed //lvc:AngularGauge.Sections
/lvc:AngularGauge
效果 ScottPlot考虑性能 建议这个 号称500万点数据无压力
第一步下载ScottPlot NuGet包 第二步引用 xmlns:sp clr-namespace:ScottPlot;assemblyScottPlot.Wpf
第三步使用
注意此控件只可以C#代码进行赋值
sp:WpfPlot Namewpf_plot /
C#代码
属性
DataGen模拟数据加载
Refresh()刷新表格 当数据变化的时候 刷新表格数据
YAxis第一个Y轴
YAxis2第二个Y轴
YAxisIndex对应的Y轴
AddAxis可以建立多个轴 XY都可以
ManualTickSpacing轴显示的时间格式化
TickLabelFormat刻度标签格式化
TickLabelStyle标签样式
AddHorizontalLine添加Y轴预警线
AddVerticalLine添加X轴预警线
using ScottPlot;
using System.Windows;namespace XH.CustomLesson.ChartLib
{/// summary/// ScottPlotTestWindow.xaml 的交互逻辑/// /summarypublic partial class ScottPlotTestWindow : Window{public ScottPlotTestWindow(){InitializeComponent();this.Loaded ScottPlotTestWindow_Loaded;}private void ScottPlotTestWindow_Loaded(object sender, RoutedEventArgs e){// 数据加载var plt wpf_plot.Plot;// 模拟序列数据double[] datas DataGen.RandomWalk(new Random(),1000000);plt.AddSignal(datas);// 不调 Refresh 会报错 必须调用Refresh() // YAxis第一个Y轴// YAxis2第二个Y轴plt.YAxis2.Ticks(true);plt.YAxis2.Color(System.Drawing.Color.Red);datas DataGen.Cos(1000000);var series plt.AddSignal(datas);//YAxisIndex 对应的Y轴 series.YAxisIndex 1;// 可以有多个轴 第三个Y轴var yAxis3 plt.AddAxis(ScottPlot.Renderable.Edge.Right,10,新轴,System.Drawing.Color.Blue);datas DataGen.Sin(1000000);series plt.AddSignal(datas);series.YAxisIndex 10;// 第二个X轴plt.XAxis2.Ticks(true);plt.XAxis2.Color(System.Drawing.Color.Green);datas DataGen.Random(new Random(),100);var barPlot plt.AddBar(datas, System.Drawing.Color.Orange);barPlot.XAxisIndex 1;barPlot.YAxisIndex 1;// 第三个X轴var xAxis3 plt.AddAxis(ScottPlot.Renderable.Edge.Bottom,3, 第三个X轴, System.Drawing.Color.OrangeRed);xAxis3.Ticks(true);xAxis3.DateTimeFormat(true);// X轴时间格式化xAxis3.ManualTickSpacing(20, ScottPlot.Ticks.DateTimeUnit.Day);// 斜着显示xAxis3.TickLabelStyle(rotation: 45);// 第四个Y轴var yAxis4 plt.AddAxis(ScottPlot.Renderable.Edge.Left,4, 第四个Y轴, System.Drawing.Color.OrangeRed);yAxis4.Ticks(true);yAxis4.DateTimeFormat(true);// Y轴格式化yAxis4.TickLabelFormat(P1, false);// 添加第三个数据序列 并且对齐到第三个X轴 和 第四个Y轴datas DataGen.Sin(1000);double[] x_datas new double[1000];DateTime dateTime DateTime.Now;for (int i 0; i x_datas.Length; i){x_datas[i] dateTime.AddDays(i).ToOADate();} var scatterPlot plt.AddScatterLines(x_datas, datas, System.Drawing.Color.Green);scatterPlot.YAxisIndex 4;scatterPlot.XAxisIndex 3;// 预警线var hl plt.AddHorizontalLine(0.8, System.Drawing.Color.Red);// 对应到哪个Y轴//hl.YAxisIndex 4;plt.AddVerticalLine(DateTime.Now.AddDays(50).ToOADate());wpf_plot.Refresh();}}
}显示结果 OxyPlot
LightingChart 付费