Chart C# remove numbers and add range - c#

My questions:
How can I remove these numbers that I marked in the screenshot https://prnt.sc/116tvvz?
How do I specify the range of numbers on the chart? For example, here's a screenshot https://prnt.sc/116txqs. It shows numbers in the range of 50.000-60.000, but the graph starts from zero to 60.000.

I'm assuming you're using the default WinForms Chart available from the framework? (from System.Windows.Forms.DataVisualization).
If so, you could manipulate the X & Y axes either from code or from the UI. The key is that they're defined under ChartAreas.
From the UI: Properties > ChartAreas > Axes. From there you can hide the labels by turning off Enabled. Same with Minimum and Maximum, and a whole lot of other customisations.
They're obviously also available from code, which can be useful in case you want to play with the scaling at the arrival of each data point.
More reading on the ChartArea class in the docs.

Related

Windows Charts Forms C# Auto labeling of the points on X

I'm having some issues with Windows charts and the points displayed on the x-axis.
I have two plots of data in a line chart based upon set data points, e.g. 200,400,600,800,1000. I also use a 3rd & 4th series to colour areas depending which line is higher. To do this I've had to add extra points where the two lines intersect. This then throws out the labels on the x axis as the chart automatically labels the points something odd such as:
|
|
|
|
=========================
120......370.....590.....730......850
Is there a way I can explicitly specify the datapoints on the axis that I want to use, other than the min-maximum value function?
So you want to customize the X axis labels to match your data? If so you can define custom labels and a customize event to do that. This was posted on StackOverflow by the user Somebody
How to set values in x axis MSChart using C#

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: Design messed Up after clearing and re-adding Y-Values

Been struggling with this through out the day. I have three series on a chart that look like this. NOTE: I am using the winforms control.
The values are being added based on calculations from input. I am using this code to add the values to each series.
this.chart1.Series["green"].Points.AddY(greenvalue);
this.chart1.Series["totalsaving"].Points.AddY(totalsavingvalue);
this.chart1.Series["blue"].Points.AddY(bluevalue);
The series properties I have set like this. Green and totalsaving are both set to StackedColumn, blue is set to Column for chart type.
I then have a button to start over which brings the user back to the input area and I am then using this code to clear the series values on the start over click.
chart1.Series["totalsaving"].Points.Clear();
chart1.Series["green"].Points.Clear();
chart1.Series["blue"].Points.Clear();
The same calculation click is being used as above to calculate and populate the series data. The problem is when I click the calculate button to calculate the values after I have cleared them, the total savings, and the green are missing. Just the blue is shown.
Am I doing something wrong with the way I am trying to clear the values so I can re calculate?
OK, from the edits, comments, our chat and the joim.me session enough data has accumulated to answer the question.
You have twisted the display by adding an extra data point to the blue series in the designer.
This point occupies slot 1 but remains invisible as its value = 0.
This pushes the next point in the series to slot 2
After clearing the points it is gone and the display doesn't work anymore.
The disappearing of the two columns probably was caused by hard coded widths.
You have several paths you can follow:
recreating the extra point with value = 0 before adding the real data (not recommended)
not adding the extra point in the first place but forcing each point into its slot by using Points.AddXY instead of Points.AddY with X being the slot.
not clearing the points but updating their values by using the SetValueY method. After all three data points have beend assigned their new values you need to call chart1.Invalidate() to make it show.
Fore easiest styling of all those properties, some of which are deeply burried inside of property strings(!), you may even decide to add and style&polish all three points in the designer and only update their y-values like this:
chart1.Series["green"].SetValueY(greenvalue);
chart1.Series["totalsaving"].SetValueY(totalsavingvalue);
chart1.Series["blue"].SetValueY(bluevalue);
chart1.Invalidate();
The choice is yours, but in any case I recommend setting the proper X values, be it in code or in the desginer..

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.

How to print labels on both sides of a rangebar in WinForms MS Chart using C#

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.

Categories