using logarithmic scale in Ms chart control - c#

Im trying to create a chart the has a base 10 logarithmic scale for the x axis with a range from 1 to 1000. I seem to be able create the axis during design time but whenever the form is loaded I get an error message saying "Chart Area Axes - A logarithmic scale cannot be used for this axis.
Is this a limitation on the MSChart control? why am I not able to create a log scale on the X Axis?

It is because for a logarithm scale, the values must be greater than zero. Charting.CHart treats empty chart as being consisting of zeros (I know it is weird). This error can be very difficulty to debug. Therefore, it mean that the graph cannot be EMPTY if any of the axis is a logarithm scale. What I normally do is set the axis as linear and the change it immediately after plot on the graph (and checking no zeros or negative values on the logarithm scale). Also, remember to change the axis to linear before clearing the axis and plotting. Hope this helps someone.

I propose to use SuppressExceptions property which allows to ignore some exceptions, also that one connected with zeros in axis with logarithmic scale. I think this is the best solution for that situation instead manipulating data.
chart.SuppressExceptions = true;

It's not just about zeroes but also about having your values in the right datatype. Suppose you're populating the chart with values form a DataTable. If you haven't specified the type, .NET will automatically assume they are strings and thus not be able to plot a logarithmic scale.
incomplete specification of the datatable:
PP = New DataTable
PP.Columns.Add("X-value")
PP.Columns.Add("Y-value")
complete specification:
PP = New DataTable
PP.Columns.Add("X-value", Type.GetType("System.Double"))
PP.Columns.Add("Y-value", Type.GetType("System.Double"))
In the first example the exception will be thrown. In the second it won't.

Not all chart types support logarithmic scales; try changing the chart type e.g. to Line Chart.
Chart types: http://msdn.microsoft.com/en-us/library/dd489233.aspx
ChartType property: http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.series.charttype.aspx

Related

Fit as much on the x axis as possible in chart control

I have a chart that has times on X axes. How can I remove the gaps in between the points on the X axes? I think that it might be called interval or scale or something but I'm not sure where in the properties I can find it.
I assume that you are using Microsoft Chart controls and you are trying to fit the "time" labels within the XAxis length.
You can set the LabeAutoFitStyle property of the ChartArea's XAxis as fitted for your requirement. See this MSDN link for different LabelAutoFitStyles.
chart1.ChartAreas[ChartName].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep45;
If you want to change the intervals and number of intervals used in display, use AxisX.Interval and AxisX.IntervalAutoMode property.

MS Chart not showing all the series values at same time ( for the same X value)

Apologies for not able to find a more suitable title for my issue here. I am using MS Chart control in my project to plot real-time values from a source that generates 4 values per second. X axis is time at which the value is generated and the Y axis the value itself. I am dynamically adding a new series for each variable. All the variables are manually added by the user one-by-one and then a series will be created for it.
Basic part seems to be working except the chart is plotting values from different series at different time even though the values are generated at same time. Following image shows the exact issue:
As you can see, the list in bottom is a list of values I am plotting. It shows values and the time they are generated at (hh:mm:ss.ms)
When I plot these values, which is shown in the chart area, this is what I get. See the location of the latest values (marked by red arrows) for all the series. The latest value is at different time even though they all are generated at the same time. Every series seem to have a separate X axis. I expected the latest Y values should be plotted at the same X value and that should be shown at the extreme right of the chart. More like the bottom most series is being shown. That is the very first series created. Every time only the series that is created first works fine and the following series lags for some reason.
Chart, share X axis between different series looks like similar issue to mine but is not answered.
Chart Multiple series different length generate duplicate x axis seems to be the exact issue I am having but the difference is - I am plotting a real-time graph. I can't loop through every series after adding a new data point to mark whether a point is empty or not. That will be a lot of overhead. Some Googling suggested use of InsertEmptyPoints() to every series to match all the X axis. MS Chart sample code also explains using this method but I am not sure where/when to use this method. If I use it after creating a series but before adding a data point - the code crashes. I have tried something like this:
_chart.Series.Add(series);
_chart.DataManipulator.InsertEmptyPoints(250, IntervalType.Milliseconds, name);
Am I doing something wrong here? Thanks for any help offered.
I got this working by adding empty points. I filled every series with max possible data points to begin with. Say I want to show 100 data points in every series before I start deleting the oldest (Points[0]) data point so that my chart will look like it's moving from right to left. In that case I will add 100 empty points while creating every series using:
for (int i = 0; i < 100; i++)
{
series.Points.AddXY(i.ToString(), double.NaN);
series.Points[i].AxisLabel = " ";
}
Then, while adding real data just do it normal way:
_chart.Series[index].Points.AddXY(time, YValue);
// delete more than max. points.
if (_chart.Series[index].Points.Count > MaxTrendPoints - 10) // -10 is adjustment. Got it by trial and error.
_chart.Series[index].Points.RemoveAt(0);

