public void LoadGraph() { if (_report.State != Report.StateEnum.Executed) { return; } bool rotateGraph = false; bool rotateAxes = ((_report.GraphOptions & OlapReport.GraphOptionsEnum.RotateAxes) > 0); int seriesPosCount = (rotateAxes ? _report.Cellset.Axis1PosCount: _report.Cellset.Axis0PosCount); int seriesMemCount = (rotateAxes ? _report.Cellset.Axis1TupleMemCount: _report.Cellset.Axis0TupleMemCount); int catPosCount = (rotateAxes ? _report.Cellset.Axis0PosCount: _report.Cellset.Axis1PosCount); int catMemCount = (rotateAxes ? _report.Cellset.Axis0TupleMemCount: _report.Cellset.Axis1TupleMemCount); if (seriesPosCount > 256) { seriesPosCount = 256; } if (catPosCount > 1024) { catPosCount = 1024; } bool showValues = (_report.GraphOptions & OlapReport.GraphOptionsEnum.ShowValues) > 0; bool showSeries = (_report.GraphOptions & OlapReport.GraphOptionsEnum.ShowSeries) > 0; bool showCats = (_report.GraphOptions & OlapReport.GraphOptionsEnum.ShowCategories) > 0; bool setScaling = (_report.GraphOptions & OlapReport.GraphOptionsEnum.SetScaling) > 0; // create series for (int i = 0; i < seriesPosCount; i++) { string name = ""; for (int j = 0; j < seriesMemCount; j++) { name += (j == 0 ? "" : " | ") + (rotateAxes ? _report.Cellset.GetCellsetMember(1, j, i).Name : _report.Cellset.GetCellsetMember(0, j, i).Name); } Series series = new Series(); series.Name = name; _chCtrl.Series.Add(series); // type if (_report.GraphType == OlapReport.GraphTypeEnum.Pie) { // limit number of series if (seriesPosCount > 6) { seriesPosCount = 6; } // disable scaling for pie setScaling = false; series.ChangeView(ViewType.Pie); PiePointOptions ppo = (PiePointOptions)series.PointOptions; PieSeriesView psw = (PieSeriesView)series.View; PieSeriesLabel psl = (PieSeriesLabel)series.Label; psl.Position = PieSeriesLabelPosition.TwoColumns; series.ShowInLegend = false; // cause it's shown in pie anyway showValues = true; showCats = true; this.chkCat.Checked = true; this.chkCat.Disabled = true; this.chkValues.Checked = true; this.chkValues.Disabled = true; } else { if (_report.GraphType == OlapReport.GraphTypeEnum.BarVertical) { series.ChangeView(ViewType.Bar); } else if (_report.GraphType == OlapReport.GraphTypeEnum.BarHorizontal) { series.ChangeView(ViewType.Bar); rotateGraph = true; } else if (_report.GraphType == OlapReport.GraphTypeEnum.StackedBarVertical) { series.ChangeView(ViewType.StackedBar); } else if (_report.GraphType == OlapReport.GraphTypeEnum.StackedBarHorizontal) { series.ChangeView(ViewType.StackedBar); rotateGraph = true; } else if (_report.GraphType == OlapReport.GraphTypeEnum.LineHorizontal) { series.ChangeView(ViewType.Line); } series.LegendText = name; series.ShowInLegend = true; series.ValueScaleType = ScaleType.Numerical; series.Visible = true; // labels orientation XYDiagram diag = (XYDiagram)_chCtrl.Diagram; diag.Rotated = rotateGraph; if (rotateGraph) { diag.AxisY.Label.Antialiasing = true; diag.AxisY.Label.Angle = 315; } else { diag.AxisX.Label.Antialiasing = true; diag.AxisX.Label.Angle = 315; } // if scaling if (setScaling) { diag.AxisY.Visible = false; } // if(setScaling) // { // // hide axis, cause it won't display real values // if(seriesPosCount<10) // diag.AxisY.Visible=false; // if(i<10) // { // SecondaryAxisY axisY=new SecondaryAxisY(name); // // axisY.Alignment=AxisAlignment.Near; // axisY.Title.Text = name; // axisY.Title.Visible = true; // axisY.Title.Font=new Font(axisY.Title.Font.Name, 10); // axisY.Label.Antialiasing=true; // axisY.Label.Angle=315; // // diag.SecondaryAxesY.Add(axisY); // ((XYDiagramSeriesViewBase)series.View).AxisY = axisY; // } // } } // prepare scaling ranges double scalingMin = double.MaxValue; double scalingMax = double.MinValue; if (setScaling) { for (int l = 0; l < catPosCount; l++) { string val = (rotateAxes ? _report.Cellset.GetCell(l, i).Value : _report.Cellset.GetCell(i, l).Value); double dVal = 0; double.TryParse(val, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out dVal); if (dVal < scalingMin) { scalingMin = dVal; } if (dVal > scalingMax) { scalingMax = dVal; } } } scalingMin = scalingMin - (scalingMax - scalingMin) * 0.1; // set data for (int l = 0; l < catPosCount; l++) { string argument = ""; for (int m = 0; m < catMemCount; m++) { argument += (m == 0 ? "" : " | ") + (rotateAxes ? _report.Cellset.GetCellsetMember(0, m, l).Name : _report.Cellset.GetCellsetMember(1, m, l).Name); } string val = (rotateAxes ? _report.Cellset.GetCell(l, i).Value : _report.Cellset.GetCell(i, l).Value); string fVal = (rotateAxes ? _report.Cellset.GetCell(l, i).FormattedValue : _report.Cellset.GetCell(i, l).FormattedValue); double dVal = 0; double.TryParse(val, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out dVal); if (setScaling) { dVal = (scalingMax - scalingMin == 0 ? 0 : (scalingMin + dVal) / (scalingMax - scalingMin)); } // custom point label string customLabel = string.Empty; if (!showValues && !showSeries && !showCats) { series.Label.Visible = false; } else { customLabel = (showSeries ? series.Name : string.Empty); customLabel += (showCats ? (customLabel != string.Empty ? " | " : string.Empty) + argument : string.Empty); customLabel += (showValues ? (customLabel != string.Empty ? ": " : string.Empty) + fVal : string.Empty); } CustomChartSeriesPoint sp = new CustomChartSeriesPoint(argument, dVal, customLabel); series.Points.Add(sp); } } ChartTitle title = new ChartTitle(); title.Alignment = StringAlignment.Center; title.Lines = new string[] { _report.Name, _report.Description }; _chCtrl.Titles.Add(title); if (_report.GraphTheme != null && _report.GraphTheme != "") { _chCtrl.AppearanceName = _report.GraphTheme; } _chCtrl.Width = AdjustGraphSize(_report.GraphWidth); _chCtrl.Height = AdjustGraphSize(_report.GraphHeight); string imgNamePrefix = _report.GetType().Name + _report.ID.ToString(); //delete older images of same report string[] filePaths = System.IO.Directory.GetFiles(FI.Common.AppConfig.TempDir, imgNamePrefix + "*.PNG"); if (filePaths != null && filePaths.Length > 0) { for (int j = 0; j < filePaths.Length; j++) { try { System.IO.File.Delete(filePaths[j]); } catch (Exception exc) { //do nothing exc = null; } } } //write to file and display, it will overwite itself if needed string imgName = imgNamePrefix + "." + DateTime.Now.ToString("yyyyMMddHHssfff") + ".PNG"; string imgVirtPath = Request.ApplicationPath + "/" + FI.Common.AppConfig.TempVirtualDir + "/" + imgName; string imgPhysPath = FI.Common.AppConfig.TempDir + @"\" + imgName; _chCtrl.ExportToImage(imgPhysPath, System.Drawing.Imaging.ImageFormat.Png); System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image(); img.ImageUrl = imgVirtPath; this.cellGraph.Controls.Add(img); }
public void LoadGraph() { if(_report.State!=Report.StateEnum.Executed) return; bool rotateGraph=false; bool rotateAxes=((_report.GraphOptions & OlapReport.GraphOptionsEnum.RotateAxes)>0); int seriesPosCount=(rotateAxes ? _report.Cellset.Axis1PosCount: _report.Cellset.Axis0PosCount); int seriesMemCount=(rotateAxes ? _report.Cellset.Axis1TupleMemCount: _report.Cellset.Axis0TupleMemCount); int catPosCount=(rotateAxes ? _report.Cellset.Axis0PosCount: _report.Cellset.Axis1PosCount); int catMemCount=(rotateAxes ? _report.Cellset.Axis0TupleMemCount: _report.Cellset.Axis1TupleMemCount); if(seriesPosCount>256) seriesPosCount=256; if(catPosCount>1024) catPosCount=1024; bool showValues=(_report.GraphOptions & OlapReport.GraphOptionsEnum.ShowValues)>0; bool showSeries=(_report.GraphOptions & OlapReport.GraphOptionsEnum.ShowSeries)>0; bool showCats=(_report.GraphOptions & OlapReport.GraphOptionsEnum.ShowCategories)>0; bool setScaling=(_report.GraphOptions & OlapReport.GraphOptionsEnum.SetScaling)>0; // create series for(int i=0;i<seriesPosCount;i++) { string name=""; for(int j=0; j<seriesMemCount;j++) name+=(j==0 ? "" : " | ")+ (rotateAxes ? _report.Cellset.GetCellsetMember(1, j, i).Name : _report.Cellset.GetCellsetMember(0, j, i).Name); Series series=new Series(); series.Name=name; _chCtrl.Series.Add(series); // type if(_report.GraphType==OlapReport.GraphTypeEnum.Pie) { // limit number of series if(seriesPosCount>6) seriesPosCount=6; // disable scaling for pie setScaling=false; series.ChangeView(ViewType.Pie); PiePointOptions ppo=(PiePointOptions)series.PointOptions; PieSeriesView psw=(PieSeriesView)series.View; PieSeriesLabel psl=(PieSeriesLabel)series.Label; psl.Position=PieSeriesLabelPosition.TwoColumns; series.ShowInLegend=false; // cause it's shown in pie anyway showValues=true; showCats=true; this.chkCat.Checked=true; this.chkCat.Disabled=true; this.chkValues.Checked=true; this.chkValues.Disabled=true; } else { if(_report.GraphType==OlapReport.GraphTypeEnum.BarVertical) { series.ChangeView(ViewType.Bar); } else if(_report.GraphType==OlapReport.GraphTypeEnum.BarHorizontal) { series.ChangeView(ViewType.Bar); rotateGraph=true; } else if(_report.GraphType==OlapReport.GraphTypeEnum.StackedBarVertical) series.ChangeView(ViewType.StackedBar); else if(_report.GraphType==OlapReport.GraphTypeEnum.StackedBarHorizontal) { series.ChangeView(ViewType.StackedBar); rotateGraph=true; } else if(_report.GraphType==OlapReport.GraphTypeEnum.LineHorizontal) series.ChangeView(ViewType.Line); series.LegendText=name; series.ShowInLegend=true; series.ValueScaleType=ScaleType.Numerical; series.Visible=true; // labels orientation XYDiagram diag=(XYDiagram)_chCtrl.Diagram; diag.Rotated=rotateGraph; if(rotateGraph) { diag.AxisY.Label.Antialiasing=true; diag.AxisY.Label.Angle=315; } else { diag.AxisX.Label.Antialiasing=true; diag.AxisX.Label.Angle=315; } // if scaling if(setScaling) diag.AxisY.Visible=false; // if(setScaling) // { // // hide axis, cause it won't display real values // if(seriesPosCount<10) // diag.AxisY.Visible=false; // if(i<10) // { // SecondaryAxisY axisY=new SecondaryAxisY(name); // // axisY.Alignment=AxisAlignment.Near; // axisY.Title.Text = name; // axisY.Title.Visible = true; // axisY.Title.Font=new Font(axisY.Title.Font.Name, 10); // axisY.Label.Antialiasing=true; // axisY.Label.Angle=315; // // diag.SecondaryAxesY.Add(axisY); // ((XYDiagramSeriesViewBase)series.View).AxisY = axisY; // } // } } // prepare scaling ranges double scalingMin=double.MaxValue; double scalingMax=double.MinValue; if(setScaling) { for(int l=0;l<catPosCount;l++) { string val=(rotateAxes ? _report.Cellset.GetCell(l, i).Value : _report.Cellset.GetCell(i, l).Value); double dVal=0; double.TryParse(val, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out dVal); if(dVal<scalingMin) scalingMin=dVal; if(dVal>scalingMax) scalingMax=dVal; } } scalingMin=scalingMin-(scalingMax-scalingMin)*0.1; // set data for(int l=0; l<catPosCount;l++) { string argument=""; for(int m=0;m<catMemCount;m++) argument+=(m==0 ? "" : " | ")+ (rotateAxes ? _report.Cellset.GetCellsetMember(0, m, l).Name : _report.Cellset.GetCellsetMember(1, m, l).Name); string val=(rotateAxes ? _report.Cellset.GetCell(l, i).Value : _report.Cellset.GetCell(i, l).Value); string fVal=(rotateAxes ? _report.Cellset.GetCell(l, i).FormattedValue : _report.Cellset.GetCell(i, l).FormattedValue); double dVal=0; double.TryParse(val, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out dVal); if(setScaling) dVal=(scalingMax-scalingMin==0 ? 0 : (scalingMin+dVal)/(scalingMax-scalingMin)); // custom point label string customLabel=string.Empty; if(!showValues && !showSeries&& !showCats) series.Label.Visible=false; else { customLabel=(showSeries ? series.Name : string.Empty); customLabel+=(showCats ? (customLabel!=string.Empty ? " | " : string.Empty) + argument : string.Empty); customLabel+=(showValues ? (customLabel!=string.Empty ? ": " : string.Empty) + fVal : string.Empty); } CustomChartSeriesPoint sp=new CustomChartSeriesPoint(argument, dVal, customLabel); series.Points.Add(sp); } } ChartTitle title=new ChartTitle(); title.Alignment=StringAlignment.Center; title.Lines=new string[]{ _report.Name, _report.Description }; _chCtrl.Titles.Add(title); if(_report.GraphTheme!=null && _report.GraphTheme!="") _chCtrl.AppearanceName=_report.GraphTheme; _chCtrl.Width=AdjustGraphSize(_report.GraphWidth); _chCtrl.Height=AdjustGraphSize(_report.GraphHeight); string imgNamePrefix=_report.GetType().Name + _report.ID.ToString(); //delete older images of same report string[] filePaths=System.IO.Directory.GetFiles(FI.Common.AppConfig.TempDir , imgNamePrefix + "*.PNG"); if(filePaths!=null && filePaths.Length>0) for(int j=0;j<filePaths.Length;j++) { try { System.IO.File.Delete(filePaths[j]); } catch(Exception exc) { //do nothing exc=null; } } //write to file and display, it will overwite itself if needed string imgName=imgNamePrefix + "." + DateTime.Now.ToString("yyyyMMddHHssfff") + ".PNG"; string imgVirtPath=Request.ApplicationPath + "/" + FI.Common.AppConfig.TempVirtualDir + "/" + imgName; string imgPhysPath=FI.Common.AppConfig.TempDir + @"\" + imgName; _chCtrl.ExportToImage(imgPhysPath, System.Drawing.Imaging.ImageFormat.Png); System.Web.UI.WebControls.Image img=new System.Web.UI.WebControls.Image(); img.ImageUrl=imgVirtPath; this.cellGraph.Controls.Add(img); }