Set Y-axis scale MS chart - c#

I am using MS chart, basically a line chart.
I am also using label format to show numbers upto 2 decimal places using
chart2.ChartAreas[0].AxisY.LabelStyle.Format = "#,##0.00;(#,##0.00)";
and property IsStartedFromZero is set to false.
This works for most of the cases.
But if i plot using value (.1,.1,.09) or (.25,.25.22), it shows duplicate values in Y-axis scale. This happens due to formatting of label.
In excel,there is option of setting major unit under format axis option, charts are properly created in excel if Major unit is set to 0.01 (fixed)
how can this be set in microsoft chart, i want to create the same using MS chart.
Tried chart2.ChartAreas[0].AxisY.Interval = .01, but this doesn't works.
Any other suggestion to fix this.

Related

Axis values formatting for chart

In my WinForms project I use the standard Chart control (from the VS toolbox) to display pressure versus time. It must be possible to zoom the graph. This works fine, but the X-axis values in the zoomed graph shows the values in a lot of decimals:
Does anyone have an idea what I can show the values in a better format? For example, in the above graph I would see labels like: 8.00, 10.00, 12.00? I can also live with values like: 7.98, 9.98, 11.98, so with a limited number of decimals.
I've looked in the control designers for the Chart control where I can specify a format string or the number of decimals, but I could not find it.
There is nothing special for this chart. It shows 2 series (not easy to see but you could probably see a blue and a green line). I use for both series the FastLine type of graph. I enabled the zooming by setting IsUserEnabled and IsUSerSelection to true for CursorX and CursorY in the graph designer. As said, this works, but I could not spot a property to customize the format of the values.
Set the LabelStyle.Format property:
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "0.00";
Or
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "{0:0.00}";

Chart control - Gap between first X value and Y-axis

I'm using a line chart to plot some values, where the x-axis has a set of strings and the y-axis has a double value between 0 and 1. Everything works correctly except there is a gap between the first x value and the y-axis
the image shows.
In this question the solution is setting the x-axis maximum and minimum value. However, I can't seem to do it in this case as the values are strings and not doubles / dates.
Given that you are using strings, this may or may not help. Try setting the IsXValueIndexed property of your underlying series to be false.
See this MSDN article for reference:
http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.series.isxvalueindexed(v=vs.110).aspx
To remove the margin you need to set
chart.ChartAreas[0].AxisX.IsMarginVisible = false;

Wpf Charting with x axis as time in minutes for one day and y axis as variable inputs range is not specified?

I need x axis as time in minutes as 00:00, 00:01, 00:02 ,00:03 ....00:60,01:00,...59:50,...59:59,00:00
if possible to show current date from system date time. and the x axis has to move to left for the whole day. and continue so on.
and y axis 0 to 65324 or may vary accordingly depending on the points it reads but i thik that is the max limit.
How to draw a line chart in wpf with a free source control?
I have tried to worked with WPF Toolkit but not able to find a solution
and now iam using Dynamic Data Display (D3) which is easy but i dont have this type of example.
You can use OxyPlot. It's free, and I've used it in several of my projects.
You can start with the official page, but here's a good example that will set you on the right trail:
line chart + live data.
You'll have to modify the axis a bit, but it's not too dificult.
Here's a screenshot from the above link:

Data Chart display

I want to display some values on graphic using a Chart in C#. I am using the following code
graphics.graphic1.Series[0].Points.AddXY(1, 14);
graphics.graphic1.Series[0].Points.AddXY(4, 0);
graphics.graphic1.Series[0].Points.AddXY(12, 4);
graphics.graphic1.Series[0].Points[0].AxisLabel = "lll";
graphics.graphic1.Series[0].Points[1].AxisLabel = "bbb";
graphics.graphic1.Series[0].Points[2].AxisLabel = "ccc";
to set some point values and some text on the X axis for each point. The problem is that the text is not shown.
What should I do in order to display the text on X axis beneath each point?
In Passing value to another class
you can find a complete working example of a chart using OxyPlot.WPF. If you have not gone too far with your app (which seems to be in WinForms), consider switching to WPF, it will be worth your while. Specifically, the result in that example is that without doing any special effort you get a chart with automated zoom as well as manual zoom (mouse wheel) on X and on Y.
switching to a DateTime x-Axis is as simple as changing the type of the axis in the XAML from:
<oxy:LinearAxis Position="Bottom" Title="Curvature (rad/in)" TitleFont="Arial" TitleFontSize="12" TitleColor="Black"/>
to:
<oxy:DateTimeAxis Position="Bottom" Title="Time" TitleFont="Arial" TitleFontSize="12" TitleColor="Black"/>
then when zooming you see your X-Axis automatically changing from Time only at 1 minute resolution to a 10 minute resolution to hourly, and then to date resolution... Magic.
I was really impressed by the results of this (see full example in the link).

How to force displaying specific dates on DateTimeAxis

Is it possible to force the display of grid lines on the chart with the dates for the extreme data points?
I've tried almost every configuration of following Chart DateTimeAxis properties: IntervalType, Interval, Minimum and Maximum but I wasn't satisfied with the result.
Setting properties Minimum and Maximum didn't solve the problem.
For instance (IntervalType="Days" , Interval="4" , Minimum="1/1/2010" , Maximum="1/31/2010"):
If I'm lucky I will generate some random data where only one extreme point will have the date with grid line.
Does somebody have an idea how to solve the problem mentioned above?
Edited to add
I added a bounty to this question since I really need a fast solution for this issue.
I am binding a series of specific pairs to my chart and I'd like to display excactly those given DateTime values on the x-axis.
Since these are usually dates like 6/30/11, 6/30/12 and so on, I can't use the Interval/IntervalType properties because adding 1 year or 365 days to 6/30/11 doesn't necessarily result in 6/30/12.
So what I need to do is either disable the "automatic axis label generation" of the DateTime axis or use another axis type.
LinearAxis doesn't work because it expects double values and CategoryAxis is not an option because it displays the axis labels between two tickmarks instead of underneath them.
I am very grateful for any help!
To be perfectly clear, here is what axis labels I need (taken from another chart component):
This is what I get so far with the Silverlight 4 Toolkit:
€: I also opened a thread in the official Silverlight Toolkit Support Forums.
The vertical lines are set where you specify an interval.
There is no vertical line for the data for 1/31/2010 as it does not fall on an interval.

Categories