C# Chart date type x axis is not hiding empty point

Basically my C# chart control has a datetime type x axis.
I am plotting 2 different time period, but do not want the empty points to even show up in the x axis.
Is it possible to change a certain property of the chart control to hide the period of time which does not have point.
I implemented something similar to your problem, here is what I used (C#), it may help:
Chart4.DataManipulator.InsertEmptyPoints(1, System.Web.UI.DataVisualization.Charting.IntervalType.Number, Chart4.Series["s3"]);
Chart4.DataManipulator.InsertEmptyPoints(1, System.Web.UI.DataVisualization.Charting.IntervalType.Number, Chart4.Series["s2"]);
Chart4.Series["s3"].EmptyPointStyle.Color = System.Drawing.Color.Transparent;
Chart4.Series["s2"].EmptyPointStyle.Color = System.Drawing.Color.DarkGreen;
You can specify the intervalType.Days in place of number..
datamanipulator.ignoreemptypoints = true;
from this article on grouping:
http://msdn.microsoft.com/en-us/library/dd489213.aspx
If you don't want the x-axis to be scaled to the x-values simply set the/all series to be indexed:
foreach (Series s in chart1.Series) s.IsXValueIndexed = true;
Now each DataPoint will sit at its index position instead of its x-value position. Note that this also mean that you need to make sure all Series aligned, read all have a DataPoint at the same indices, be it a real one or an Empty one or else the will shift..!

Microsoft Chart Controls: Label multiple y values and variable y axis?

I am currently using Microsoft Chart Controls to generate a box plot chart. I have enabled the IsValueShownAsLabel property of the chart's series, but only the first y-value(lower whisker) value is being labeled. Is there a way to enable the labeling of all y-values in the chart?
Also, is there a way to get a different axis for each data point? The different data points of the chart are not related when it comes to value ranges, so many data points with small y-values are difficult to read on the chart. I have currently enabled scrolling as a workaround, but am not satisfied with the result. I would instead like to have a different y-axis for each data point, so that the y-values for each data point take up the full height of the chart, with the min and max whisker values serving as the y-axis minimum and maximum points. Is this possible?
To get different axis you will need to look into the properties under ScaleBreakStyle under AxisY
Set something like
Chart1.ChartAreas[0].AxisY.ScaleBreakStyle.Enabled = true;
Chart1.ChartAreas[0].AxisY.ScaleBreakStyle.BreakLineStyle = Charting.BreakLineStyle.Wave;
// set this to an even lower value if required
Chart1.ChartAreas[0].AxisY.ScaleBreakStyle.CollapsibleSpaceThreshold = 15;
Not sure on how to get multiple values but can you try setting those values specifically to the labels in these format #VALY1,#VALY2 depending on the number of Y values available.

Display unsorted data in SL3 line chart

I'm having trouble with my Silverlight Chart. My model is unsorted, that is, the sorting is done on the server side. It needs to support year transitions, but as you can see from the screenshot the charting control automatically sorts the model and fills in the gaps. The line sort be ever increasing and not taking a dip on new year.
How can I make the chart display the data in the order specified in the grid control to the left?
Btw, using SL3
alt text http://img705.imageshack.us/img705/7602/unsortedsilverlightchar.png
The line chart is not designed to do the task you seem to be asking. After all the purpose of a line chart is to help the user trace a trend or even visually interpolate an interim value. However if the interval between horizontal points is not linear and always traveling in the same direction such lines meaningless.
I would therefore suggest that the Line chart is not appropriate or that you have some other hidden data which should be used for the Y-axis which would make the lines meaningful.
Alternatives might be to use a Scatter graph or a Column series where the y-axis value has been converted to a string and thus cause the series to use a Category based axis instead of range based one.

Categories

Resources