0

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!

Andy
  • 3,997
  • 2
  • 19
  • 39
  • I wonder if it is because you are trying to set a property of a property? As opposed to `{ AxisX = new Axis { Maximum = 1.0 } }` for example (not sure if that is posible, not familiar with these classes) – musefan Aug 02 '13 at 08:42

2 Answers2

1

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

Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284
1

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 };
Tobia Zambon
  • 7,479
  • 3
  • 37
  • 69