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.
Related
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..
I have a c# RangeBar chart with about 25 labels on the AxisX. Depending on my live data, some of these labels have visible data points in the chart. Typically about 3/4 of the 25 labels don't have any data points. All horizontal gridlines are enabled, which makes the chart a bit cluttered. Especially for data points that are further away on the AxisY, it's difficult to distinguish at a glance to what label on the AxisX they belong.
My idea is to differentiate the AxisX labels that have visible data points either by giving their gridline a different color, a different style, or to completely remove gridlines of AxisX labels that have no corresponding data points. Is this even possible? Because all controllable properties and documentation I have found so far is regarding gridline styles of the entire chart.
Btw: Only showing AxisX labels that have data points is not an option.
Thanks in advance.
To reduce clutter you could use the axis.Interval property.
But each line will still have the same style, either of major or of the minor lines.
You could add VerticalLineAnnotations for selected points or try StripLines. Both can be styled freely.
Here is an example of a normal line chart, with lines randomly added to a few points:
The same result can be achieved by either Annotations or Striplines. The blue lines are StripLine and the red ones Annotations. Here are two functions to add a colored line to a DataPoint:
void AddStripLine(Chart chart, ChartArea ca, DataPoint dp, Color col)
{
Axis ax = ca.AxisX;
StripLine sl = new StripLine();
sl.BorderColor = col;
sl.IntervalOffset = dp.XValue;
sl.Interval = 0;
sl.StripWidth = 0;
sl.BorderWidth = 1;
ax.StripLines.Add(sl);
}
If you look very closely you'll see that the only visual difference is that the former are below, the latter above all other chart elements.
void AddAnnotation(Chart chart, ChartArea ca, DataPoint dp, Color col)
{
Axis ay = ca.AxisY;
VerticalLineAnnotation vl = new VerticalLineAnnotation();
vl.LineColor = col;
vl.AnchorDataPoint = dp;
vl.IsInfinitive = true;
vl.LineWidth = 1;
vl.Height = ay.Maximum - ay.Minimum;
vl.ClipToChartArea = ca.Name;
chart.Annotations.Add(vl);
}
For Bar charts use HorizontalLineAnnotations and anchor to the correct axis...
Using Annotatons is in fact the more natural way, since each is an individual object. StripLines are too, but are repeated at intervals . To avoid visible repetiton each needs to have suitable offsets and intervals to be determined for each. But it isn't hard to do either way.
Also note that the both types of lines lines are anchored to their DataPoints and will move with them e.g. when chart is resized..
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.
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'.
I am working with TeeChart fro .net, I would like to increase the size of drawing line in the chart. presently it is drawing very thin line which is not visible for all people. How to increase size of drawing line in TeeChart.
I have attached a simple chart image from my application. I would like to draw the line with more or equal size to axis lines. presently it seems drawing line size less that axis line size. I mean i want to draw line more thick.
2) How to assign axis scale more reliably, i mean presently if i have axis minimum and maximum values from 0 to 6, then it is showing on the axis like 0,2,4,6. I would like to see like 0,1,2,3,4,5,6 like that i mean with 1 scale increment. Please help me with the above two things.
1) How to increase drawing line size?
2) How to assign scale of axis more convenient?
The chart's features mention support for Csharp .NET charting control.
http://www.steema.com/teechart/net
Microsoft has pages with information about the chart controls:
http://msdn.microsoft.com/en-us/library/dd456632.aspx
Looks like you will find how to do the things you want there.
1) How to increase drawing line size?
You can set Line or FastLine Pen.Width like this:
line1.LinePen.Width = tChart1.Axes.Left.AxisPen.Width;
2) How to assign scale of axis more convenient?
TeeChart will automatically set axis scales to the minimum increment possible provided labels don't overlap. To get a fixed axis increment you should set axis Increment property. Labels won't be allowed to overlap though.
tChart1.Axes.Bottom.Increment = 1;
For more information on axis settings please read tutorial 4. Tutorials can be found at TeeChart's program group.