Grid++报表的 柱状图(一)
1 function FillDataChart(DataURL) 2 { 3 //获得柱状图报表节对象 4 var Chart = Report.ControlByName("Chart1").AsChart; 5 6 7 8 //从网上取XML数据并转存到xmlDom中 9 var xml = Report.ExtractXMLFromURL(DataURL); 10 var xmlDom = CreateXMLDOM(); 11 xmlDom.async=false; 12 xmlDom.load(xml); 13 14 15 //将xmlDom中的数据赋值给图表 16 var RowNodes = xmlDom.childNodes[0]; 17 var RowCount = RowNodes.childNodes.length; 18 Chart.GroupCount =RowCount; 19 Chart.SeriesCount=RowNodes.childNodes[0].childNodes.length-1+1; 20 //首先将原来数据全部置为0 21 for (SeriesIndex=0; SeriesIndex<Chart.SeriesCount; ++SeriesIndex) 22 for (GroupIndex=0; GroupIndex<Chart.GroupCount; ++GroupIndex) 23 Chart.Value(SeriesIndex, GroupIndex) = 0; 24 25 26 for(i=0; i<RowNodes.childNodes.length; ++i) 27 { 28 Chart.GroupLabel(i)=RowNodes.childNodes[i].childNodes[0].text; 29 } 30 for(i=1; i<RowNodes.childNodes[0].childNodes.length; ++i) 31 { 32 Chart.SeriesLabel(i-1)=RowNodes.childNodes[0].childNodes[i].baseName; 33 } 34 Chart.SeriesLabel(Chart.SeriesCount-1)="毛利"; 35 var MaxVal = 0; //找出值中的最大值,以便设定图表的 YAxisMaximum 属性 36 for (i=0; i<RowCount; ++i) 37 { 38 var FieldNodes = RowNodes.childNodes[i]; 39 40 for( j=1; j<FieldNodes.childNodes.length; ++j) 41 { 42 var Val=parseInt(FieldNodes.childNodes[j].text); 43 if (MaxVal < Val) 44 MaxVal = Val 45 Chart.Value(j-1,i) = Val; 46 } 47 Chart.Value(Chart.SeriesCount-1,i) = Chart.Value(0,i)- Chart.Value(2,i)- Chart.Value(4,i); 48 } 49 Chart.YAxisMaximum = MaxVal; 50 51 }