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..
Related
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 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;
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.
I have a dotnetcharting graph with 3 series. I can change the style of the whole graph to stacked.
ChartIn.YAxis.Scale = Scale.Stacked;
But I want to just stack two out of the three series. So that for each there are two bars combined into one stack with another whole bar next to it.
Can this be done?
In the end I made the data I wanted separated from the stack into a separate filled line series. Not ideal but it looked fine.
ChartThree.SeriesCollection[3].Type = SeriesType.AreaLine;
The way to accomplish this is by creating an additional scale and setting the extra series's YAxis to that scale. The second scale can be stacked independently of whether or not the first scale is stacked. Note that you will need to adjust the ranges on the second scale in order to make the values show up in the correct relative size.
Here's an example that produces a chart with two separately stacked sets of data (using a chart that has previously been populated with a total of 4 series):
//set main chart to stacked
Chart.YAxis.Scale = Scale.Stacked;
//create new axis, assign it to relevant series, and set it's scale to stacked
Axis a2 = new Axis();
Chart.SeriesCollection[2].YAxis = a2;
Chart.SeriesCollection[3].YAxis = a2;
a2.Scale = Scale.Stacked;
//tie the scales together to ensure proper relative display
Chart.YAxis.SynchronizeScale.Add(a2);
How can i add labels for each and every yvalue in series of a rangebarchart ?
You all know that for plotting rangebartype series ,we need two yvalues as yvalue[0] and yvalue[1] .Here I need to add data labels to each of those yvalues( which means both at yvalue[0] and yvalue[1]).how can i implement that?can anybody suggest me?please!!
The label should look like as below for a rangebar(to be displayed on both sides of a rangebar).
Label1 ███████████████ Label2
Label███████████████████ Label
There is no built-in way to do this in MS Chart. However, there is an ugly little workaround that will give you the display that you want.
For each datapoint (rangebar) that you want to display, you will need to create 2 datapoints that lie on top of one another. As an example:
DataPoint0: X=1 Y=5,10
DataPoint1: X=1 Y=10,5
These two datapoints lie right on top of one another, except one is displayed left-to-right and the other is displayed right-to-left.
For each DataPoint, under CustomProperties, there is the BarLabelStyle property. Set this to 'Outside' for both of the datapoints. Normally, this will display the label to the right of the range bar, but for DataPoint1, with the reversed Y values, the label is now placed to the left of the range bar. So, set your label for DataPoint0 to 10 (max value), and for DataPoint1 set the label to 5 (min value).
This will then look just like one range bar with the min value on the left and the max value on the right.
Caution: If either end of the range bar is too close to the edge of your graph, MS Chart, in its infinite wisdom, will force the label to be displayed inside the range bar. To overcome this, you can actually add a third number to the Y values of the DataPoint object. This third value is not displayed, but if it is larger than the largest Y value in your data series, it will force the chart to rescale to accommodate this larger value, so your labels are not forced inside the range bars. You could probably handle this another way with setting properties of the ChartArea also.