Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12878
  • Last Modified:

C# and ZedGraph with time and date in X axis.

How to put the current date and time on the x-axis of the ZedGraph?
How to make the graph plot lines for 10 minutes and stop?

// GraphPane SETTINGS
            GraphPane myPane02m = zed2mm.GraphPane;

            timer1.Enabled = false;

            //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;

            // Y AXIS SETTINGS
            myPane02m.YAxis.Title.Text = "Particles";                       // Setta como Legenda (Particles) no Eixo Y
            myPane02m.YAxis.MajorGrid.IsVisible = true;                     // Setta Linhas no Eixo Y ou seja na Horizontal.
            myPane02m.YAxis.MajorGrid.DashOff = 5;                          // Seta a Intensidade da Linha no Eixo Y.

            // X AXIS SETTINGS

            myPane02m.XAxis.MajorGrid.DashOff = 5;                          // Seta a Intensidade da Linha no Eixo X.
            myPane02m.XAxis.MajorGrid.IsVisible = true;                     // Setta Linhas no Eixo X ou seja na Vertical.
            myPane02m.XAxis.MajorTic.IsOpposite = false;
            myPane02m.XAxis.MinorTic.IsAllTics = false; // mudei aqui para ver se para de pular o grafico.

            myPane02m.XAxis.Scale.FontSpec.Angle = 90;                      // Setta o Angulo do Scale do Eixo X.
            myPane02m.XAxis.Scale.FontSpec.Family = "Arial, Narrow";          // Setta a Fonte da Scale no Eixo X.
            myPane02m.XAxis.Scale.FontSpec.FontColor = Color.Fuchsia;       // Setta a Cor da Legenda do Dado que Entrara no Eixo X.
            myPane02m.XAxis.Scale.FontSpec.IsBold = true;                   // Setta Negrito na Scale no Eixo X.
            myPane02m.XAxis.Scale.FontSpec.Size = 10;                       // Setta o Tamanho da Fonte da Scale no Eixo X.
            myPane02m.XAxis.Scale.Format = "HH:mm:ss\nyy/MM/dd";            // Setta o formato de data e hora e o \n faz uma mudança de linha.
            myPane02m.XAxis.Scale.IsSkipCrossLabel = true;
            myPane02m.XAxis.Scale.IsPreventLabelOverlap = true;

            // Set the initial viewed range
            myPane02m.XAxis.Scale.Min = new XDate(DateTime.Now);            // We want to use time from now
            myPane02m.XAxis.Scale.Max = new XDate(DateTime.Now.AddMinutes(1));        // 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;                            // Setta os tracinhos da reta.
            myPane02m.XAxis.Scale.MajorStep = 10;                            // Setta o intervalo do tempo na Scale X.
            //myPane02m.XAxis.Scale.MinGrace = 1;
            //myPane02m.XAxis.Scale.MaxGrace = 10;

            myPane02m.XAxis.Title.FontSpec.FontColor = Color.DarkViolet;    // Setta a Cor do Titulo no Eixo X.
            myPane02m.XAxis.Title.Text = "Date & Time";                     // Setta a Legenda Date & Time no Eixo X.

            myPane02m.XAxis.Type = AxisType.Date;                             // Setta o Tipo do Eixo X como Data.
            myPane02m.Legend.Position = ZedGraph.LegendPos.TopCenter;
            //myPane02m.Legend.Location.AlignH = AlignH.Right;
            //myPane02m.Legend.Location.AlignV = AlignV.Top;

Open in new window

0
ocaccy
Asked:
ocaccy
  • 14
  • 14
1 Solution
 
Chuck YetterCommented:
I wouldn't recomment putting the date and time at every tick along the x axis, that would be too much text.  Since the graph will only contain 10 minutes of data, just put the date and start time in the XAxis.Title.Text and then put the minutes only on the XAxis.

As far as stopping the graph at 10 minutes, I think your application needs to handle that in the method that adds the points to the curve.
0
 
ocaccyAuthor Commented:
Thank you for your replies.

What should change in the lines below to obtain a graph with 10 minutes?
I really need to fix this, I tried a lot on the net, but unfortunately did not find this information.
However, the ZedGraph is a powerful tool and just not know the way.


myPane02m.XAxis.Scale.Min = new XDate(DateTime.Now);
myPane02m.XAxis.Scale.Max = new XDate(DateTime.Now.AddMinutes(1));
myPane02m.XAxis.Scale.MinorUnit = DateUnit.Second;
myPane02m.XAxis.Scale.MajorUnit = DateUnit.Minute;
myPane02m.XAxis.Scale.MinorStep = 1;
myPane02m.XAxis.Scale.MajorStep = 10;
//myPane02m.XAxis.Scale.MinGrace = 1;
//myPane02m.XAxis.Scale.MaxGrace = 10;

Open in new window

0
 
Chuck YetterCommented:
myPane02m.XAxis.Scale.Max = new XDate(DateTime.Now.AddMinutes(10));

That will create a 10 minute page size on the x axis.  If you only want to show a 1 minute page size you will need to scroll the graph.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ocaccyAuthor Commented:
How do to scroll the graph?

