ZedGraph Scroll Event [英] ZedGraph Scroll Event

查看:80
本文介绍了ZedGraph Scroll Event的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个项目中,我在一个Window窗体中有两个Zedgraph。我在图表中加载数据,对于zedGraph,使AutoScroll为True。

如果我向左或向右移动第一个图形的水平滚动条,然后第一个图形正在移动拳头水平滚动条移动。现在我想在第一个图形滚动条移动的第二个图形上产生相同的效果。我的项目的代码是下面:



In One of my Project,I have two Zedgraph in the one Window Form.I am loading data in the Graph,for both zedGraph ,Making AutoScroll is True.
if i move Left or Right the Horizontal scrollBar of the First Graph,then the Graph of the First is moving on the move of Fist Horizontal ScrollBar move.Now i want to develop same effect on the Second Graph on the Move of First Graph Scrollbar move.Code of my Project is Below:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using System.IO;

namespace MyTestGraph
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            CreateGraph_Test(zedGraphControl_Left, zedGraphControl_Right);
            SetSize();          
            
        }

        public void CreateChart(ZedGraphControl zgc)
        {
            GraphPane myPane = zgc.GraphPane;

            // Set the titles and axis labels
            myPane.Title.Text = "My Test Graph \n Wind Management";
            myPane.XAxis.Title.Text = "Time (hour)";
            myPane.YAxis.Title.Text = "Wind Speed (m/s)";
            myPane.Y2Axis.Title.Text = "Temparature (ºC)";

            PointPairList vList = new PointPairList();
            vList = ListWindSpeed();
            PointPairList aList = new PointPairList();
            aList = ListTemparature();

            LineItem myCurve = myPane.AddCurve("Velocity", vList, Color.Green, SymbolType.Star);
            myCurve.Symbol.Fill = new Fill(Color.White);

            myCurve = myPane.AddCurve("Acceleration", aList, Color.Blue, SymbolType.Circle);
            myCurve.Symbol.Fill = new Fill(Color.White);

            myCurve.IsY2Axis = true;
            myCurve.Symbol.Fill = new Fill(Color.White);
            myCurve.YAxisIndex = 1;
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;
            // Associate this curve with the second Y2 axis
            myCurve.YAxisIndex = 1;

            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;

            // Setting Color
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Green;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Green;
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue;

            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            myPane.YAxis.Scale.Max = 100;

            // Enable the Y2 axis display
            myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale blue

            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = true;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;
            //myPane.Y2Axis.Scale.Min = 1.5;
            myPane.Y2Axis.Scale.Max = 100;

            myPane.Chart.Fill = new Fill(Color.White, Color.WhiteSmoke, 45.0f);

            zgc.AxisChange();
        }

        public void CreateChart1(ZedGraphControl zgc1)
        {
            GraphPane myPane = zgc1.GraphPane;

            // Set the titles and axis labels
            myPane.Title.Text = "My Test Graph \n Wind Management";
            myPane.XAxis.Title.Text = "Time (hour)";
            myPane.YAxis.Title.Text = "Wind Speed (m/s)";
            myPane.Y2Axis.Title.Text = "Temparature (ºC)";

            PointPairList vList = new PointPairList();
            vList = ListWindSpeed();
            PointPairList aList = new PointPairList();
            aList = ListTemparature();

            LineItem myCurve = myPane.AddCurve("Velocity", vList, Color.Green, SymbolType.Star);
            myCurve.Symbol.Fill = new Fill(Color.White);

            myCurve = myPane.AddCurve("Acceleration", aList, Color.Blue, SymbolType.Circle);
            myCurve.Symbol.Fill = new Fill(Color.White);

            myCurve.IsY2Axis = true;
            myCurve.Symbol.Fill = new Fill(Color.White);
            myCurve.YAxisIndex = 1;
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;
            // Associate this curve with the second Y2 axis
            myCurve.YAxisIndex = 1;

            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;

            // Setting Color
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Green;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Green;
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue;

            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            myPane.YAxis.Scale.Max = 100;

            // Enable the Y2 axis display
            myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale blue

            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = true;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;
            //myPane.Y2Axis.Scale.Min = 1.5;
            myPane.Y2Axis.Scale.Max = 100;

            myPane.Chart.Fill = new Fill(Color.White, Color.WhiteSmoke, 45.0f);

            zgc1.AxisChange();
        }

        private void SetSize()
        {
            zedGraphControl_Left.Location = new Point(10, 10);

            zedGraphControl_Left.Size = new Size(ClientRectangle.Width - 20, ClientRectangle.Height - 20);


            zedGraphControl_Right.Location = new Point(10, 10);

            zedGraphControl_Right.Size = new Size(ClientRectangle.Width - 20, ClientRectangle.Height - 20);
        }


        private PointPairList ListWindSpeed()
        {
            PointPairList list = new PointPairList();
            string line;
            // Read the file and display it line by line.
            using (StreamReader file = new StreamReader("D:\\WindSpeed.txt"))
            {
                while ((line = file.ReadLine()) != null)
                {
                    string[] xy = line.Split('\t');
                    if (xy.Length == 2)
                    {
                        if (xy[0].ToString() != "X" && xy[1].ToString() != "Y")
                        {
                            double x = Convert.ToDouble(xy[0]);
                            double y = Convert.ToDouble(xy[1]);

                            list.Add(x, y);
                        }
                    }
                }

                file.Close();
            }
            return list;
        }

        private PointPairList ListTemparature()
        {
            PointPairList list = new PointPairList();
            string line;

            // Read the file and display it line by line.
            using (StreamReader file = new StreamReader("D:\\Temparature.txt"))
            {
                while ((line = file.ReadLine()) != null)
                {
                    string[] xy = line.Split('\t');
                    if (xy.Length == 2)
                    {
                        if (xy[0].ToString() != "X" && xy[1].ToString() != "Y")
                        {
                            double x = Convert.ToDouble(xy[0]);
                            double y = Convert.ToDouble(xy[1]);

                            list.Add(x, y);
                        }
                    }
                }
                file.Close();
            }
            return list;
        }

        private PointPairList ListForGraph2()
        {
            PointPairList list = new PointPairList();
            string line;

            // Read the file and display it line by line.
            using (StreamReader file = new StreamReader("D:\\Data2.txt"))
            {
                while ((line = file.ReadLine()) != null)
                {
                    string[] xy = line.Split('\t');
                    if (xy.Length == 2)
                    {
                        if (xy[0].ToString() != "X" && xy[1].ToString() != "Y")
                        {
                            double x = Convert.ToDouble(xy[0]);
                            double y = Convert.ToDouble(xy[1]);

                            list.Add(x, y);
                        }
                    }
                }

                file.Close();
            }
            return list;
        }

        private PointPairList ListForGraph3()
        {
            PointPairList list = new PointPairList();
            string line;

            // Read the file and display it line by line.
            using (StreamReader file = new StreamReader("D:\\Data3.txt"))
            {
                while ((line = file.ReadLine()) != null)
                {
                    string[] xy = line.Split('\t');
                    if (xy.Length == 2)
                    {
                        if (xy[0].ToString() != "X" && xy[1].ToString() != "Y")
                        {
                            double x = Convert.ToDouble(xy[0]);
                            double y = Convert.ToDouble(xy[1]);

                            list.Add(x, y);
                        }
                    }
                }

                file.Close();
            }
            return list;
        }

        private void CreateGraph_Test(ZedGraphControl zgc, ZedGraphControl zgc1)
        {
            // show the horizontal scroll bar
            zgc.IsShowHScrollBar = true;

            // automatically set the scrollable range to cover the data range from the curves
            zgc.IsAutoScrollRange = true;
            // Add 10% to scale range
            zgc.ScrollGrace = 0.1;

            // Horizontal pan and zoom allowed
            zgc.IsEnableHPan = false;
            zgc.IsEnableHZoom = false;

            // Vertical pan and zoom not allowed
            zgc.IsEnableVPan = false;
            zgc.IsEnableVZoom = false;

            // Set the initial viewed range
            zgc.GraphPane.XAxis.Scale.Min = 50.0;
            zgc.GraphPane.XAxis.Scale.Max = 250.0;

            //show the cursor Value
            zgc.IsShowCursorValues = true;
            
            ScrollSample_Setup(zgc);

            zgc1.IsShowHScrollBar = true;

            // automatically set the scrollable range to cover the data range from the curves
            zgc1.IsAutoScrollRange = true;
            // Add 10% to scale range
            zgc1.ScrollGrace = 0.1;

            // Horizontal pan and zoom allowed
            zgc1.IsEnableHPan = false;
            zgc1.IsEnableHZoom = false;

            // Vertical pan and zoom not allowed
            zgc1.IsEnableVPan = false;
            zgc1.IsEnableVZoom = false;

            //show the cursor Value
            zgc1.IsShowCursorValues = true;
            // Set the initial viewed range
            zgc1.GraphPane.XAxis.Scale.Min = 50.0;
            zgc1.GraphPane.XAxis.Scale.Max = 250.0;

            ScrollSample_Setup(zgc1);
        }

        private void ScrollSample_Setup(ZedGraphControl zgc)
        {
            // get a reference to the GraphPane
            GraphPane myPane = zgc.GraphPane;
            // Set the titles
            myPane.Title.Text = "Sample ScrollBar Graph";
            myPane.XAxis.Title.Text = "Index";
            myPane.XAxis.Title.Text = "Phased Sine Data";
            // Generate some sample sine data in PointPairList's
            PointPairList list = new PointPairList();
            PointPairList list2 = new PointPairList();
            PointPairList list3 = new PointPairList();
            for (int i = 0; i < 100; i++)
            {
                double x = (double)i * 5.0 + 25.0;
                double y = Math.Sin((double)i * Math.PI / 25.0) * 16.0;
                double y2 = Math.Sin((double)i * Math.PI / 25.0 + 30.0) * 12.0;
                double y3 = Math.Sin((double)i * Math.PI / 25.0 + 60.0) * 8.0;
                list.Add(x, y);
                list2.Add(x, y2);
                list3.Add(x, y3);
            }
            // create three curves from the above data sets
            LineItem myCurve = myPane.AddCurve("Alpha", list, Color.Red, SymbolType.Diamond);
            myCurve = myPane.AddCurve("Beta", list2, Color.Blue, SymbolType.Plus);
            myCurve = myPane.AddCurve("Sigma", list3, Color.Green, SymbolType.XCross);
            // scale the axes base on the data
            zgc.AxisChange();
        }

        private void zedGraphControl_Left_Scroll(object sender, ScrollEventArgs e)
        {

        }

        private void zedGraphControl_Left_ScrollDoneEvent(ZedGraphControl sender, ScrollBar scrollBar, ZoomState oldState, ZoomState newState)
        {
            //ScrollBar sc = (ScrollBar)zedGraphControl_Right.Controls[0];
            //sc.Value = scrollBar.Value;
            //zedGraphControl_Right_ScrollDoneEvent(sender, scrollBar, oldState, newState);
        }

        private void zedGraphControl_Left_ScrollEvent(object sender, ScrollEventArgs e)
        {
            ScrollBar sc = (ScrollBar)zedGraphControl_Right.Controls[0];
            sc.Value = e.NewValue;
        }

        private void zedGraphControl_Left_ScrollProgressEvent(ZedGraphControl sender, ScrollBar scrollBar, ZoomState oldState, ZoomState newState)
        {
           
        }


        private void zedGraphControl_Right_ScrollDoneEvent(ZedGraphControl sender, ScrollBar scrollBar, ZoomState oldState, ZoomState newState)
        {

        }

        private void zedGraphControl_Right_ScrollEvent(object sender, ScrollEventArgs e)
        {
            ScrollBar sc = (ScrollBar)zedGraphControl_Left.Controls[0];
            sc.Value = e.NewValue;
        }

    }
}



如果有人找到它的解决方案,请发邮件给我[电子邮件删除以避免垃圾邮件]


If any one find solution for it,Kindly Mail me [Email removed to avoid spam]

推荐答案

使用masterpane,

并在zedgraphcontrol中设置此值:



zedGraphcontrol.IsShowHScrollbar = true;

zedGraphcontrol.IsShowVScrollbar = true;
use masterpane,
and in zedgraphcontrol, set this value :

zedGraphcontrol.IsShowHScrollbar = true;
zedGraphcontrol.IsShowVScrollbar = true;


这篇关于ZedGraph Scroll Event的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