{"id":2405,"date":"2024-10-21T13:51:58","date_gmt":"2024-10-21T05:51:58","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=2405"},"modified":"2024-10-21T13:51:58","modified_gmt":"2024-10-21T05:51:58","slug":"scottplot-%e6%9c%ac%e5%9c%b0%e5%a4%a7%e6%89%b9%e9%87%8f%e6%95%b0%e6%8d%ae%e7%bb%98%e5%88%b6%e5%b0%9d%e8%af%95","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2024\/10\/21\/scottplot-%e6%9c%ac%e5%9c%b0%e5%a4%a7%e6%89%b9%e9%87%8f%e6%95%b0%e6%8d%ae%e7%bb%98%e5%88%b6%e5%b0%9d%e8%af%95\/","title":{"rendered":"ScottPlot \u8bfb\u53d6\u672c\u5730\u5927\u6279\u91cf\u6570\u636e\u7ed8\u5236\u5c1d\u8bd5"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanroimg.oss-cn-shanghai.aliyuncs.com\/img\/202410211351573.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u76f8\u5173<strong>\u4ecb\u7ecd<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/ScottPlotQuickstart\">\u5feb\u901f\u5165\u95e8<\/a> &#8211; ScottPlot 5 \u4e2d\u7684\u57fa\u672c\u529f\u80fd\u8c03\u67e5<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/AxisAndTicks\">\u8f74\u548c\u523b\u5ea6<\/a> &#8211; \u8f74\u6807\u7b7e\u548c\u523b\u5ea6\u7684\u5e38\u89c1\u81ea\u5b9a\u4e49\u793a\u4f8b<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Legend\">\u914d\u7f6e\u56fe\u4f8b<\/a> &#8211; \u56fe\u4f8b\u662f\u901a\u5e38\u663e\u793a\u5728\u7ed8\u56fe\u4e00\u89d2\u7684\u952e<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Styling\">\u8bbe\u7f6e\u7ed8\u56fe\u6837\u5f0f<\/a> &#8211; \u5982\u4f55\u81ea\u5b9a\u4e49\u7ed8\u56fe\u7684\u5916\u89c2<\/li><\/ul>\n\n\n\n<p><strong>\u8f74<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/AdvancedAxis\">\u9ad8\u7ea7\u8f74\u529f\u80fd<\/a> &#8211; \u5982\u4f55\u8fdb\u4e00\u6b65\u81ea\u5b9a\u4e49\u8f74<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/CustomizingGrids\">\u81ea\u5b9a\u4e49\u8f74\u7f51<\/a> &#8211; \u8f74\u7f51\u7ebf\u7684\u9ad8\u7ea7\u81ea\u5b9a\u4e49<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/CustomizingTicks\">\u81ea\u5b9a\u4e49\u523b\u5ea6<\/a> &#8211; \u523b\u5ea6\u7ebf\u548c\u523b\u5ea6\u6807\u7b7e\u7684\u9ad8\u7ea7\u81ea\u5b9a\u4e49<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/DateTimeAxes\">DateTime Axes<\/a> &#8211; \u5728 DataTime \u8f74\u4e0a\u7ed8\u5236\u6570\u636e\u503c<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/MultiAxis\">\u591a\u8f74<\/a> &#8211; \u523b\u5ea6\u7ebf\u81ea\u5b9a\u4e49\u548c\u591a\u8f74\u56fe<\/li><\/ul>\n\n\n\n<p><strong>\u5e03\u5c40<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Layout\">\u5e03\u5c40\u9009\u9879<\/a> &#8211; \u5982\u4f55\u81ea\u5b9a\u4e49\u7ed8\u56fe\u7684\u5e03\u5c40<\/li><\/ul>\n\n\n\n<p><strong>\u7ed8\u56fe\u7c7b\u578b<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Annotation\">\u6ce8\u91ca<\/a> &#8211; \u6ce8\u91ca\u662f\u4f4d\u4e8e\u6570\u636e\u533a\u57df\u4e0a\u65b9\u7684\u59cb\u7ec8\u53ef\u89c1\u7684\u6587\u672c\u6807\u7b7e\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/ArrowCoordinated\">\u7bad\u5934<\/a> &#8211; \u7bad\u5934\u6307\u5411\u5750\u6807\u7a7a\u95f4\u4e2d\u7684\u67d0\u4e2a\u4f4d\u7f6e\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/AxisLines\">\u8f74\u7ebf<\/a> &#8211; \u8f74\u7ebf\u8868\u793a\u8f74\u4e0a\u7684\u4f4d\u7f6e\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/AxisSpans\">\u8f74\u8de8\u5ea6<\/a> &#8211; \u8f74\u8de8\u5ea6\u8868\u793a\u8f74\u7684\u8303\u56f4\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Bar\">\u6761\u5f62\u56fe<\/a> &#8211; \u6761\u5f62\u56fe\u5c06\u503c\u8868\u793a\u4e3a\u6c34\u5e73\u6216\u5782\u76f4\u77e9\u5f62<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Box\">\u7bb1\u5f62\u56fe<\/a> &#8211; \u7bb1\u5f62\u56fe\u4e00\u76ee\u4e86\u7136\u5730\u663e\u793a\u5206\u5e03<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Callout\">\u6807\u6ce8<\/a> &#8211; \u6807\u6ce8\u663e\u793a\u6807\u7b7e\uff0c\u5e76\u901a\u8fc7\u6807\u8bb0\u56fe\u4e0a\u70b9\u7684\u7bad\u5934\u8fde\u63a5\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Coxcomb\">Coxcomb \u56fe<\/a> &#8211; Coxcomb \u56fe\u662f\u4e00\u4e2a\u997c\u56fe\uff0c\u5176\u4e2d\u5207\u7247\u7684\u89d2\u5ea6\u662f\u6052\u5b9a\u7684\uff0c\u4f46\u534a\u5f84\u4e0d\u662f\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Crosshair\">\u5341\u5b57\u51c6\u7ebf<\/a> &#8211; \u5341\u5b57\u51c6\u7ebf\u7ed3\u5408\u4e86\u6c34\u5e73\u8f74\u7ebf\u548c\u5782\u76f4\u8f74\u7ebf\uff0c\u4ee5\u5728\u5750\u6807\u7a7a\u95f4\u4e2d\u6807\u8bb0\u4f4d\u7f6e\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Ellipse\">\u692d\u5706<\/a> &#8211; \u692d\u5706\u662f\u5177\u6709\u5b9a\u4e49\u4e2d\u5fc3\u548c\u4e0d\u540c X \u548c Y \u534a\u5f84\u7684\u66f2\u7ebf\u3002\u5706\u662f X \u534a\u5f84\u7b49\u4e8e\u5176 Y \u534a\u5f84\u7684\u692d\u5706\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/ErrorBar\">\u8bef\u5dee\u7ebf<\/a> &#8211; \u8bef\u5dee\u7ebf\u8868\u793a\u6d4b\u91cf\u503c\u7684\u53ef\u80fd\u8303\u56f4<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/FillY\">FillY \u56fe<\/a> &#8211; FillY \u56fe\u5728\u5b9a\u4e49\u7684 X \u4f4d\u7f6e\u663e\u793a\u4e24\u4e2a Y \u503c\u4e4b\u95f4\u7684\u5782\u76f4\u8303\u56f4<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Finance\">\u8d22\u52a1\u56fe<\/a> &#8211; \u8d22\u52a1\u56fe\u663e\u793a\u6309\u65f6\u95f4\u8303\u56f4\u5206\u7bb1\u7684\u4ef7\u683c\u6570\u636e<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Function\">\u51fd\u6570<\/a> &#8211; \u51fd\u6570\u56fe\u662f\u4e00\u79cd\u7ebf\u56fe\uff0c\u5176\u4e2d Y \u4f4d\u7f6e\u7531\u4f9d\u8d56\u4e8e X \u7684\u51fd\u6570\u5b9a\u4e49\uff0c\u800c\u4e0d\u662f\u79bb\u6563\u6570\u636e\u70b9\u7684\u96c6\u5408\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Heatmap\">\u70ed\u56fe<\/a> &#8211; \u70ed\u56fe\u5c06 2D \u6570\u636e\u4e2d\u7684\u503c\u663e\u793a\u4e3a\u5177\u6709\u4e0d\u540c\u5f3a\u5ea6\u7684\u50cf\u5143\u7684\u56fe\u50cf<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Images\">\u56fe\u50cf<\/a> &#8211; \u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5c06\u56fe\u50cf\u653e\u7f6e\u5728\u7ed8\u56fe\u4e0a<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/LinePlot\">Line Plot<\/a> &#8211; \u53ef\u4ee5\u4f7f\u7528 Start\u3001End \u548c\u53ef\u9009\u7684 LineStyle \u5c06\u7ebf\u56fe\u653e\u7f6e\u5728\u5750\u6807\u7a7a\u95f4\u4e2d\u7684\u7ed8\u56fe\u4e0a\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Lollipop\">\u68d2\u68d2\u7cd6\u56fe<\/a> &#8211; \u68d2\u68d2\u7cd6\u56fe\u662f\u6761\u5f62\u56fe\u7684\u4e00\u79cd\u53d8\u4f53\uff0c\u5b83\u4f7f\u7528\u4ece\u57fa\u7ebf\u5ef6\u4f38\u5230\u6807\u8bb0\uff08\u5934\u90e8\uff09\u7684\u7ebf\u6761\uff08\u830e\uff09\u6765\u8868\u793a\u6570\u636e\u70b9\u3002\u4e0e\u4f20\u7edf\u6761\u5f62\u56fe\u76f8\u6bd4\uff0cLollipop \u7a81\u51fa\u663e\u793a\u5355\u4e2a\u6570\u636e\u70b9\u7684\u89c6\u89c9\u6df7\u4e71\u7a0b\u5ea6\u8f83\u4f4e\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Marker\">\u6807\u8bb0<\/a> &#8211; \u6807\u8bb0\u53ef\u4ee5\u653e\u7f6e\u5728\u5750\u6807\u7a7a\u95f4\u7684\u7ed8\u56fe\u4e0a\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Phasor\">\u76f8\u91cf\u56fe<\/a> &#8211; \u76f8\u91cf\u56fe\u5728\u4ee5\u539f\u70b9\u4e3a\u4e2d\u5fc3\u7684\u5f84\u5411\u8f74\u4e0a\u663e\u793a\u77e2\u91cf<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Pie\">\u997c\u56fe<\/a> &#8211; \u997c\u56fe\u5c06\u6570\u5b57\u6bd4\u4f8b\u8bf4\u660e\u4e3a\u5706\u7684\u5207\u7247\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Polar\">\u6781\u8f74<\/a> &#8211; \u521b\u5efa\u6781\u8f74\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u7ed8\u56fe\u4e2d\uff0c\u4ee5\u5728\u5706\u5f62\u5750\u6807\u7cfb\u4e0a\u663e\u793a\u6570\u636e\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Population\">\u603b\u4f53\u56fe<\/a> &#8211; \u603b\u4f53\u56fe\u663e\u793a\u5355\u4e2a\u503c\u7684\u96c6\u5408\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Radar\">\u96f7\u8fbe\u56fe<\/a> &#8211; \u96f7\u8fbe\u56fe\uff08\u4e5f\u79f0\u4e3a\u8718\u86db\u56fe\u6216\u661f\u5f62\u56fe\uff09\u5c06\u591a\u8f74\u6570\u636e\u8868\u793a\u4e3a\u56f4\u7ed5\u4e2d\u5fc3\u70b9\u5706\u5468\u6392\u5217\u7684\u8f74\u4e0a\u7684 2D \u5f62\u72b6\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/RadialGauge\">\u5f84\u5411\u4eea\u8868<\/a> &#8211; \u5f84\u5411\u4eea\u8868\u56fe\u5c06\u6807\u91cf\u6570\u636e\u663e\u793a\u4e3a\u5706\u5f62\u4eea\u8868\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Scatter\">\u6563\u70b9\u56fe<\/a> &#8211; \u6563\u70b9\u56fe\u5728\u5750\u6807\u7a7a\u95f4\u4e2d\u7684 X\/Y \u4f4d\u7f6e\u663e\u793a\u70b9\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Shapes\">\u5f62\u72b6<\/a> &#8211; \u53ef\u4ee5\u6dfb\u52a0\u5230\u7ed8\u56fe\u7684\u57fa\u672c\u5f62\u72b6<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Signal\">\u4fe1\u53f7\u56fe<\/a> &#8211; \u4fe1\u53f7\u56fe\u663e\u793a\u5747\u5300\u5206\u5e03\u7684\u6570\u636e<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/SignalConst\">SignalConst<\/a> &#8211; SignalConst \u662f\u4e00\u79cd\u4fe1\u53f7\u56fe\uff0c\u5b83\u5305\u542b\u4e0d\u53ef\u53d8\u7684\u6570\u636e\u70b9\u5e76\u5360\u7528\u66f4\u591a\u5185\u5b58\uff0c\u4f46\u4e3a\u8d85\u5927\u578b\u6570\u636e\u96c6\u63d0\u4f9b\u66f4\u9ad8\u7684\u6027\u80fd\u3002\u5b83\u5f88\u5c11\u9700\u8981\uff0c\u4f46\u6700\u9002\u5408\u7528\u4e8e\u7ed8\u5236\u5305\u542b\u6570\u767e\u4e07\u4e2a\u70b9\u7684\u6570\u636e\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/SignalXY\">SignalXY \u7ed8\u56fe<\/a> &#8211; SignalXY \u662f\u4e00\u79cd\u9ad8\u6027\u80fd\u7ed8\u56fe\u7c7b\u578b\uff0c\u9488\u5bf9 X \u503c\u59cb\u7ec8\u5347\u5e8f\u7684 X\/Y \u5bf9\u8fdb\u884c\u4e86\u4f18\u5316\u3002\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0cSignalXY \u56fe\u7684\u6027\u80fd\u6bd4\u6563\u70b9\u56fe\uff08\u5141\u8bb8\u65e0\u5e8f\u7684 X \u70b9\uff09\u9ad8\u5f97\u591a\uff0c\u4f46\u4e0d\u5982\u4fe1\u53f7\u56fe\uff08\u9700\u8981 X \u70b9\u4e4b\u95f4\u7684\u56fa\u5b9a\u95f4\u8ddd\uff09\u7684\u6027\u80fd\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Text\">\u6587\u672c<\/a> &#8211; \u6587\u672c\u6807\u7b7e\u53ef\u4ee5\u653e\u7f6e\u5728\u5750\u6807\u7a7a\u95f4\u7684\u7ed8\u56fe\u4e0a<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/VectorField\">Vector Field<\/a> &#8211; \u5411\u91cf\u573a\u663e\u793a\u4ee5\u5750\u6807\u7a7a\u95f4\u4e2d\u7684\u70b9\u4e3a\u6839\u7684\u5411\u91cf\u96c6\u5408<\/li><\/ul>\n\n\n\n<p><strong>\u7edf\u8ba1\u5b66<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Regression\">\u56de\u5f52<\/a> &#8211; \u4f7f\u7ebf\u6761\u9002\u5408\u6570\u636e\u7684\u7edf\u8ba1\u64cd\u4f5c<\/li><\/ul>\n\n\n\n<p><strong>\u6742\u9879<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/AdvancedStyling\">\u9ad8\u7ea7\u6837\u5f0f<\/a> &#8211; \u9002\u7528\u4e8e\u5bfb\u6c42\u5e7f\u6cdb\u81ea\u5b9a\u4e49\u9009\u9879\u7684\u7528\u6237\u7684\u529f\u80fd\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/Internationalization\">\u56fd\u9645\u5316<\/a> &#8211; \u8de8\u5177\u6709\u4e0d\u540c\u6587\u672c\u548c\u6570\u5b57\u8981\u6c42\u7684\u533a\u57df\u6027\u4f7f\u7528 ScottPlot\u3002<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/palettes\">\u8c03\u8272\u677f<\/a> &#8211; \u53ef\u7528\u4e8e\u8868\u793a\u5206\u7c7b\u6570\u636e\u7684\u989c\u8272\u96c6\u5408<\/li><li><a href=\"https:\/\/scottplot.net\/cookbook\/5.0\/colormaps\">Colormaps<\/a> &#8211; \u53ef\u7528\u4e8e\u8868\u793a\u8fde\u7eed\u6570\u636e\u7684\u989c\u8272\u6e10\u53d8<\/li><\/ul>\n\n\n\n<p><strong>xaml<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Window x:Class=\"RealTimePlotDemo.MainWindow\"\n        xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n        xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n        xmlns:d=\"http:\/\/schemas.microsoft.com\/expression\/blend\/2008\"\n        xmlns:mc=\"http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006\"\n        xmlns:local=\"clr-namespace:RealTimePlotDemo\"\n        xmlns:ScottPlot=\"clr-namespace:ScottPlot.WPF;assembly=ScottPlot.WPF\"  \n        mc:Ignorable=\"d\"\n        Title=\"Real-Time Plot Demo\" Height=\"650\" Width=\"1100\"&gt;\n    &lt;Grid&gt;\n        &lt;Grid.RowDefinitions&gt;\n            &lt;RowDefinition Height=\"4*\"\/&gt;\n            &lt;!-- \u6298\u7ebf\u56fe\u533a\u57df --&gt;\n            &lt;RowDefinition Height=\"3*\"\/&gt;\n            &lt;!-- \u76f4\u65b9\u56fe\u533a\u57df --&gt;\n        &lt;\/Grid.RowDefinitions&gt;\n\n        &lt;ScottPlot:WpfPlot Name=\"linePlot\" Grid.Row=\"0\" \/&gt;\n        &lt;!-- \u6298\u7ebf\u56fe --&gt;\n        &lt;ScottPlot:WpfPlot Name=\"histogramPlot\" Grid.Row=\"1\" \/&gt;\n        &lt;!-- \u76f4\u65b9\u56fe --&gt;\n    &lt;\/Grid&gt;\n&lt;\/Window&gt;<\/code><\/pre>\n\n\n\n<p><strong>xaml.cs<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using ScottPlot;\nusing System;\nusing System.IO;\nusing System.Linq;\nusing System.Timers;\nusing System.Windows;\n\nnamespace RealTimePlotDemo {\n    public partial class MainWindow : Window {\n        \/\/ \u5e38\u91cf\u5b9a\u4e49\n        private const int DataSize = 50000; \/\/ \u6570\u636e\u70b9\u603b\u6570\n        private const double XInterval = 2.0; \/\/ X \u503c\u4e4b\u95f4\u7684\u95f4\u9694\n        private const double YAmplitude = 0.5; \/\/ \u6b63\u5f26\u6ce2\u7684\u5e45\u5ea6\n        private const double NoiseRange = 0.02; \/\/ \u968f\u673a\u566a\u58f0\u7684\u8303\u56f4\n        private const double UpdateInterval = 100; \/\/ \u56fe\u5f62\u66f4\u65b0\u7684\u65f6\u95f4\u95f4\u9694\uff08\u6beb\u79d2\uff09\n        private const double VisibleRange = 50; \/\/ \u53ef\u89c6\u8303\u56f4\u7684\u957f\u5ea6\uff08X \u8f74\uff09\n        private const int BatchSize = 100; \/\/ \u6bcf\u6b21\u7ed8\u5236\u7684\u6570\u636e\u70b9\u6570\u91cf\uff0c\u8bbe\u7f6e\u4e3a 1 \u786e\u4fdd\u6bcf\u4e2a\u70b9\u5bf9\u5e94\u4e00\u4e2a\u77e9\u5f62\n\n        private Timer _timer; \/\/ \u5b9a\u65f6\u5668\n        private double&#91;] _lineDataX; \/\/ X \u8f74\u6570\u636e\n        private double&#91;] _lineDataY; \/\/ Y \u8f74\u6570\u636e\n        private double&#91;] _histogramData; \/\/ \u76f4\u65b9\u56fe\u6570\u636e\n        private double&#91;] _histogramX; \/\/ \u76f4\u65b9\u56fe\u7684 X \u8f74\u6570\u636e\n        private Random _random; \/\/ \u968f\u673a\u6570\u751f\u6210\u5668\n        private string _dataFilePath; \/\/ \u4fdd\u5b58\u6570\u636e\u7684\u6587\u4ef6\u8def\u5f84\n        private int _currentIndex = 0; \/\/ \u5f53\u524d\u8bfb\u53d6\u7684\u7d22\u5f15\n\n        public MainWindow() {\n            InitializeComponent();\n\n            _random = new Random();\n            _lineDataX = new double&#91;DataSize];\n            _lineDataY = new double&#91;DataSize];\n            _histogramData = new double&#91;DataSize]; \/\/ \u76f4\u65b9\u56fe\u6570\u636e\u957f\u5ea6\uff0c\u4fee\u6539\u4e3a\u4e0e\u6570\u636e\u70b9\u6570\u76f8\u540c\n            _histogramX = new double&#91;DataSize]; \/\/ \u76f4\u65b9\u56fe\u7684 X \u8f74\u6570\u636e\n\n            \/\/ \u4fdd\u5b58\u6570\u636e\u7684\u6587\u4ef6\u8def\u5f84\n            _dataFilePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), \"data.csv\");\n\n            \/\/ \u751f\u6210\u6240\u6709\u6570\u636e\u5e76\u4fdd\u5b58\u5230\u672c\u5730\n            GenerateAndSaveData();\n\n            \/\/ \u521d\u59cb\u5316\u6298\u7ebf\u56fe\u548c\u76f4\u65b9\u56fe\n            InitializePlots();\n\n            \/\/ \u8bbe\u7f6e\u5b9a\u65f6\u5668\uff0c\u6bcf\u9694\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u66f4\u65b0\u56fe\u5f62\n            _timer = new Timer(UpdateInterval);\n            _timer.Elapsed += UpdatePlots;\n            _timer.Start();\n        }\n\n        \/\/ \u751f\u6210\u6570\u636e\u5e76\u4fdd\u5b58\u5230\u6587\u4ef6\n        private void GenerateAndSaveData() {\n            using (var writer = new StreamWriter(_dataFilePath)) {\n                for (int i = 0; i &lt; DataSize; i++) {\n                    _lineDataX&#91;i] = i * XInterval; \/\/ \u589e\u52a0 X \u503c\u4e4b\u95f4\u7684\u95f4\u9694\n\n                    \/\/ \u751f\u6210 Y \u503c\uff0c\u4f7f\u7528\u6b63\u5f26\u51fd\u6570\uff0c\u5e76\u6dfb\u52a0\u968f\u673a\u566a\u58f0\n                    double noise = _random.NextDouble() * NoiseRange - (NoiseRange \/ 2); \/\/ \u968f\u673a\u566a\u58f0\u8303\u56f4\n                    _lineDataY&#91;i] = YAmplitude * Math.Sin(_lineDataX&#91;i]) + noise; \/\/ Y \u503c\u53d8\u5316\u5e45\u5ea6\u51cf\u5c0f\n\n                    \/\/ \u4fdd\u5b58\u6570\u636e\u5230\u6587\u4ef6\n                    writer.WriteLine($\"{_lineDataX&#91;i]},{_lineDataY&#91;i]}\");\n                }\n            }\n        }\n\n        \/\/ \u521d\u59cb\u5316\u6298\u7ebf\u56fe\u548c\u76f4\u65b9\u56fe\n        private void InitializePlots() {\n            linePlot.Plot.Axes.SetLimitsX(0, VisibleRange); \/\/ X \u8f74\u8303\u56f4\n            linePlot.Plot.Axes.SetLimitsY(0, 1.2); \/\/ Y \u8f74\u8303\u56f4\n            histogramPlot.Plot.Axes.SetLimitsX(0, VisibleRange); \/\/ \u76f4\u65b9\u56fe X \u8f74\u8303\u56f4\n            histogramPlot.Plot.Axes.SetLimitsY(0, 1.2); \/\/ \u76f4\u65b9\u56fe Y \u8f74\u8303\u56f4\n            linePlot.Refresh();\n            histogramPlot.Refresh();\n        }\n\n        \/\/ \u66f4\u65b0\u56fe\u5f62\n        private void UpdatePlots(object sender, ElapsedEventArgs e) {\n            \/\/ \u68c0\u67e5\u662f\u5426\u8bfb\u53d6\u5b8c\u6240\u6709\u6570\u636e\n            if (_currentIndex >= DataSize) {\n                _timer.Stop();\n                return;\n            }\n\n            \/\/ \u9010\u6e10\u8bfb\u53d6\u5e76\u66f4\u65b0\u6298\u7ebf\u56fe\n            ReadData();\n            Dispatcher.Invoke(() => {\n                RefreshLinePlot();\n                RefreshHistogramPlot();\n                UpdateAxisLimits(); \/\/ \u66f4\u65b0\u5750\u6807\u8f74\u9650\u5236\n            });\n        }\n\n        \/\/ \u9010\u6b65\u8bfb\u53d6\u6570\u636e\n        private void ReadData() {\n            \/\/ \u9010\u6b65\u8bfb\u53d6\u6570\u636e\n            int endIndex = Math.Min(_currentIndex + BatchSize, DataSize);\n\n            for (int i = _currentIndex; i &lt; endIndex; i++) {\n                _lineDataX&#91;i] = i * XInterval; \/\/ \u5047\u8bbe\u6bcf\u4e2a\u70b9\u95f4\u9694\u4e3a XInterval\n                _lineDataY&#91;i] = _random.NextDouble(); \/\/ \u968f\u673a\u751f\u6210 Y \u503c\n            }\n\n            _currentIndex = endIndex; \/\/ \u66f4\u65b0\u5f53\u524d\u7d22\u5f15\n        }\n\n        \/\/ \u5237\u65b0\u6298\u7ebf\u56fe\n        private void RefreshLinePlot() {\n            linePlot.Plot.Clear();\n            linePlot.Plot.Add.Scatter(_lineDataX.Take(_currentIndex).ToArray(), _lineDataY.Take(_currentIndex).ToArray());\n            linePlot.Refresh();\n        }\n\n        \/\/ \u5237\u65b0\u76f4\u65b9\u56fe\n        private void RefreshHistogramPlot() {\n            histogramPlot.Plot.Clear();\n\n            \/\/ \u4f7f\u7528\u5df2\u8bfb\u53d6\u7684\u6240\u6709\u6570\u636e\u6765\u7ed8\u5236\u76f4\u65b9\u56fe\uff0c\u800c\u4e0d\u662f\u53ea\u7ed8\u5236\u6700\u8fd1\u7684 BatchSize \u4e2a\u70b9\n            int barCount = _currentIndex; \/\/ \u76f4\u65b9\u56fe\u7684\u6761\u6570\u4e3a\u5f53\u524d\u8bfb\u53d6\u7684\u6240\u6709\u70b9\n            double&#91;] sampledHistogramX = new double&#91;barCount]; \/\/ \u6bcf\u4e2a\u70b9\u5bf9\u5e94\u4e00\u4e2a\u77e9\u5f62\n            double&#91;] sampledHistogramData = new double&#91;barCount];\n\n            \/\/ \u586b\u5145\u76f4\u65b9\u56fe\u6570\u636e\n            for (int i = 0; i &lt; barCount; i++) {\n                sampledHistogramX&#91;i] = _lineDataX&#91;i]; \/\/ \u5bf9\u5e94\u7684 X \u503c\n                sampledHistogramData&#91;i] = _lineDataY&#91;i]; \/\/ \u5bf9\u5e94\u7684 Y \u503c\n            }\n\n            \/\/ \u6dfb\u52a0\u77e9\u5f62\u5230\u56fe\u8868\u4e2d\n            histogramPlot.Plot.Add.Bars(sampledHistogramX, sampledHistogramData); \/\/ \u77e9\u5f62\u5bbd\u5ea6\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8c03\u6574\n\n            \/\/ \u66f4\u65b0\u5750\u6807\u8f74\u8303\u56f4\n            UpdateHistogramAxisLimits(sampledHistogramData);\n\n            histogramPlot.Refresh();\n        }\n\n\n\n        \/\/ \u66f4\u65b0\u5750\u6807\u8f74\u9650\u5236\n        private void UpdateAxisLimits() {\n            if (_currentIndex > 0) {\n                \/\/ \u8ba1\u7b97\u5f53\u524dX\u8f74\u7684\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\n                double minX = _lineDataX&#91;Math.Max(0, _currentIndex - (int)VisibleRange)];\n                double maxX = _lineDataX&#91;_currentIndex - 1];\n\n                \/\/ \u66f4\u65b0 X \u8f74\u8303\u56f4\n                linePlot.Plot.Axes.SetLimitsX(minX, maxX);\n                histogramPlot.Plot.Axes.SetLimitsX(minX, maxX); \/\/ \u66f4\u65b0\u76f4\u65b9\u56fe X \u8f74\u8303\u56f4\n            }\n        }\n\n        \/\/ \u66f4\u65b0\u76f4\u65b9\u56fe\u7684Y\u8f74\u9650\u5236\n        private void UpdateHistogramAxisLimits(double&#91;] sampledHistogramData) {\n            if (sampledHistogramData.Length > 0) {\n                \/\/ \u66f4\u65b0Y\u8f74\u8303\u56f4\n                double maxY = sampledHistogramData.Max();\n                histogramPlot.Plot.Axes.SetLimitsY(0, maxY * 1.1); \/\/ \u7ed9 Y \u8f74\u7559\u4e00\u70b9\u7a7a\u95f4\n            }\n        }\n    }\n\n    \/\/ \u968f\u673a\u6570\u6269\u5c55\u65b9\u6cd5\n    public static class RandomExtensions {\n        public static double&#91;] NextDoubles(this Random rand, int count) {\n            return Enumerable.Range(0, count).Select(_ => rand.NextDouble()).ToArray();\n        }\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u76f8\u5173\u4ecb\u7ecd \u5feb\u901f\u5165\u95e8 &#038;#8211&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2405","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=2405"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2405\/revisions"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=2405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=2405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=2405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}