滚动不适用于 ZedGraph

发布于 2024-12-08 03:20:30 字数 4436 浏览 0 评论 0原文

我在 ZedGraph 中有一个折线图。 每秒都有数据从串行端口传来。 图表正在运行。 但不在X轴上滚动(滚动)并且在左角被压缩。 我需要图表从右向左滚动并且日期和时间出现在 X 轴上

 #region 2 mm zed2mm
            GraphPane myPane02m=zed2mm.GraphPane;
            myPane02m.Fill.Color=System.Drawing.Color.GhostWhite;
            myPane02m.Title.Text="Particle Counter: 2μm";
            myPane02m.YAxis.Title.Text="Particles";

            // X AXIS SETTINGS

            myPane02m.XAxis.Title.Text="Date & Time";
            myPane02m.XAxis.Scale.FontSpec.Family="Arial, Narrow";
            myPane02m.XAxis.Scale.FontSpec.Size=14;
            myPane02m.XAxis.Scale.FontSpec.IsBold = false;
            myPane02m.XAxis.MajorGrid.IsVisible = true;
            myPane02m.YAxis.MajorGrid.IsVisible = true;
            myPane02m.XAxis.MajorGrid.DashOff = 15;
            myPane02m.YAxis.MajorGrid.DashOff = 15;
            myPane02m.XAxis.Scale.IsPreventLabelOverlap = false;
            myPane02m.XAxis.Type=AxisType.Date;
            myPane02m.XAxis.Scale.Format = "HH:mm:ss\nyy/MM/dd";

            myPane02m.XAxis.Scale.Min = new XDate(DateTime.Now);       // We want to use time from now
            myPane02m.XAxis.Scale.Max = new XDate(DateTime.Now.AddMinutes(5));        // to 5 min per default
            myPane02m.XAxis.Scale.MinorUnit = DateUnit.Second;         // set the minimum x unit to time/seconds
            myPane02m.XAxis.Scale.MajorUnit = DateUnit.Minute;         // set the maximum x unit to time/minutes

            myPane02m.XAxis.Scale.MinorStep = 1;
            myPane02m.XAxis.Scale.MajorStep = 50;

            myPane02m.XAxis.MinorTic.IsAllTics = true;
            myPane02m.XAxis.MajorTic.IsOpposite = true;
            myPane02m.XAxis.Scale.IsSkipCrossLabel = false;

            //myPane02m.XAxis.Scale.MinGrace = 0;
            //myPane02m.XAxis.Scale.MaxGrace = 0;

            //myPane02m.XAxis.Scale.MinorUnit = DateUnit.Second;
            //myPane02m.XAxis.Scale.MajorUnit = DateUnit.Minute;

            //myPane02m.XAxis.Scale.Min = DateTime.Now.AddSeconds(-60).ToOADate();
            //myPane02m.XAxis.Scale.Max = DateTime.Now.ToOADate();


            // Save 6000 points. At 50 ms sample rate, this is one minute
            // The RollingPointPairList is an efficient storage class that always
            // keeps a rolling set of point data without needing to shift any data values
            RollingPointPairList lista02m_1=new RollingPointPairList(6000);
            RollingPointPairList lista02m_2=new RollingPointPairList(6000);
            RollingPointPairList lista02m_3=new RollingPointPairList(6000);
            RollingPointPairList lista02m_4=new RollingPointPairList(6000);
            RollingPointPairList lista02m_5=new RollingPointPairList(6000);
            RollingPointPairList lista02m_6=new RollingPointPairList(6000);

            // Initially, a curve is added with no data points (list is empty)
            // Color is blue, and there will be no symbols
            LineItem curve02m_1=myPane02m.AddCurve("ID 01",lista02m_1,Color.Red,SymbolType.Circle);
            curve02m_1.Line.IsSmooth=true;
            curve02m_1.Line.SmoothTension=0.3F;

            LineItem curve02m_2=myPane02m.AddCurve("ID_02",lista02m_2,Color.Blue,SymbolType.Diamond);
            curve02m_2.Line.IsSmooth=true;
            curve02m_2.Line.SmoothTension=0.3F;

            LineItem curve02m_3=myPane02m.AddCurve("ID_03",lista02m_3,Color.Black,SymbolType.Plus);
            curve02m_3.Line.IsSmooth=true;
            curve02m_3.Line.SmoothTension=0.3F;

            LineItem curve02m_4=myPane02m.AddCurve("ID_04",lista02m_4,Color.BurlyWood,SymbolType.Star);
            curve02m_4.Line.IsSmooth=true;
            curve02m_4.Line.SmoothTension=0.3F;

            LineItem curve02m_5=myPane02m.AddCurve("ID_05",lista02m_5,Color.Chartreuse,SymbolType.TriangleDown);
            curve02m_5.Line.IsSmooth=true;
            curve02m_5.Line.SmoothTension=0.3F;

            LineItem curve02m_6=myPane02m.AddCurve("ID_06",lista02m_6,Color.Coral,SymbolType.Square);
            curve02m_6.Line.IsSmooth=true;
            curve02m_6.Line.SmoothTension=0.3F;
            // Sample at 50ms intervals

            // Scale the axes
            zed2mm.AxisChange();

            // Redraw the axes
            zed2mm.Invalidate();

            // Save the beginning time for reference
            TickStart=Environment.TickCount;
            #endregion

