DevExpress:如何以编程方式设置图表到图表控件

时间:2016-01-19 22:03:14

标签: c# devexpress devexpress-windows-ui

我动态创建ChartControl,我必须将Diagram属性设置为dynamiclly。 这是我的代码:

double[] test1 = {4., 26., 30., 17., 2.};
double[] test2 = {0., 0., 0., 0., 0.};
double[] test3 = {4., 26., 30., 100., 2.};
double[] test4 = {4., 26., 30., 200., 2.};
double[] test5 = {3.4, 0., 17., 17., 2.};
double[] test6 = {3.4, -10., 17., 17., 2.};
double[] test7 = {1.0};
double[] test8 = {};
double[] test9 = null;

UVI testOne = UVICalculator.calculateUVI(test1);
UVI testTwo = UVICalculator.calculateUVI(test2);
UVI testThree = UVICalculator.calculateUVI(test3);
UVI testFour = UVICalculator.calculateUVI(test4);
UVI testFive = UVICalculator.calculateUVI(test5);
UVI testSix = UVICalculator.calculateUVI(test6);
UVI testSeven = UVICalculator.calculateUVI(test7);
UVI testEight = UVICalculator.calculateUVI(test8);
UVI testNine= UVICalculator.calculateUVI(test9);

assertTrue(8.8956 == testOne.getValue());
assertTrue(0 == testTwo.getValue());
assertTrue(8.9952 == testThree.getValue());
assertTrue(8.9952 == testFour.getValue());
assertTrue(4.027200000000001 == testFive.getValue());
assertTrue(4.027200000000001 == testSix.getValue());
assertNull(testSeven);
assertNull(testEight);
assertNull(testNine);

但它会引发 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; 异常。你有什么建议吗?

1 个答案:

答案 0 :(得分:1)

ChartControl.Diagram的实例由图表自动创建。 ViewType枚举控件可以控制创建的图表。因此,将ChartControl.Diagram属性强制转换为图表类型以获取它。您不需要手动创建图表。