Lock axis in ZedGraph - c#

I've used ZedGraph to plot data from several sources with a single click. I need the Y-axes to always have the same max and min-values for each plot. I need this to be able to see changes between datasets as I flip through them. In my case, it would not make sense to plot data from several sources in one graph.
I've tried to set axis properties like this:
myPane.Y2Axis.Scale.Max = 40;
myPane.Y2Axis.Scale.MaxAuto = false;
myPane.Y2Axis.Scale.Min = -40;
myPane.Y2Axis.Scale.MinAuto = false;
I still see the axes beeing auto scaled. Please give me a hint if this is possible or not. I probably only miss a small thing...
(by the way: I hope someone picks this project up, it's great!)

Well, solved like this:
zGC.AxisChange();
zGC.RestoreScale(myPane);
zGC.ZoomOut(myPane);
Added a ZoomOut(), since I realized that RestoreScale() actually always autozooms...
-rb

Is your intention to synchronize the scales of all panes that you use?
If so, have you seen this tutorial?
The second thing is that the Y2Axis is not visible by default. ZG uses by default first Y axis (YAxis). Have you enabled Y2Axis manually?

Related

Chart X Axis wrong labels

I have a chart and a datagridview, both of them are databound to a dictionary, for example:
freqChart.Series[0].Points.DataBindXY(symCount.Keys, symCount.Values);
And on the screenshot below you can see the difference in X-Axis label/key names. Datagridview shows it correctly, while chart flips char if it's punctuation char. What's the problem? How do I fix it?
Screenshot (Chart and DataGridView):
My comment was wrong; in fact this is a funny effect you get when you have a RightToLeft turned on.
There are several values but this one is enough to reproduce:
freqChart.RightToLeft = RightToLeft.Yes
Either this is what you want, then you can turn it on for the DGV as well; or it isn't then simply turn it off..
freqChart.RightToLeft = RightToLeft.No
As you can see it is a Control.Property so it will work on all controls. Also to be noted: The RightToLeft property is an ambient property, so it propagates to child controls.
Why it acts so strangly I can't say, though. The docs basically talk about alignment, not punctuation. If you are interested you may want to read up on it in wikipedia

How to add labels onto a form one under another?

I made this program and it worked until it didn't... I was adding labels with text onto a form and setting label.Location = new Point(0, yPos); and then doing yPos += labelHeight;
It didn't make sense to me why at first my labels were fine and then I saw huge gaps between then, turns out yPos overflowed, so I can't use this method, is there some sort of container I can use to add labels one after another without setting label location? Also my labels can be of any height and there can be a lot of them.
I was adding these labels as controls of TabPage.
You're ignoring the main problem which is that you are somehow overflowing the yPos value. So either your logic for setting the y position is flawed or you are displaying WAY too much data in one form. My large 32-inch monitor runs at a resolution of 2,500 X 1,600. The maximum value for int (and thus the maximum y value) is 2,147,483,647. Even a scrollable form that's over 1.3 Million "pages" of data at that resolution. If I could process one "screen" of data per second it would take me 373 hours (15.5 days) to consume all of the labels in that form.
So the problem is not which control to use - it how to reduce the amount of data in one form to a manageable amount. You need to look at filtering, searching, sorting, paging, etc. to get the amount of data to a manageable level. Otherwise it's write-only memory. You are displaying it but noe one is reasonably able to use it.
(Looking past the fact that you may be trying to add too many labels to begin with)
You might want to use TableLayoutPanel for adding multiple controls.
https://blogs.msdn.microsoft.com/jpricket/2006/04/05/winforms-autolayout-basics-tablelayoutpanel/
I believe this is a method you can run on something like that
Table.Controls.Add(new Label() { Text = "textHere", Anchor = ... etc};
That way you don't have to explicitly position everything within the panel, only the panel itself.
There are probably a few ways of doing what you're asking. A little bit of research on my part found that this method is generally the right way to go.
Unfortunately I am unable to test this at the moment, but it may put you on the right track.
Turns out when you add things to a form, that has AutoScroll set to true, you should always do:
this.AutoScrollPosition = new Point(0,0);
This worked, thanks to Hans Passant.

How can I properly format the Y axis labels on an ASP.NET chart?

I am trying to construct a chart using the native ASP.NET 4.0 charting control.
I've done nearly everything I wanted to do, but if you look at the following screenshot:
You'll notice that the Y axis labels are all wonky - that is, they are decimals, and they don't fall directly on any of the actual gridlines.
The purpose of my chart is to show a value that will always be between 0 and 16. I need to know the exact value, so I was able to set the gridlines to represent each value, by using this code:
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Interval = 1;
As you can see, it is showing all lines, 0 to 16. However, the Y axis labels not only do not line up, but aren't even whole values. I would like there to be a label for EACH gridline, and I'd like them to be whole values.
I've done my share of googling, but I mostly find stuff pertaining to turning off the gridlines altogether, which is not what I want.
Any ideas?
can you not just set AxisY.Interval?
chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Interval = 1;
chart1.ChartAreas["ChartArea1"].AxisY.Interval = 1;
I created a test chart quick and got the following:
When I set the interval, I only set the property for the Axis Interval property
chart1.ChartAreas["ChartArea1"].AxisY.Interval = 1;
The default behavior sets the major grid and major tick to this interval unless you have otherwise overridden a property that turns auto off for everything. Microsoft Charting aka Dundas charting (where Microsoft got the code) can be tricky this way.
While I cannot speak for every property within Microsoft Charting, it helps to set the most non-specific property you can find. Only go deeper if you do not get the desired result as going deeper can have unintended consequences by overriding the defaults which generally work quite well.
i.e.:
chart1.ChartAreas["ChartArea1"].AxisY.Interval = 1;
instead of
chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Interval = 1;

.NET Chart control - dynamically change y-axis interval

I have a bar graph displaying a number of different series (stacked on each other) and I'm trying to find a way to dynamically change the y-axis interval if the values go above a set value.
If the bars only go up to a maximum of 50, I'd like the interval to be 25 so the bars still 'look' rather small. But if a large spike comes through, the interval needs to be set to 0 so the large spike is more noticeable.
Oh, and this is in C# .NET 3.5
I hope that makes sense :)
Thanks in advance
This is pretty much feasible by tweaking both the size of the axis and the relative intervals dynamically by updating the right properties. Default control behavior is rescaling the axis to adapt to the dataset so this should be no problem (works well for me)
Take a look at the Axis Class MSDN Reference, especially the Interval and IntervalAutoMode Properties. (the MSDN in pretty exhaustive on chart control if you dig enough you'll find everything you might need).
besides I HEAVILY advice you to download the very complete sample application
and play around with it locally. It is pretty exhaustive and you'll have the complete source at hand.
Set IntervalAutoMode="Variable Count" and dint mention any axis interval in the Axis Y element of the chart Area of that chart,it will adjust according to the maximum value.

XNA/C# Game Settings (Menu?)

It's my first time trying to make anything really interesting in C# and I was trying to make a simple form or game screen where the user could define a custom resolution/screen ratio etc. or to automatically detect the max screen size/ratio and output? its my first game, so I was wondering if it was possible or if there would be any major issues with such, rather than just setting it to 1366x768 (the resolution of all of my computers).
Thanks in advance for any assistance.
You could enumerate through the default GraphicAdapter's DisplayModeCollection property to find the DisplayMode with the max width/height/aspect ratio.
Something like:
GraphicsAdapter defaultAdapter = GraphicsAdapter.DefaultAdapter;
DisplayMode maxMode = defaultAdapter.DisplayModeCollection[0];
foreach (DisplayMode enumeratedDisplay in defaultAdapter.DisplayModeCollection)
{
//Test enumeratedDisplay against maxMode, setting maxMode to enumeratedDisplay if enumeratedDisplay is better
}
Maybe there's a better way, but that's certainly one way you could find the max.
Or, you could take the same DisplayModeCollection and populate a comboBox of sorts or a list, letting the user choose for themselves.
My apologies if the above code doesn't work in that exact form. I can't test it where I am currently
Just set the PreferredBackBuffer to 1366x768 and if the graphics device can handle that resolution you'll get it. otherwise you'll get something scaled down. the xbox will automatically scale if nescessary to support the television being used as well.

Categories