Click here to Skip to main content
14,733,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Master,

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:

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

Thanks for your help



What I have tried:

<pre lang="C#">   // Set the titles and axis labels
            GraphPane myPane = ZedGraphControl1.GraphPane;

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

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

            myPane.YAxis.Title.Text = &quot;Temperature (Celcius)&quot;;
            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(&quot;Temperature&quot;, list, Color.Red, SymbolType.None);

            //Scale the axis

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 &lt; NoOfCurves; j++)
                PointPairList tempppl = new PointPairList();

                for (double x = 0; x &lt; Samples; x++)
                    tempppl.Add(x, -1);



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

            // Tell ZedGraph to refigure the
            // axes since the data have changed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900