0

I have a Line Chart in Visual Studio, and the Axis X values are from 0 to 20000 (43 in total).

The values are actually frequency values, and they increase each time. So in the first twenty, it reaches from 0 to 200, but in last 23 it goes from 200 to 20000. In my chart, it looks very annoying as 20000 is very high, so it shrinks about half of the values in the left corner and shows half in the whole chart.

I have attached an image of my diagram and also code. Please have a look and suggest me how do set the interval property to auto so it can show all the values equally. I have also attached an image of what I'm trying to do.

Chart image

enter image description here

and here is the image of what I want to achieve:

Frequency table excel.

enter image description here

Here are my chart settings:

        ChartArea chart = chartEnergy.ChartAreas[0]; 
        chart.AxisX.IntervalType = DateTimeIntervalType.Number;

        chart.AxisX.LabelStyle.Format = "";
        chart.AxisY.LabelStyle.Format = "";
        chart.AxisY.LabelStyle.IsEndLabelVisible = true;

        chart.AxisX.Minimum = 0;
        chart.AxisY.Minimum = 0;
        chart.AxisY.Interval = 10;
        chart.AxisY.IsStartedFromZero = false;

I have also tried minimum, maximum, interval setting to 1 or not setting at all but none of these work. Any help would be appreciated. Thanks.

Frequency Values:

1.25,
1.6,
2,
2.5,
3.15,
4,
5,
6.3,
8,
10,
12,
16,
20,
25,
31.5,
40,
50,
63,
80,
100,
125,
160,
200,
250,
315,
400,
500,
630,
800,
1000,
1250,
1600,
2000,
2500,
3150,
4000,
5000,
6300,
8000,
10000,
12500,
16000,
20000.
TaW
  • 53,122
  • 8
  • 69
  • 111
  • . Look at the update of the linked answer - Note that you will need CustomLabels; no matter which Interval/Offset and which Base you use, the calculated values will never quite fit your labels. – TaW May 05 '18 at 07:46

1 Answers1

1

You are looking for a logarithmic scale.

Try setting the Axis.IsLogarithmic property for the X axis.

https://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.axis.islogarithmic(v=vs.110).aspx

iamJP
  • 386
  • 1
  • 12
  • Thanks but my chart contains zeros and this property is only for positive values! – Madhsudhan Khemchandani May 04 '18 at 17:36
  • 2
    I don't see any zeroes in your frequencies. I believe it is the X axis that should be logarithmic. The Y axis should remain linear. – iamJP May 04 '18 at 18:01
  • but I'm getting an exception in Program.cs. "Axis object - Negative or zero values cannot be plotted correctly on logarithmic charts. Only positive values can be interpreted on a logarithmic scale." – Madhsudhan Khemchandani May 05 '18 at 05:40
  • Alright! I had to remove AxisX.minimum = 0! Now it is working but the maximum is 10000, and maximum value in frequency is 20000! It is showing the values, but I can't see 20000 on the end. – Madhsudhan Khemchandani May 05 '18 at 05:47
  • 1
    To make the Labels for Minimum and Maximum show you need to set `yourXAxis.IsMarginVisible = true;` – TaW May 05 '18 at 08:37