Plot zedgraph direction

495 views Asked by At

I trying make a zedgraph plotter system in C# in the temperature measurement system, and successfully to graph serial data. But the direction is not linear, it's mean the lower temperature not placed in the first time but in the end of time. This is my code:

private void initCurves()
    {
        PointPairList list1 = new PointPairList();
        PointPairList list2 = new PointPairList();
        PointPairList list3 = new PointPairList();

        Samples = 10000;
        NoOfCurves = 3;

        // Samples = int.Parse(XTextBox.Text);
        // NoOfCurves = (int)NoOfDataNumericUpDown.Value;

        for (int j = 0; j < NoOfCurves; j++)
        {
            PointPairList tempppl = new PointPairList();

            for (double x = 0; x < Samples; x++)
            {
                tempppl.Add(x, -1);
            }

            list1.Add(tempppl);
            list2.Add(tempppl);
            list3.Add(tempppl);

        }

        // Generate a red curve with diamond
        // symbols, and "Porsche" in the legend
        ZedGraphControl1.GraphPane.AddCurve("Thermocouple #1",list1, Color.Red, SymbolType.None);
        ZedGraphControl1.GraphPane.AddCurve("Thermocouple #2", list2, Color.Blue, SymbolType.None);
        ZedGraphControl1.GraphPane.AddCurve("Thermocouple #3", list3, Color.Brown, SymbolType.None);

        // Tell ZedGraph to refigure the
        // axes since the data have changed
        ZedGraphControl1.AxisChange();
    }


private void Form1_Load(object sender, EventArgs e) {


        //Array of baud rates
        string[] baudrates = {"75", "110", "134", "150", "300", "600", "1200", "1800",
                             "2400", "4800", "7200", "9600", "14400", "19200", "38400",
                             "57600", "115200", "128000"};


        //Set data source for baud rate combobox
        COMBaudComboBox.DataSource = baudrates;


        // Set the titles and axis labels
        GraphPane myPane = ZedGraphControl1.GraphPane;

        //Set title axis labels and font color
        myPane.Title.Text = "Temperature vs. Time";
        myPane.Title.FontSpec.FontColor = Color.Black;

        myPane.XAxis.Title.Text = "Time (Sec)";
        myPane.XAxis.Title.FontSpec.FontColor = Color.Black;

        myPane.YAxis.Title.Text = "Temperature (Celcius)";
        myPane.YAxis.Title.FontSpec.FontColor = Color.Black;

        //Fill the chart background with a color gradient
        myPane.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F);
        myPane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F);

        myPane.XAxis.Scale.FontSpec.IsAntiAlias = true;
        myPane.YAxis.Scale.FontSpec.IsAntiAlias = true; 

        //Add grid lines to the plot and make them gray
        myPane.XAxis.MajorGrid.IsVisible = true;
        myPane.XAxis.MajorGrid.Color = Color.LightGray;

        myPane.YAxis.MajorGrid.IsVisible = true;
        myPane.YAxis.MajorGrid.Color = Color.LightGray;

        //Enable point value tooltips and handle point value event
        ZedGraphControl1.IsShowPointValues = true;
       ZedGraphControl1.PointValueEvent += new ZedGraphControl.PointValueHandler(PointValueHandler);

        //Show the horizontal scroll bar
        ZedGraphControl1.IsShowHScrollBar = true;

        //Automatically set the scrollable range to cover the data range from the curves
        ZedGraphControl1.IsAutoScrollRange = true;

        //Add 10% to scale range
        ZedGraphControl1.ScrollGrace = 0.1;

        //Horizontal pan and zoom allowed
        ZedGraphControl1.IsEnableHPan = true;
        ZedGraphControl1.IsEnableHZoom = true;

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

        //Set the initial viewed range
       // ZedGraphControl1.GraphPane.XAxis.Scale.MinAuto = true;
       // ZedGraphControl1.GraphPane.XAxis.Scale.MaxAuto = true;


        //Let Y-Axis range adjust to data range
        ZedGraphControl1.GraphPane.IsBoundedRanges = true;

        //Set the margins to 10 points
        myPane.Margin.All = 10;

        //Hide the legend
        // myPane.Legend.IsVisible = false;

        //Set start point for XAxis scale
        myPane.XAxis.Scale.BaseTic = 0;

        //Set start point for YAxis scale
        myPane.YAxis.Scale.BaseTic = 0;

        //Set max/min XAxis range
        myPane.XAxis.Scale.Min = 0.0;
       // myPane.XAxis.Scale.Max = 7200;
        myPane.XAxis.Scale.MinorStep = 5;
        myPane.XAxis.Scale.MajorStep = 10;


        //Set max/min YAxis range
        myPane.YAxis.Scale.Min = 0;
        myPane.YAxis.Scale.Max = 400;
        myPane.YAxis.Scale.MinorStep = 5;
        myPane.YAxis.Scale.MajorStep = 10;
        RollingPointPairList list = new RollingPointPairList(7400);

        //Initially, a curve is added with no data points (list is empty)
        //Color is red, and there will be no symbols
        //LineItem curve = myPane.AddCurve("Temperature", list, Color.Red, SymbolType.None);

        //Scale the axis
       myPane.AxisChange();

        // Set defaults for UI

        SpeedNumericUpDown.Value = Properties.Settings.Default.SpeedSetting;
        NoOfDataNumericUpDown.Value = Properties.Settings.Default.DataSetsSetting;
        XTextBox.Text = Properties.Settings.Default.XScaleSetting;
        YTextBox.Text = Properties.Settings.Default.YScaleSetting;
        SeriesLineSizeNumericUpDown.Value = Properties.Settings.Default.LineSizeSetting;

        // Fill COMPortComboBox with available COM ports
        string[] aosPorts = SerialPort.GetPortNames();
        bool foundCOMPortFlag = false;
        COMPortComboBox.DataSource = aosPorts;
        foreach (string port in aosPorts) {
            if (port == Properties.Settings.Default.COMPortSetting) {
                COMPortComboBox.Text = port;
                foundCOMPortFlag = true;
            }
        }

        // We didn't find the COM port, so set to COM1
        if (foundCOMPortFlag == false) {
            COMPortComboBox.SelectedIndex = 0;
        }
    }

can I change the plot graph direction to be linear? how I can do that?

Thanks for your help

regards

Nanang

The Picture of Result Plot graph and wish plot graph

0

There are 0 answers