문제

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!

도움이 되었습니까?

해결책

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

다른 팁

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 };
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top