Question

I am using .NET 4.

I experience a strange behaviour with the object initializer combined with the ChartArea.

The object initializer works with the Chart class:

For example:

Chart ch = new Chart { Anchor = AnchorStyles.Bottom };

But it doesn't with the ChartArea:

ChartArea ca = new ChartArea { AxisX.Maximum = 1.0 };

The IntelliSense displays the AxisX, but after implementing it says:

Cannot resolve symbol 'AxisX'

What happens here? Why it doesn't work? Is this a fault by me or by the compiler?

Thanks!

Était-ce utile?

La solution

Try the below, shoudl work

ChartArea ca = new ChartArea { AxisX = new Axis {Maximum = 1.0 }};

Anchor is an enum, whereas AxisX is an object that represents the primary X-axis

Autres conseils

AxisX must be initialized itself, create a new Axis and initialize it.

var x = new Axis {Maximum = 1.0 };
ChartArea ca = new ChartArea { AxisX = x };
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top