I have a line chart in ZedGraph.
The data is coming from serial port every second.
The chart is running.
But do not roll (scroll) on the X axis and is compressed in the left corner.
I need the chart scroll from right to left and the date and time appear in the X axis

 #region 2 mm zed2mm
            GraphPane myPane02m=zed2mm.GraphPane;
            myPane02m.Fill.Color=System.Drawing.Color.GhostWhite;
            myPane02m.Title.Text="Particle Counter: 2μm";
            myPane02m.YAxis.Title.Text="Particles";

            // X AXIS SETTINGS

            myPane02m.XAxis.Title.Text="Date & Time";
            myPane02m.XAxis.Scale.FontSpec.Family="Arial, Narrow";
            myPane02m.XAxis.Scale.FontSpec.Size=14;
            myPane02m.XAxis.Scale.FontSpec.IsBold = false;
            myPane02m.XAxis.MajorGrid.IsVisible = true;
            myPane02m.YAxis.MajorGrid.IsVisible = true;
            myPane02m.XAxis.MajorGrid.DashOff = 15;
            myPane02m.YAxis.MajorGrid.DashOff = 15;
            myPane02m.XAxis.Scale.IsPreventLabelOverlap = false;
            myPane02m.XAxis.Type=AxisType.Date;
            myPane02m.XAxis.Scale.Format = "HH:mm:ss\nyy/MM/dd";

            myPane02m.XAxis.Scale.Min = new XDate(DateTime.Now);       // We want to use time from now
            myPane02m.XAxis.Scale.Max = new XDate(DateTime.Now.AddMinutes(5));        // to 5 min per default
            myPane02m.XAxis.Scale.MinorUnit = DateUnit.Second;         // set the minimum x unit to time/seconds
            myPane02m.XAxis.Scale.MajorUnit = DateUnit.Minute;         // set the maximum x unit to time/minutes

            myPane02m.XAxis.Scale.MinorStep = 1;
            myPane02m.XAxis.Scale.MajorStep = 50;

            myPane02m.XAxis.MinorTic.IsAllTics = true;
            myPane02m.XAxis.MajorTic.IsOpposite = true;
            myPane02m.XAxis.Scale.IsSkipCrossLabel = false;

            //myPane02m.XAxis.Scale.MinGrace = 0;
            //myPane02m.XAxis.Scale.MaxGrace = 0;

            //myPane02m.XAxis.Scale.MinorUnit = DateUnit.Second;
            //myPane02m.XAxis.Scale.MajorUnit = DateUnit.Minute;

            //myPane02m.XAxis.Scale.Min = DateTime.Now.AddSeconds(-60).ToOADate();
            //myPane02m.XAxis.Scale.Max = DateTime.Now.ToOADate();


            // Save 6000 points. At 50 ms sample rate, this is one minute
            // The RollingPointPairList is an efficient storage class that always
            // keeps a rolling set of point data without needing to shift any data values
            RollingPointPairList lista02m_1=new RollingPointPairList(6000);
            RollingPointPairList lista02m_2=new RollingPointPairList(6000);
            RollingPointPairList lista02m_3=new RollingPointPairList(6000);
            RollingPointPairList lista02m_4=new RollingPointPairList(6000);
            RollingPointPairList lista02m_5=new RollingPointPairList(6000);
            RollingPointPairList lista02m_6=new RollingPointPairList(6000);

            // Initially, a curve is added with no data points (list is empty)
            // Color is blue, and there will be no symbols
            LineItem curve02m_1=myPane02m.AddCurve("ID 01",lista02m_1,Color.Red,SymbolType.Circle);
            curve02m_1.Line.IsSmooth=true;
            curve02m_1.Line.SmoothTension=0.3F;

            LineItem curve02m_2=myPane02m.AddCurve("ID_02",lista02m_2,Color.Blue,SymbolType.Diamond);
            curve02m_2.Line.IsSmooth=true;
            curve02m_2.Line.SmoothTension=0.3F;

            LineItem curve02m_3=myPane02m.AddCurve("ID_03",lista02m_3,Color.Black,SymbolType.Plus);
            curve02m_3.Line.IsSmooth=true;
            curve02m_3.Line.SmoothTension=0.3F;

            LineItem curve02m_4=myPane02m.AddCurve("ID_04",lista02m_4,Color.BurlyWood,SymbolType.Star);
            curve02m_4.Line.IsSmooth=true;
            curve02m_4.Line.SmoothTension=0.3F;

            LineItem curve02m_5=myPane02m.AddCurve("ID_05",lista02m_5,Color.Chartreuse,SymbolType.TriangleDown);
            curve02m_5.Line.IsSmooth=true;
            curve02m_5.Line.SmoothTension=0.3F;

            LineItem curve02m_6=myPane02m.AddCurve("ID_06",lista02m_6,Color.Coral,SymbolType.Square);
            curve02m_6.Line.IsSmooth=true;
            curve02m_6.Line.SmoothTension=0.3F;
            // Sample at 50ms intervals

            // Scale the axes
            zed2mm.AxisChange();

            // Redraw the axes
            zed2mm.Invalidate();

            // Save the beginning time for reference
            TickStart=Environment.TickCount;
            #endregion

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2024-12-15 03:20:30

尝试

zed2mm.IsShowHScrollBar = true;
zed2mm.IsAutoScrollRange = true;

了解更多信息,请参阅 IsAutoScrollRangePropertyIsShowHScrollBarProperty

编辑:
对于自动滚动,当新数据进入时(或者计时器到期),您必须手动滚动:

double xRange = myPane02m.XAxis.Scale.Max - myPane02m.XAxis.Scale.Min;
myPane02m.XAxis.Scale.Max = new XDate(DateTime.Now);
myPane02m.XAxis.Scale.Min = myPane02m.XAxis.Scale.Max - xRange;

Try

zed2mm.IsShowHScrollBar = true;
zed2mm.IsAutoScrollRange = true;

For more information see IsAutoScrollRangeProperty and IsShowHScrollBarProperty

EDIT:
For autoscrolling you have to scroll by hand when new data comes in (or your timer elapses):

double xRange = myPane02m.XAxis.Scale.Max - myPane02m.XAxis.Scale.Min;
myPane02m.XAxis.Scale.Max = new XDate(DateTime.Now);
myPane02m.XAxis.Scale.Min = myPane02m.XAxis.Scale.Max - xRange;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文