ZedGraph Legend text Location - c#

I have a problem positioning a legend to accommodate changing graph data values.
The Zedgraph Y axis scale is set to auto - GraphPane.YAxis.Scale.MinAuto = true.
The graph is populated with differing data stes as chosen by a combobox.
This obviously results in fluctuating Scale.Min values.
I have a legend located under the min value line. As I select differing sources, the location of this legend jumps around.
How can I specify the legends position so that it stays in the same place regardless of input?
What I need is to get the axis minimum value and offset it by a negative amount to be just under the graph data.
It would be easy if the scale was zero'd but as it changes, I'm lost...
These pics show how the legend moves with differing data.
This is the code referencing the text placement.
The offset value representing UNKNOWN is what I need to determine each time.
TextObj Qtr1Text = new TextObj("Q" + Qtr1 + " 16", dQtrFirst, myPane.YAxis.Scale.Min - UNKNOWN);
As shown, both the 'Q2 16' offsets are 0.08.
or maybe there is a much better way of doing all this?

Finally figured out a reliable way to do this.
double yOffset = (myPane.YAxis.Scale.Max - myPane.YAxis.Scale.Min) / 36; //magic number
TextObj Qtr1Text = new TextObj("Text Value", xLocation, yOffset);
myPane.GraphObjList.Add(Qtr1Text);
The value 36 is an arbitrary number which should be adjusted to give you the negative spacing you want. 36 gives a spacing like in the top pic, right hand side 'Q3 16'.

Related

C# Candlestick plot graph issue. No candle body visible. Candles plot like lines

I am trying to plot some sample data I got from an excel file and saved into arrays in a candlestick chart. The data I am trying (if it helps) is a forex pair(EUR/GBP ratio), in forex, pairs are quoted at the 4 decimal point.
The problem is that the body of the candle is not visible on the chart as I would've expected in the below graph(image is just a random example).
example candlestick chart
My candles plot like lines with barely any visible body.
my plotted candlestick chart
The Y axis minimum and maximum values are set by default to 0 and 1 so logically I assumed that the interval is the problem.(my sample data is around 0.8500 min and 0.9500 max) so naturally in order to see the candle body I tried to reduce the minimum and maximum interval in order to see any candle body, but this only caused my chart to plot blank, nothing there.
blank candle chart
Just to test things around i'm plotting 15 points.
To plot those 15 point
if (i < 15)
{
chart1.Series["Series1"].Points.AddXY(i, 0, 0, Open[i], Close[i]);
}
The plotting function takes 5 arguments, arg1 date, arg2 candle low, arg3 candle high, arg4 candle open price, arg5 candle close price.
If I had two candles with close prices of 0.8532 and 0.8539 and open prices 0.8530 and 0.8537 respectively I should've seen candle bodies like this
Expcted candle body
The only thing I tried to play around with was with Y minimum and maximum values but with no solution, and with the Y axis scaleview property again with no solution again.
The last thing I can think of is to make the chart to take into account the 4 decimal point as a main value for which it plots it's data (I don't know how to make sense of this), going with significance from right to left If this makes sense.
Is there something that I miss?
What can I do to properly see the body of the candle?
And why when I reduce the Y axis value interval my charts gets blank.
Thanks in advance, any suggestion would be helpful.
It all comes down to the numbers in your data.
The automatic axes scaling will allow for all values to show.
With high/low being 0/0 or 0/1 the range it needs to show goes from 0 to 0.8539 or from 0 to 1.
But the body only goes from 0.8530 to 0.8532.
So the body is ca 2/1000 of the axis range. To make it show you would need a rather large chart height.
Make sure to set suitable values in your data and help the chart along by setting the Minimum/Maximum values..:
var ca = chart1.ChartAreas[0];
ca.AxisY.Minimum = 0.8500;
ca.AxisY.Maximum = 0.8570;
chart1.Series["Series1"].Points.Clear();
chart1.Series["Series1"].Points.AddXY(2, 0.8532, 0.8530, 0.8532, 0.8530);
Result:

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..

MSChart axis moves depending on text size

