0

I create ChartControl dynamiclly and I have to set Diagram property as dynamiclly. Here is my code:

   XYDiagram xyDiagram1 = new XYDiagram();
   xyDiagram1.AxisX.Title.Text = "";
   xyDiagram1.AxisX.VisibleInPanesSerializable = "-1";
   xyDiagram1.AxisX.WholeRange.Auto = false;
   xyDiagram1.AxisX.WholeRange.AutoSideMargins = false;
   xyDiagram1.AxisX.WholeRange.MaxValueSerializable = "10";
   xyDiagram1.AxisX.WholeRange.MinValueSerializable = "5";
   xyDiagram1.AxisX.WholeRange.SideMarginsValue = 2.5D;
   xyDiagram1.AxisY.Title.Text = "";
   xyDiagram1.AxisY.VisibleInPanesSerializable = "-1";

   barChart.Diagram = xyDiagram1;

But it throws This property can't be customized at runtime. exception. Do you have any suggestion?

cagin
  • 5,772
  • 14
  • 74
  • 130

1 Answers1

1

An instance of ChartControl.Diagram is automatically created by a chart. The ViewType enumerable controls what diagram is created. So, cast the ChartControl.Diagram property to your diagram type to get it. You don't need to create a diagram manually.

Gosha_Fighten
  • 3,838
  • 1
  • 20
  • 31