How to setup the legend on Top Right?

Axshun, do you have a model running.

My line chart has problem in the scroll.

Best Regards,
ocaccy
0
 
Chuck YetterCommented:
To show the horizontal scrollbar, set the IsShowHScrollBar property of your ZedGraphControl object (I don't see it's name in your code):
yourZedGraphControlName.IsShowHScrollBar = true.

To set the legend position, I think you want to use:
myPane02m.Legend.Position = LegendPos.InsideTopRight;
0
 
ocaccyAuthor Commented:
I can not use inside.
I need the top right.
Not have otherwise?

best Regards,
ocaccy
0
 
Chuck YetterCommented:
Try using

myPane02m.Legend.Position = LegendPos.Float;

then set the myPane02m.Legend.Location property.

Legend.Location only works when Legend.Position = LegendPos.Float.
0
 
ocaccyAuthor Commented:
How do like this video?
However the X axis by placing the 10 minutes.

http://www.youtube.com/watch?v=XXjbu2v1AMU
0
 
Chuck YetterCommented:
To get the graph to "auto-scroll" like the one in the video you need to change myPane02m.XAxis.Scale.Min and .Max when each new point of data is added to the curve, but only when a data point is beyond the original .Max.
0
 
ocaccyAuthor Commented:
Axshun, thank you.

I text and come back .

Best regards,
ocaccy
0
 
ocaccyAuthor Commented:
It's not working, you have a working model or example?
It may be that I am changing properties.
How to show only the time in the X axis and not be shown any more in the X axis.

Best Regards,
ocaccy
0
 
Chuck YetterCommented:
The project in which I have used ZedGraph is too complex to post any meaningful code here.  Maybe you could post your code along with more specific questions/problems?
0
 
ocaccyAuthor Commented:
Ok, Axshun.

myPane02m.YAxis.Title.Text = "Particles";  
myPane02m.XAxis.Title.Text = "Date & Time";
How to bring up only the values ¿¿in X and Y axes.
Does not appear XAxis.Title and YAxis.Title and not apperasl X axis and Y axis?

Thank you,
ocaccy
0
 
Chuck YetterCommented:
Ok, I built a quick form application using your code and I see you need

zed2mm.Invalidate();

after your other code in order to update the graph changes.
0
 
Chuck YetterCommented:
After trying your code I also see you have the MajorStep and MinorStep values set too high.  They should be something like:

myPane02m.XAxis.Scale.MinorStep = .1;            myPane02m.XAxis.Scale.MajorStep = 1.0;
0
 
Chuck YetterCommented:
To get the legend put in the upper right I used the code below.
This will only show a legend if you have added at least one curve to your graph pane.
myPane02m.AddCurve("test curve", new ZedGraph.PointPairList(), Color.Red);
myPane02m.Legend.IsVisible = true;
myPane02m.Legend.Position = LegendPos.Float;
myPane02m.Legend.Location = new Location(0.8, 0.0, CoordType.PaneFraction);

Open in new window

0
 
ocaccyAuthor Commented:
OK Axshun,
His information about positioning.
Positioning solved!
See the picture.
The contents of this rectangle appears on two lines.
How to enlarge the rectangle so that it is the content in just one (line) row?
I tried that, but the subscript appears in red.
Zedgraph-capturado.JPG
0
 
Chuck YetterCommented:
I couldn't find a way to resize the legend other than setting its font size like:

myPane02m.Legend.FontSpec.Size = 7;

Size 7 will put them all on one line.
ZedGraph.JPG
0
 
ocaccyAuthor Commented:
I did that too.
As was very small, I am looking for a solution.
It seems to me that this related to the myPane .... Float.
But I learned a lot from you, and my graphics are better.
Thank you.
I'll finish it for scoring.
I'll ask another question to this problem.

Best Regards,
ocaccy
0
 
ocaccyAuthor Commented:
I learned a lot, and my graphics are better.
ocaccy
0
 
Chuck YetterCommented:
The only other way I could get a single line legend was to use LegendPos.TopCenter.
0
 
ocaccyAuthor Commented:
I did that too.
However, the customer wants right-aligned in a row and with font size 14.
If don`t have a solution within the library ZefGraph; do a backgroud.
0
 
Chuck YetterCommented:
You would need to modify ZedGraph's LegendPos enum to add TopFlushRight, and then modify the graph pane Paint() method to work with that.
0
 
ocaccyAuthor Commented:
Wow, this was very good.
But you said ZedGraph and not myPane, which way?
0
 
Chuck YetterCommented:
You would have to modifiy ZedGraph source files and rebuild their dll file.
0
 
ocaccyAuthor Commented:
I'll try it then.
I will take a while.
It is best to ask another question or we can continue this same?
0
 
Chuck YetterCommented:
Probably best to ask a new question when you have one.
0
 
ocaccyAuthor Commented:
Thank you Axshun.

Best Regards,
ocaccy
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 14
  • 14
Tackle projects and never again get stuck behind a technical roadblock.
Join Now