Does anybody now how to prevent the Y-axis from moving (horizontally) when the text area increases (for example when displaying 100 instead of 1 on a label on the Y-axis).
The following image illustrates the problem; when a decimal is added to the number on the labels, the diagram is resized and the Y-axis is moved to the right:
The reason the Axis and other a few other ChartElements may move is that their Positions are set to Automatic by default; so when the lables need more space they get it and the inner portion is reduced.
So if you want to prevent that you need to set an explicit values for the X values of its Position.
Note that the values are in percent of the respective containers.
Unless you set a special Crossing value, the primary axes are always drawn to the left and bottom of the InnerPlotArea.
So you want to set the position, maybe like this:
ChartArea ca = chart1.ChartAreas[0];
ca.InnerPlotPosition.X = 10;
Note however, that this means: The Y-Axis will start at 10% of the whole ChartArea.Width, which usually means something like 'almost 10%' of the whole Chart.Width. (The Legend and some white space will usually take some space, too).
So if you resize your chart the axis may sit a little too much to the right.. You may want ot play with the number and maybe code an extra line in the Resize event of the Chart.

ilnumerics axis label positions messed up in manual mode & label position property not working

i tried to configure my own custom y-axis for a little more advanced axis (norm probability plot, for the result look at the linked png) :
http://img5.fotos-hochladen.net/uploads/labelmisaligned2cd86m4qov.png
the tick mode is set to 'manual'. I want the tick lines to direct inwards, which looks sometimes a little more 'professional' in plots for scientific topics). so i set the TickLength property to -0.5 (but the issue does not depend on the direction). there is no "inwards" property, at least i couldnt find one, so i tried this idea, which worked for the tick lines.
With this configuration the tick labels are not anymore properly aligned with the axis (see image). so i played a little with the anchor and position properties. the position property of an individual tick is set by
tick.Label.Position = new Vector3(2f, 0, 0);
The problem is, this property has no effect. so i searched in the original source code for the code that causes this problem and i found it. the position property is overwritten all the time the axis is constructed by some values that only depend on the origins of the "world" and the positions of the tick lines. the custom position setting is erased.
so my question is:
is this behaviour intended or a bug?
and if it is no bug, how can i allign my axis tick label so that it is well alligned with the axis line ?
To wrap it up: The position property of the ticks label has no effect. The automatic text alignment is 'ok' when i use the standard tick direction (although it would be nice to have the ability to control the text to axis distance and the right/left alignment of the text itself (text block alignment) even for this case). If i want to change the label to axis position it does not work. I think for professional looking plots those formating features are essential.
ConfigureAxis method in ILAxis.cs overwrites all label positions in the following foreach block:
foreach (ILTick tick in Ticks) {
float curVal = tick.Position - min;
Vector3 curPos = startWorld + a * curVal;
tickPosArr[i++] = curPos.X; tickPosArr[i++] = curPos.Y; tickPosArr[i++] = curPos.Z;
if (Ticks.TickLength < 0)
tick.Label.Position = curPos;
curPos += (tickDirWorldStartLines + ticka * curVal);
tickPosArr[i++] = curPos.X; tickPosArr[i++] = curPos.Y; tickPosArr[i++] = curPos.Z;
if (Ticks.TickLength >= 0)
tick.Label.Position = curPos;
cheers,
andré
edit:
as mentioned in my comments i found a "work around" by using the anchor property
http://www.fotos-hochladen.net/uploads/unbenanntcs7kreytib.png
The first part of your question addresses the issue http://ilnumerics.net/mantis/view.php?id=168 which will be fixed in the next version. In general, the ticks are automatically positioned on user interaction like rotation. Depending on the relative position of the tick labels regarding the axis, the tick labels position and anchor are constantly adjusted. A fixed value would be helpful in rare situations only.
However, you can configure your own setup with custom tick labels, if you do not want to rely on the automatic settings. You may use ‘ILAxis.Ticks.Mode = TickMode.Manual’ and add individual ticks. Each tick may have its individual label which is not overwritten within the axis configuration function.
See: Everything about axis + ticks configuration: http://ilnumerics.net/axis-configuration.html

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.

Categories