Oxyplot C# Win Forms - Spreading out data on x axis - c#

I'm plotting relatively large amounts of data (~ 1 million points). The plot is working fine, but it seems that it is forcing all of the points within the viewable window despite default scrolling being enabled.
Any way to make it more readable? E.g. to spread the points out on the x axis. Perhaps zooming? I've looked a while and am rather lost.

You can add the following lines to enable the zooming function.
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].CursorY.IsUserEnabled = true;
chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
You can certainly choose to zoom only one of the axis.
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(0d, 200d);

Related

How to keep PointWidth fixed and add scrollbar in Range bar Chart

I have a gantt chart contrains tasks.
I declared the PointWidth as 0.25
GanttChart.Series["Tasks"]["PointWidth"] = "0.25";
this works good when I have few tasks but whenever I have more tasks the pointWidth (range) becomes smaller and smaller!
I want to keep it 0.25 and to put scrollbar when there are many tasks.
The CustomProperty PointWidth is in percent of the visible axis.
So with one point the bar or column is really fat and the more data points you add the thinner they will get.
If you want to keep a fixed width while changing the number of data points you need to use PixelPointWidth instead.
Note however that by default now the bars/columns get closer and closer to each other until the overlap.
To give them enough room and show scollbars instead, you need to enable the built-in zooming mechanism as MSChart will not use normal Scrollbars.
This should help:
Series s = chart1.Series[0];
s.SetCustomProperty("PixelPointWidth", "12"); // 12 pixels
var ca = chart1.ChartAreas[0];
ca.AxisX.ScrollBar.Enabled = true;
ca.AxisX.ScaleView.Size = 30; // show a value range of 30
chart1.Refresh(); // usally not needed, but we change a custom property
Note that the ScaleView.Size is in data values. This is the 3rd of the three coordinate system in the chart: percentages, pixels and values! Very powerful and rather tricky..

Chart Compression

I am writing a C# desktop application that requires a graphical representation (XoY) of some values (Y - value, X - (in) time).
chart1.Series[0].Points.AddXY(time, new Random().Next(-325, 531)); //this operation occurs at a set interval
The operation does its job, adding up values; however, in time the chart has the tendency to
"squeeze" itself which makes interpreting it a much harder task.
I want to make the graphic generate a better output, despite the number of points.
Notes
I consider that a good example of graphical representation would be one generated by an oscilloscope.
The chart is an spline.
The point addition is triggered upon a tick of a timer.
Depending on what you want there are several choices. My guess is that you want to keep all data points and simply want to add a scrollbar. To do you can write:
ChartArea A1 = chart1.ChartAreas["yourChartAreaByNameOrNumber"];
A1.AxisX.ScrollBar.Size = 12;
// show either just the center scroll button..
A2.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
// .. or include the left and right buttons:
A1.AxisX.ScrollBar.ButtonStyle =
ScrollBarButtonStyles.All ^ ScrollBarButtonStyles.ResetZoom;
// looks better inside, but ymmv
A1.AxisX.ScrollBar.IsPositionedInside = true;
A1.AxisX.ScrollBar.Enabled = true;
A1.AxisX.ScaleView.Size = 100; // number (!) of data points visible
You may want to play with the size and placement. Please pick the number of data points you want to have visible at any time..
If you want the visible area to follow the new data like in an oscilloscope, you can set the scroll position :
Series S1 = chart1.Series["yourSeriesByNameOrNumber"];
A1.AxisX.ScaleView.Position = S1.Points.Count - A1.AxisX.ScaleView.Size;
Note that you need to set it again after adding any data!
If you also want to let the users adapt the zoom range set
A1.AxisX.CursorX.IsUserSelectionEnabled = true;

ASP Chart. Multiple X axis values

I have been trying to have a chart with horizontal bars, with 2 series, one of them has huge values (1000,5000) and the other one tends to have smaller ones (10,100).
Something like this but on horizontal:
ASP Chart with multiple X axis columns
The problem is that I'm unable to have some kind of different range/legend for each one.
The small one stays small, but I would like to have some kind of proportional, having 2 legends on bottom.
How could I do that?
I have tried different things like using this statement:
seriesSmall.XAxisType = AxisType.Secondary;
chart.ChartAreas[0].AxisX2.Maximum = 200
But it did not work out...
seriesSmall.YAxisType = AxisType.Secondary;

Scalebreakstyle not working in Chart

My chart has a Datetime type X Axis and Double type Y Axis. I am trying to use the following code to insert the scalebreakstyle feature but it is not working. Does anyone have sample code for it. I was trying the web.UI code but did not work. Also I set the color of 2 series the same it keeps making them different.
/
/ Enable scale breaks.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.Enabled = true;
// Show scale break if more than 25% of the chart is empty space.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.CollapsibleSpaceThreshold = 25;
// Set the line width of the scale break.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.LineWidth = 2;
// Set the color of the scale break.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.LineColor = Color.Red;
// If all data points are significantly far from zero, the chart will calculate the scale minimum value.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.StartFromZero = StartFromZero.Auto;
// Set the spacing gap between the lines of the scale break (as a percentage of the Y-axis).
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.Spacing = 2;
www.tinypic.com/r/6e2c83/5
Scale breaks will not work under a wide array of conditions. According to the documentation any of the following causes scale breaks to be "not supported", which I have found means they will not work at all or they will warp your graph in weird ways
•Pie, doughnut, funnel, pyramid, radial or any stacked chart types are used.
•Custom intervals for labels, tick marks or grid lines are enabled.
•The minimum or maximum value for the axis is set.
•Custom labels are used.
•A logarithmic Y-axis is specified.
•Axis views on the Y-axis, which include scrolling and zooming, are used.
•3-D charts are used.
It looks like you maybe have a custome x axis label which would cause the scale break to fail.

Lock axis in ZedGraph

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?

Categories