Esempio n. 1
0
        protected override string ReplaceValuesInChartInSlide(ChartPart chartPart, string categoryTitle, int nSerie)
        {
            ChartSpace chartSpace = chartPart.ChartSpace;

            GraficoBarre myBarre = new GraficoBarre2d();

            myBarre.BarChartSpace = chartSpace;
            myBarre.getBarre();

            if (myBarre.Barre != null)
            {
                BarChartSeries barChartSeries1 = myBarre.barChartSeries1;

                SeriesText       seriesText1;
                CategoryAxisData categoryAxisData1;
                Values           values1;

                modificaChartData("0,0", "", out seriesText1, out categoryAxisData1, out values1);

                barChartSeries1.SeriesText = seriesText1;
                barChartSeries1.Append(categoryAxisData1);
                barChartSeries1.Append(values1);

                return("ok");
            }
            else
            {
                return("non trovo il grafico a barre!");
            }
        }
Esempio n. 2
0
        //竖状柱状图+曲线图
        public string ChartTypeColumnClustered2(string strDataName, string data1, string data2, string data3, string data4, string caption)
        {
            var mychartSpace = new ChartSpace();
            var mychart = mychartSpace.Charts.Add(0);
            mychart.HasLegend = false;
            mychart.HasTitle = true;
            mychart.Title.Caption = caption;

            var chart1 = mychart.SeriesCollection.Add(0);
            chart1.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
            chart1.SetData(DimCategories,DataLiteral, strDataName);
            chart1.SetData(DimValues, DataLiteral, data1);
            chart1.DataLabelsCollection.Add().HasValue = true;

            var chSeries1 = mychart.SeriesCollection.Add(0);
            chSeries1.Type = ChartChartTypeEnum.chChartTypeSmoothLine;
            chSeries1.SetData(DimValues, DataLiteral, data2);

            var chSeries2 = mychart.SeriesCollection.Add(0);
            chSeries2.Type = ChartChartTypeEnum.chChartTypeSmoothLine;
            chSeries2.SetData(DimValues, DataLiteral, data3);

            var chSeries3 = mychart.SeriesCollection.Add(0);
            chSeries3.Type = ChartChartTypeEnum.chChartTypeSmoothLine;
            chSeries3.SetData(DimValues, DataLiteral, data4);

            var image = UrlPath("柱状曲线图");
            mychartSpace.ExportPicture(image, "GIF", 400, 300);
            return image;
        }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //创建图表控件
        ChartSpace laySpace = new ChartSpace();
        //添加一个表容器
        SpreadsheetClass myexcel = new SpreadsheetClass();
        Worksheet        mysheet = myexcel.ActiveSheet;

        //添加表标题
        myexcel.Cells[1, 1] = "籍贯";
        myexcel.Cells[1, 2] = "人数";
        //连接数据库
        String        str = ConfigurationManager.ConnectionStrings["connection"].ConnectionString.ToString();
        SqlConnection con = new SqlConnection(str);

        con.Open();
        String         sel  = "select jiguan,count(jiguan) as number from xx group by jiguan";
        SqlDataAdapter adsa = new SqlDataAdapter(sel, con);
        DataSet        adds = new DataSet();

        adsa.Fill(adds);
        if (adds.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < adds.Tables[0].Rows.Count; i++)
            {
                mysheet.Cells[i + 2, 1] = adds.Tables[0].Rows[i][0].ToString();
                mysheet.Cells[i + 2, 2] = adds.Tables[0].Rows[i][1].ToString();
            }
            //导出表格
            myexcel.Export(Server.MapPath(".") + @"\test.xls", SheetExportActionEnum.ssExportActionOpenInExcel, SheetExportFormat.ssExportXMLSpreadsheet);
        }
        con.Close();
    }
Esempio n. 4
0
  }//Page_Load()

  ///<summary>ChartPie</summary>
  public void ChartPie()
  {
   string      exceptionMessage  =  null;

   ChartSpace  chartSpace        =  null;
   ChChart     chChart           =  null;
   
   try
   {
    
    //First create a ChartSpace object to hold the chart
    chartSpace = new ChartSpaceClass();
   
    //Add a chart and provide a type
    chChart = chartSpace.Charts.Add(0);
    chChart.Type = ChartChartTypeEnum.chChartTypePie3D;

    //add chart titles and legend
    chChart.HasTitle                 =  true;
    chChart.Title.Caption            =  "Office Web Components (OWC) Pie";
    chChart.HasLegend                =  true;
    chChart.Legend.Border.DashStyle  =  OWCTypeLib.ChartLineDashStyleEnum.chLineDash;
    chChart.Legend.Position          =  OWCTypeLib.ChartLegendPositionEnum.chLegendPositionRight;
   
    //Add a series to the chart's series collection
    chChart.SeriesCollection.Add(0);
   
    //load the GraphCategory and GraphValue data
    chChart.SeriesCollection[0].SetData 
    (
     ChartDimensionsEnum.chDimCategories,
     ( int ) ChartSpecialDataSourcesEnum.chDataLiteral, 
     string.Join( ",", GraphCategory )
    );
   
    chChart.SeriesCollection[0].SetData 
    (
     ChartDimensionsEnum.chDimValues,
     ( int ) ChartSpecialDataSourcesEnum.chDataLiteral,
     string.Join( ",", Array.ConvertAll<double, string>( GraphValue, ConvertDoubleString ) )
    );

    //chartSpace.ExportPicture( FilenameImage, "gif", 500, 400 );
    
    //show the chart on the client
    Response.ContentType= "image/gif";
    Response.BinaryWrite( ( byte[] ) chartSpace.GetPicture( "gif", 500, 400 ) ); 
    Response.End();
  
   }
   catch ( Exception exception )
   {
   	exceptionMessage = exception.Message;
   }
   if ( exceptionMessage != null )
   {
   	Response.Write( exceptionMessage );
   }
  }//ChartPie()
Esempio n. 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //创建图表控件
        ChartSpace myspace = new ChartSpace();
        //添加一个图表对象
        ChChart mychart = myspace.Charts.Add(0);

        //设置图表类型为柱形
        mychart.Type = ChartChartTypeEnum.chChartTypePie;
        //设置图表的相关属性
        mychart.HasLegend     = true;     //添加图列
        mychart.HasTitle      = true;     //添加主题
        mychart.Title.Caption = "员工信息图表"; //设置主题内容
        //连接数据库
        String        str = ConfigurationManager.ConnectionStrings["connection"].ConnectionString.ToString();
        SqlConnection con = new SqlConnection(str);

        con.Open();
        String         sel  = "select jiguan,count(jiguan) as number from xx group by jiguan";
        SqlDataAdapter adsa = new SqlDataAdapter(sel, con);
        DataSet        adds = new DataSet();

        adsa.Fill(adds);
        if (adds.Tables[0].Rows.Count > 0)
        {
            string strDataName = "";
            string strData     = "";
            //添加图表块
            mychart.SeriesCollection.Add(0);
            //添加图表数据
            for (int j = 0; j < adds.Tables[0].Rows.Count; j++)
            {
                if (j == adds.Tables[0].Rows.Count - 1)
                {
                    strDataName += adds.Tables[0].Rows[j][0].ToString();
                }
                else
                {
                    strDataName += adds.Tables[0].Rows[j][0].ToString() + "\t";
                }
                strData += adds.Tables[0].Rows[j][1].ToString() + "\t";
            }
            //设置图表的属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strData);
            //设置百分比
            ChDataLabels labels = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            labels.HasPercentage = true;
        }
        con.Close();
        myspace.ExportPicture(Server.MapPath(".") + @"\temp.jpg", "jpg", 600, 450);
    }
        /// <summary>
        /// Modify the worksheet (embedded into chart) range values
        /// </summary>
        /// <param name="result">The DataTable instance represent a table</param>
        protected void ModifyChartRange(System.Data.DataTable result)
        {
            ChartSpace chartspace = chart_part.ChartSpace;

            for (int i = 1; i < result.Columns.Count; i++)
            {
                BarChartSeries barchart_series = chart_part.ChartSpace.Descendants <BarChartSeries>().Where(s => string.Compare(s.InnerText, worksheet_name + "!$" + GetColumnIndexByNum(i) + "$1", true) > 0).First();
                DocumentFormat.OpenXml.Drawing.Charts.Values val = barchart_series.Descendants <DocumentFormat.OpenXml.Drawing.Charts.Values>().FirstOrDefault();
                NumberReference nr = val.Descendants <NumberReference>().First();
                DocumentFormat.OpenXml.Drawing.Charts.Formula f = nr.Descendants <DocumentFormat.OpenXml.Drawing.Charts.Formula>().First();

                f.Text = worksheet_name + "!$" + GetColumnIndexByNum(i) + "$2:$" + GetColumnIndexByNum(i) + "$" + GetRowIndexByNum(result.Rows.Count - 1);
            }
        }
Esempio n. 7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //创建ChartSpace对象来放置图表
        ChartSpace laySpace = new ChartSpace();
        //在ChartSpace对象中添加图表
        ChChart InsertChart = laySpace.Charts.Add(0);

        //指定绘制图表类型
        InsertChart.Type = ChartChartTypeEnum.chChartTypeLine;//折线图
        //指定图表是否需要图例标注
        InsertChart.HasLegend     = false;
        InsertChart.HasTitle      = true;//为图表添加标题
        InsertChart.Title.Caption = "员工信息表";
        //为x,y轴添加图示说明
        InsertChart.Axes[0].HasTitle      = true;
        InsertChart.Axes[0].Title.Caption = "籍贯";
        InsertChart.Axes[1].HasTitle      = true;
        InsertChart.Axes[1].Title.Caption = "人数";
        //连接数据库
        String        str = ConfigurationManager.ConnectionStrings["connection"].ConnectionString.ToString();
        SqlConnection con = new SqlConnection(str);

        con.Open();
        String         sel  = "select jiguan,count(jiguan) as number from xx group by jiguan";
        SqlDataAdapter adsa = new SqlDataAdapter(sel, con);
        DataSet        adds = new DataSet();

        adsa.Fill(adds);
        //为x,y轴指定特定字符串,以便显示数据
        string strXdata = String.Empty;
        string strYdata = String.Empty;

        if (adds.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < adds.Tables[0].Rows.Count; i++)
            {
                strXdata = strXdata + adds.Tables[0].Rows[i][0].ToString() + "\t";
                strYdata = strYdata + adds.Tables[0].Rows[i][1].ToString() + "\t";
            }
        }
        //添加图表块
        InsertChart.SeriesCollection.Add(0);
        //设置图表的属性
        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata);
        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);
        con.Close();
        laySpace.ExportPicture(Server.MapPath(".") + @"\temp.jpg", "jpg", 600, 450);
    }
Esempio n. 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //创建图表控件
        ChartSpace myspace = new ChartSpace();
        //添加一个图表对象
        ChChart mychart = myspace.Charts.Add(0);

        //设置图表类型为柱形
        mychart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
        //设置图表的相关属性
        mychart.HasLegend     = true;     //添加图列
        mychart.HasTitle      = true;     //添加主题
        mychart.Title.Caption = "员工信息图表"; //设置主题内容
        //设置x,y轴
        mychart.Axes[0].HasTitle      = true;
        mychart.Axes[0].Title.Caption = "籍贯";
        mychart.Axes[1].HasTitle      = true;
        mychart.Axes[1].Title.Caption = "人数";
        //连接数据库
        String        str = ConfigurationManager.ConnectionStrings["connection"].ConnectionString.ToString();
        SqlConnection con = new SqlConnection(str);

        con.Open();
        String         sel  = "select jiguan,count(jiguan) as number from xx group by jiguan";
        SqlDataAdapter adsa = new SqlDataAdapter(sel, con);
        DataSet        adds = new DataSet();

        adsa.Fill(adds);
        if (adds.Tables[0].Rows.Count > 0)
        {
            //添加图表块
            for (int i = 0; i < adds.Tables[0].Rows.Count; i++)
            {
                mychart.SeriesCollection.Add(0);
            }
            for (int j = 0; j < adds.Tables[0].Rows.Count; j++)
            {
                //设置图表的属性
                mychart.SeriesCollection[j].Caption = adds.Tables[0].Rows[j][0].ToString();
                mychart.SeriesCollection[j].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, adds.Tables[0].Rows[j][0].ToString());
                mychart.SeriesCollection[j].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Convert.ToInt32(adds.Tables[0].Rows[j][1].ToString()));
            }
        }
        con.Close();
        myspace.ExportPicture(Server.MapPath(".") + @"\temp.jpg", "jpg", 600, 450);
    }
    protected string DrawChart(string DrawType, string[] AllDepartment, string[] AllDataRote, string Range)
    {
        string strXdata = string.Empty;

        for (int i = 0; i < AllDepartment.Length; i++)
        {
            strXdata += AllDepartment[i] + "\r" + DrawType + AllDataRote[i] + "\t";
        }
        string strYdata = string.Empty;

        foreach (string strValue in AllDataRote)
        {
            strYdata += strValue + "\t";
        }

        ChartSpace laySpace    = new ChartSpace();
        ChChart    InsertChart = laySpace.Charts.Add(0);

        InsertChart.Type      = ChartChartTypeEnum.chChartTypeColumnClustered;
        InsertChart.HasLegend = false;

        InsertChart.HasTitle      = true;
        InsertChart.Title.Caption = "第" + Range + "周各系部学生【" + DrawType + "】对比图";

        InsertChart.Axes[0].HasTitle      = true;
        InsertChart.Axes[0].Title.Caption = "系部";
        InsertChart.Axes[1].HasTitle      = true;
        InsertChart.Axes[1].Title.Caption = DrawType;

        InsertChart.SeriesCollection.Add(0);
        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, "图例1");
        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata);
        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);

        string strAbsolutePath = (Server.MapPath(".")) + "\\" + DrawType + ".gif";

        laySpace.ExportPicture(strAbsolutePath, "GIF", 1730, 400);

        string strRelativePath = "./" + DrawType + ".gif";
        Random rd          = new Random();
        string strImageTag = "<IMG SRC='" + strRelativePath + "?id=" + rd.Next(65500) + "'>";
        string url         = "DepartmentEachCompare.aspx?ImageUrl=" + strImageTag;

        return(strImageTag);
    }
Esempio n. 10
0
        public IPieChart InsertPieChart()
        {
            ChartSpace chartSpace = this.chartPart.ChartSpace;
            Chart      chart      = chartSpace.GetFirstChild <Chart>() ?? chartSpace.AppendChild(new Chart());
            PlotArea   plotArea   = chart.PlotArea ?? (chart.PlotArea = new PlotArea());

            return(new OpenXmlPieChart(
                       this,
                       plotArea.AppendChild(
                           new DoughnutChart()
                           .AppendChildFluent(new PieChartSeries()
            {
                Index = new Index()
                {
                    Val = 0
                }
            })
                           )
                       ));
        }
Esempio n. 11
0
        public IBarChart InsertBarChart(CartesianAxes axes)
        {
            ChartSpace chartSpace = this.chartPart.ChartSpace;
            Chart      chart      = chartSpace.GetFirstChild <Chart>() ?? chartSpace.AppendChild(new Chart());
            PlotArea   plotArea   = chart.PlotArea ?? (chart.PlotArea = new PlotArea());

            return(new OpenXmlBarChart(
                       this,
                       plotArea.AppendChild(
                           new BarChart()
                           .AppendChildFluent(new AxisId()
            {
                Val = axes.CategoryAxis.Id
            })
                           .AppendChildFluent(new AxisId()
            {
                Val = axes.ValueAxis.Id
            })
                           )
                       ));
        }
Esempio n. 12
0
        public ILineChart InsertLineChart(CartesianAxes axes)
        {
            ChartSpace chartSpace = this.chartPart.ChartSpace;
            Chart      chart      = chartSpace.GetFirstChild <Chart>() ?? chartSpace.AppendChild(new Chart());
            PlotArea   plotArea   = chart.PlotArea ?? (chart.PlotArea = new PlotArea());

            Marker marker = new Marker();

            marker.SetAttribute(new DocumentFormat.OpenXml.OpenXmlAttribute("Val", marker.NamespaceUri, "1"));

            return(new OpenXmlLineChart(
                       this,
                       plotArea.AppendChild(
                           new LineChart()
                           .AppendChildFluent(new Grouping()
            {
                Val = GroupingValues.Standard
            })
                           .AppendChildFluent(new VaryColors()
            {
                Val = true
            })
                           .AppendChildFluent(new Marker())
                           .AppendChildFluent(new Smooth()
            {
                Val = false
            })
                           .AppendChildFluent(new AxisId()
            {
                Val = axes.CategoryAxis.Id
            })
                           .AppendChildFluent(new AxisId()
            {
                Val = axes.ValueAxis.Id
            })
                           )
                       ));
        }
Esempio n. 13
0
        //竖状柱状图--叠加--
        public string ChartTypeColumnClustered3(string strDataName, Dictionary<string, string> list, string caption)
        {
            var mychartSpace = new ChartSpace();
            var mychart = mychartSpace.Charts.Add(0);
            mychart.Type = ChartChartTypeEnum.chChartTypeColumnStacked;
            mychart.HasLegend = true;
            mychart.HasTitle = true;
            mychart.Title.Caption = caption;
            mychart.Axes[1].NumberFormat = "0%";
            foreach (var dic in list)
            {
                var keys = mychart.SeriesCollection.Add(0);
                keys.SetData(DimValues, DataLiteral, dic.Value);
                //keys.DataLabelsCollection.Add().HasValue = true;
                keys.Caption = dic.Key;
                keys.DataLabelsCollection.Add().NumberFormat = "0.0%";
            }
            mychart.SeriesCollection[0].SetData(DimCategories, DataLiteral, strDataName);

            var image = UrlPath("柱状叠加图");
            mychartSpace.ExportPicture(image, "GIF", 400, 300);
            return image;
        }
    //---------------------------------------------------------------------------
    protected void DrawSlide_Nineteen()
    {
        PowerPoint.Slide slide;
         for (int i = 0; i < segmentNumber; i++)
         {
             DataSet ds_operation = getOperation(alSegment[i].ToString());
             if (ds_operation.Tables.Count > 0 && ds_operation.Tables[0].Rows.Count > 0)
             {
                 int numOfSegment = ds_operation.Tables[0].Rows.Count / 2;
                 int count = 0;
                 for (int j = 0; j < numOfSegment + (ds_operation.Tables[0].Rows.Count % 2 == 0 ? 0 : 1); j++)
                 {
                     float x = 60;
                     float x1 = 70;
                     slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
                     slide = slides[slideIndex];
                     UniformLayout(slide, alSegment[i].ToString().Trim() + " Sales By Operation by Product 2011 vs 2010");
                     int chartNum = 2;
                     if (j == numOfSegment)
                         chartNum = ds_operation.Tables[0].Rows.Count % 2;
                     bool slideIsNull = true;
                     for (int k = 0; k < chartNum; k++)
                     {
                         ChartSpace objSpace = new ChartSpace();
                         ChChart objChart = objSpace.Charts.Add(0);
                         objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
                         DataSet ds = getSlide_Nineteen(alSegment[i].ToString(), ds_operation.Tables[0].Rows[count][0].ToString());
                         DataSet dsAdd = getSlide_NineteenAdd(alSegment[i].ToString(), ds_operation.Tables[0].Rows[count][0].ToString());
                         objChart.HasTitle = true;
                         objChart.HasLegend = true;
                         objChart.Title.Font.Size = 12;
                         objChart.Title.Font.Bold = true;
                         objChart.Title.Caption = ds_operation.Tables[0].Rows[count][1].ToString();
                         count++;
                         if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                         {
                             slideIsNull = false;
                             string dimCategories = "";
                             for (int l = 1; l < ds.Tables[0].Columns.Count; l++)
                             {
                                 dimCategories += ds.Tables[0].Columns[l].ColumnName + "\t";
                             }
                             dimCategories = dimCategories.Substring(0, dimCategories.Length - 1);
                             for (int r = 0; r < ds.Tables[0].Rows.Count; r++)
                             {
                                 string dimValues = "";
                                 for (int n = 1; n < ds.Tables[0].Columns.Count; n++)
                                 {
                                     var num1 = ds.Tables[0].Rows[r][n];
                                     if (dsAdd != null && dsAdd.Tables.Count > 0 && dsAdd.Tables[0].Rows.Count > 0)
                                     {
                                         var num2 = dsAdd.Tables[0].Rows[r][n];
                                         dimValues += Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2) + "\t";
                                     }
                                     else
                                         dimValues += Convert.ToDouble(num1 is DBNull ? 0 : num1) + "\t";
                                 }
                                 dimValues = dimValues.Substring(0, dimValues.Length - 1);
                                 objChart.SeriesCollection.Add(r);
                                 objChart.SeriesCollection[r].Caption = ds.Tables[0].Rows[r][0].ToString();
                                 objSpace.Charts[0].SeriesCollection[r].SetData(ChartDimensionsEnum.chDimCategories,
                                        +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimCategories);
                                 objSpace.Charts[0].SeriesCollection[r].SetData(ChartDimensionsEnum.chDimValues,
                                         +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
                             }
                         }
                         objSpace.ExportPicture(picturePath, "GIF", 320, 160);
                         picturePath = pictureFolderPath + pictureName;
                         InsertPicture(slide, picturePath, x, 80, 300, 180);

                         int rowCount = ds.Tables[0].Rows.Count;
                         int columnCount = ds.Tables[0].Columns.Count;
                         PowerPoint.Shape shape = slide.Shapes.AddTable(rowCount + 1, columnCount, 385, 300, 700, 200);

                         for (int s = 0; s < rowCount + 1; s++)
                         {
                             for (int t = 0; t < columnCount; t++)
                             {
                                 PowerPoint.TextFrame textF = shape.Table.Cell(s + 1, t + 1).Shape.TextFrame;
                                 textF.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
                                 PowerPoint.TextRange textR = textF.TextRange;
                                 textR.Font.Bold = MsoTriState.msoTrue;
                                 textR.Font.Size = 4;
                                 if (s == 0)
                                 {
                                     textR.Text = ds.Tables[0].Columns[t].ColumnName;
                                 }
                                 else
                                 {
                                     if (t == 0)
                                     {
                                         var num1 = ds.Tables[0].Rows[s - 1][t];
                                         textR.Text = num1.ToString();
                                     }
                                     else
                                     {
                                         var num1 = ds.Tables[0].Rows[s - 1][t];
                                         if (dsAdd != null && dsAdd.Tables.Count > 0 && dsAdd.Tables[0].Rows.Count > 0)
                                         {
                                             var num2 = dsAdd.Tables[0].Rows[s - 1][t];
                                             textR.Text = (Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2)).ToString();
                                         }
                                         else
                                             textR.Text = (Convert.ToDouble(num1 is DBNull ? 0 : num1)).ToString();
                                     }
                                 }
                             }
                         }
                         shape.Export(picturePath, Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatGIF, 480, 240, Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY);
                         shape.Delete();
                         InsertPicture(slide, picturePath, x1, 340, 240, 120);
                         x = 380;
                         x1 = 410;
                     }
                     if (slideIsNull == true)
                         --slideIndex;
                 }
             }
         }
    }
    //--------------------------------------------------------------------------
    protected void DrawSlide_Fourteen()
    {
        slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
         PowerPoint.Slide slide = slides[slideIndex];
         UniformLayout(slide, "HP " + meeting.getpreyear().Trim() + "-" + meeting.getnextyear().Substring(2, 2) + " Bookings");
         InsertText(slide, "5 Top Countries CL & IN ", 205, 50, 280, 35, 24);
         string dimCategories = meeting.getpreyear().Substring(2, 2) + "\t" + meeting.getyear().Substring(2, 2) + "\t" + meeting.getnextyear().Substring(2, 2);

         DataSet ds = getSlide_Fourteen();
         if (ds == null)
             return;
         if (ds.Tables[0].Rows.Count == 0)
             return;
         int x = 22;
         string[] color = { "goldenrod", "deepskyblue", "forestgreen", "maroon", "yellow", "blue" };
         double[] total = { 0, 0, 0 };
         for (int i = 0; i < 6; i++)
         {
             string dimValues = "";
             ChartSpace objSpace = new ChartSpace();
             ChChart objChart = objSpace.Charts.Add(0);
             objChart.Type = ChartChartTypeEnum.chChartTypeAreaStacked;
             objChart.HasTitle = true;
             objChart.Title.Caption = ds.Tables[0].Columns[i + 1].ColumnName;
             objChart.Title.Font.Size = 12;
             objChart.Title.Font.Bold = true;
             if (i != 5)
             {
                 for (int j = 0; j < 3; j++)
                 {
                     var num = ds.Tables[0].Rows[j][i + 1];
                     dimValues += (num is DBNull ? 0 : num).ToString() + "\t";
                     total[j] += (num is DBNull ? 0 : (double)num);
                 }
             }
             else
             {
                 for (int j = 0; j < 3; j++)
                 {
                     var num = ds.Tables[0].Rows[j][i + 1];
                     dimValues += ((num is DBNull ? 0 : (double)num) - total[j]).ToString() + "\t";
                 }
             }
             dimValues = dimValues.Substring(0, dimValues.Length - 1);
             objChart.Border.Color = "black";
             objChart.Interior.Color = "mediumturquoise";
             objChart.PlotArea.Interior.Color = "white";
             objChart.SeriesCollection.Add(0);
             objChart.SeriesCollection[0].Interior.Color = color[i];
             objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                        +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimCategories);
             objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                     +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
             objSpace.ExportPicture(picturePath, "GIF", 115, 170);
             picturePath = pictureFolderPath + pictureName;
             InsertPicture(slide, picturePath, x, 160, 115, 170);
             x += 113;
         }
    }
    //--------------------------------------------------------------------------
    protected void DrawSlide_eleven()
    {
        PowerPoint.Slide slide = slides[++slideIndex];
         UniformLayout(slide, "ET HP " + meeting.getyear() + " Actual," + meeting.getnextyear() + "Forecast");
         DataSet ds = getSlide_eleven();
         if (ds.Tables[0].Rows.Count == 0)
             return;
         float x = 0;
         float y = 0;
         string dimValues = "";
         for (int i = 0; i < 3; i++)
         {
             switch (i)
             {
                 case 0:
                     x = 55;
                     y = 80;
                     break;
                 case 1:
                     x = 485;
                     y = 80;
                     break;
                 case 2:
                     x = 55;
                     y = 300;
                     break;
             }
             ChartSpace objSpace = new ChartSpace();
             ChChart objChart = objSpace.Charts.Add(0);
             objChart.Type = ChartChartTypeEnum.chChartTypePie3D;
             objChart.HasTitle = true;
             objChart.Title.Font.Size = 12;
             objChart.Title.Font.Bold = true;
             objChart.Title.Caption = "Booking " + ds.Tables[0].Columns[i + 1].ColumnName;
             objChart.HasLegend = true;
             objChart.SeriesCollection.Add(0);
             objChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;

             for (int k = 0; k < ds.Tables[0].Rows.Count; k++)
             {
                 var num = ds.Tables[0].Rows[k][i + 1];
                 double num1 = (num is DBNull ? 0 : (double)num);
                 if (alSegment.Count < ds.Tables[0].Rows.Count - 1)
                     dimValues += String.Format("{0:F}", (100 * num1 / (double)ds.Tables[0].Rows[alSegment.Count][i + 1])) + "\t";
                 else
                     return;
             }
             dimValues = dimValues.Substring(0, dimValues.Length - 1);
             salesGap = dimValues;
             objChart.SeriesCollection[0].DataLabelsCollection.Add();
             objChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
             objChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
             objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimSegmentCategories);
             objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                    +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
             dimValues = "";
             objSpace.ExportPicture(picturePath, "GIF", 180, 180);
             picturePath = pictureFolderPath + pictureName;
             InsertPicture(slide, picturePath, x, y, 180, 180);
         }

         ChartSpace objSpace1 = new ChartSpace();
         ChChart objChart1 = objSpace1.Charts.Add(0);
         objChart1.Type = ChartChartTypeEnum.chChartTypeColumnStacked;
         objChart1.HasTitle = true;
         objChart1.HasLegend = true;
         objChart1.Title.Caption = "Bookings " + meeting.getnextyear().Substring(2, 2).Trim() + " Gap";
         for (int k = 0; k < segmentNumber; k++)
         {
             string dimValues1 = "";
             for (int l = 0; l < segmentNumber; l++)
             {
                 if (l == k)
                 {
                     var num = ds.Tables[0].Rows[k][4];
                     dimValues1 += (num is DBNull ? 0 : (double)num).ToString() + "\t";
                 }
                 else
                     dimValues1 += "0\t";
             }
             dimValues1 = dimValues1.Substring(0, dimValues1.Length - 1);
             objChart1.SeriesCollection.Add(k);
             objChart1.SeriesCollection[k].Caption = alSegment[k].ToString();
             objSpace1.Charts[0].SeriesCollection[k].SetData(ChartDimensionsEnum.chDimCategories,
                    +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimSegmentCategories);
             objSpace1.Charts[0].SeriesCollection[k].SetData(ChartDimensionsEnum.chDimValues,
                    +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues1);
         }
         objSpace1.ExportPicture(picturePath, "GIF", 180, 180);
         picturePath = pictureFolderPath + pictureName;
         InsertPicture(slide, picturePath, 485, 300, 180, 180);
         int rowCount = ds.Tables[0].Rows.Count;
         int columnCount = ds.Tables[0].Columns.Count;

         PowerPoint.Shape shape = slide.Shapes.AddTable(rowCount + 1, columnCount, 385, 300, 700, 200);

         shape.Fill.BackColor.SchemeColor = PowerPoint.PpColorSchemeIndex.ppBackground;
         for (int s = 0; s < rowCount + 1; s++)
         {
             for (int t = 0; t < columnCount; t++)
             {
                 PowerPoint.TextFrame textF = shape.Table.Cell(s + 1, t + 1).Shape.TextFrame;
                 PowerPoint.TextRange textR = textF.TextRange;
                 textR.Font.Bold = MsoTriState.msoFalse;
                 textR.Font.Size = 4;

                 if (s == 0)
                 {
                     textR.Text = ds.Tables[0].Columns[t].ColumnName;
                 }
                 else
                 {
                     var num = ds.Tables[0].Rows[s - 1][t];

                     textR.Text = (num is DBNull ? 0 : num).ToString();
                 }
             }
         }
         shape.Export(picturePath, Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatGIF, 400, 200, Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY);
         shape.Delete();
         InsertPicture(slide, picturePath, 240, 230, 240, 120);
    }
    //------------------------------------------------------------
    //protected void DrawSlide_TwentySeven(PowerPoint.Slide slide)
    //{
    //    UniformLayout(slide, "2009  & 2010 FCST Booking by Sales Organization");
    //}
    //------------------------------------------------------------
    protected void DrawSlide_TwentySeven()
    {
        PowerPoint.Slide slide;
         int num = segmentNumber / 2;
         int count = 0;

         for (int i = 0; i < segmentNumber / 2 + (segmentNumber % 2 == 0 ? 0 : 1); i++)
         {
             bool slideIsNull = true;
             int chartNum = 2;
             if (i == num)
                 chartNum = segmentNumber / 2;
             slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
             slide = slides[slideIndex];
             UniformLayout(slide, "2010 Bookings by Sales Organization 2010 vs 2011");

             for (int j = 0; j < chartNum; j++)
             {

                 DataSet ds = getSlide_TwentySeven(alSegment[count].ToString());
                 DataSet dsAdd = getSlide_TwentySevenAdd(alSegment[count].ToString());
                 count++;
                 float x = 80;
                 //float x1 = 100;
                 if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                 {
                     slideIsNull = false;
                     ChartSpace objSpace = new ChartSpace();
                     ChChart objChart = objSpace.Charts.Add(0);
                     objChart.HasTitle = true;
                     objChart.HasLegend = true;
                     objChart.Title.Font.Size = 12;
                     objChart.Title.Font.Bold = true;
                     objChart.Title.Caption = alSegment[count - 1].ToString();

                     objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
                     for (int k = 0; k < ds.Tables[0].Rows.Count; k++)
                     {
                         string dimCategories = "";
                         string dimValues = "";
                         for (int m = 0; m < alSalesOrg.Count; m++)
                         {
                             dimCategories += alSalesOrg[m].ToString() + "\t";
                         }
                         for (int s = 1; s < ds.Tables[0].Columns.Count; s++)
                         {
                             var num1 = ds.Tables[0].Rows[k][s];
                             var num2 = dsAdd.Tables[0].Rows[k][s];
                             dimValues += Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2) + "\t";
                         }
                         dimCategories = dimCategories.Substring(0, dimCategories.Length - 1);
                         dimValues = dimValues.Substring(0, dimValues.Length - 1);
                         objChart.SeriesCollection.Add(k);
                         objChart.SeriesCollection[k].Caption = ds.Tables[0].Rows[k][0].ToString();
                         objSpace.Charts[0].SeriesCollection[k].SetData(ChartDimensionsEnum.chDimCategories,
                                +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimCategories);
                         objSpace.Charts[0].SeriesCollection[k].SetData(ChartDimensionsEnum.chDimValues,
                                 +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
                     }
                     int w = ds.Tables[0].Columns.Count * 40;
                     int h = ds.Tables[0].Columns.Count * 18;
                     objSpace.ExportPicture(picturePath, "GIF", w, 160);
                     picturePath = pictureFolderPath + pictureName;
                     InsertPicture(slide, picturePath, x, 80, w, 180);

                     int rowCount = ds.Tables[0].Rows.Count;
                     int columnCount = ds.Tables[0].Columns.Count;
                     PowerPoint.Shape shape = slide.Shapes.AddTable(rowCount + 1, columnCount, 385, 300, 700, 200);

                     for (int s = 0; s < rowCount + 1; s++)
                     {
                         for (int t = 0; t < columnCount; t++)
                         {
                             PowerPoint.TextFrame textF = shape.Table.Cell(s + 1, t + 1).Shape.TextFrame;
                             textF.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
                             PowerPoint.TextRange textR = textF.TextRange;
                             textR.Font.Bold = MsoTriState.msoTrue;
                             textR.Font.Size = 4;
                             if (s == 0)
                             {
                                 textR.Text = ds.Tables[0].Columns[t].ColumnName;
                             }
                             else
                             {
                                 if (t == 0)
                                 {
                                     var num1 = ds.Tables[0].Rows[s - 1][t];
                                     textR.Text = num1.ToString();
                                 }
                                 else
                                 {
                                     var num1 = ds.Tables[0].Rows[s - 1][t];
                                     var num2 = dsAdd.Tables[0].Rows[s - 1][t];
                                     textR.Text = (Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2)).ToString();
                                 }
                             }
                         }
                     }
                     shape.Export(picturePath, Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatGIF, w, h, Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY);
                     shape.Delete();
                     InsertPicture(slide, picturePath, x + 20, 340, w - 40, 120);
                     x = 380;
                 }

             }
             if (slideIsNull == true)
                 --slideIndex;
         }
    }
    //----------------------------------------------------------
    protected void DrawSlide_Thirteen()
    {
        slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
         PowerPoint.Slide slide = slides[slideIndex];
         UniformLayout(slide, "ET HP " + meeting.getyear() + " Actual, " + meeting.getnextyear() + " Forecast");
         DataSet ds = getSlide_eleven();
         if (ds.Tables[0].Rows.Count == 0)
             return;
         DataSet ds1 = getSlide_Telwe();
         if (ds.Tables[0].Rows.Count == 0)
             return;
         DataSet ds2 = getSlide_TelweAdd();
         if (ds.Tables[0].Rows.Count == 0)
             return;
         //int x = 0;
         int y = 0;

         for (int i = 0; i < 2; i++)
         {
             ChartSpace objSpace = new ChartSpace();
             ChChart objChart = objSpace.Charts.Add(0);
             objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
             objChart.HasTitle = true;
             objChart.Title.Font.Size = 12;
             objChart.HasLegend = true;
             objChart.Title.Font.Bold = true;
             string dimValues = "";
             switch (i)
             {
                 case 0:
                     y = 80;
                     objChart.Title.Caption = "Bookings";
                     for (int j = 4; j > 0; j--)
                     {
                         dimValues = "";
                         for (int k = 0; k < ds.Tables[0].Rows.Count - 1; k++)
                         {
                             var num = ds.Tables[0].Rows[k][j];
                             dimValues += String.Format("{0:F}", (num is DBNull ? 0 : (double)num)) + "\t";
                         }
                         dimValues.Substring(0, dimValues.Length - 1);
                         objChart.SeriesCollection.Add(0);
                         objChart.SeriesCollection[0].Caption = ds.Tables[0].Columns[j].ColumnName;

                         objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                                +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimSegmentCategories);
                         objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                 +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
                     }
                     int rowCount = ds.Tables[0].Rows.Count;
                     int columnCount = ds.Tables[0].Columns.Count;
                     PowerPoint.Shape shape = slide.Shapes.AddTable(rowCount + 1, columnCount, 385, 300, 700, 200);

                     for (int s = 0; s < rowCount + 1; s++)
                     {
                         for (int t = 0; t < columnCount; t++)
                         {
                             PowerPoint.TextFrame textF = shape.Table.Cell(s + 1, t + 1).Shape.TextFrame;
                             PowerPoint.TextRange textR = textF.TextRange;
                             textR.Font.Bold = MsoTriState.msoFalse;
                             textR.Font.Size = 4;

                             if (s == 0)
                             {
                                 textR.Text = ds.Tables[0].Columns[t].ColumnName;
                             }
                             else
                             {
                                 if (t == 0)
                                 {
                                     var num1 = ds.Tables[0].Rows[s - 1][t];
                                     textR.Text = num1.ToString();
                                 }
                                 else
                                 {
                                     var num = ds.Tables[0].Rows[s - 1][t];
                                     textR.Text = Convert.ToDouble(num is DBNull ? 0 : num).ToString();
                                 }
                             }
                         }
                     }
                     shape.Export(picturePath, Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatGIF, 400, 200, Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY);
                     shape.Delete();
                     InsertPicture(slide, picturePath, 400, 120, 240, 120);
                     InsertText(slide, "Bookings", 490, 80, 60, 35, 12);
                     break;
                 case 1:
                     objChart.Title.Caption = "Sales";
                     y = 300;
                     for (int j = 4; j > 0; j--)
                     {
                         dimValues = "";
                         for (int k = 0; k < ds1.Tables[0].Rows.Count - 1; k++)
                         {
                             var num1 = ds1.Tables[0].Rows[k][j];
                             var num2 = ds2.Tables[0].Rows[k][j];
                             dimValues += (Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2)).ToString() + "\t";
                         }
                         dimValues.Substring(0, dimValues.Length - 1);
                         objChart.SeriesCollection.Add(0);
                         objChart.SeriesCollection[0].Caption = ds1.Tables[0].Columns[j].ColumnName;

                         objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                                +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimSegmentCategories);
                         objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                 +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
                     }
                     int rowCount1 = ds1.Tables[0].Rows.Count;
                     int columnCount1 = ds1.Tables[0].Columns.Count;
                     PowerPoint.Shape shape1 = slide.Shapes.AddTable(rowCount1 + 1, columnCount1, 385, 300, 700, 200);

                     for (int s = 0; s < rowCount1 + 1; s++)
                     {
                         for (int t = 0; t < columnCount1; t++)
                         {
                             PowerPoint.TextFrame textF = shape1.Table.Cell(s + 1, t + 1).Shape.TextFrame;
                             PowerPoint.TextRange textR = textF.TextRange;
                             textR.Font.Bold = MsoTriState.msoFalse;
                             textR.Font.Size = 4;

                             if (s == 0)
                             {
                                 textR.Text = ds1.Tables[0].Columns[t].ColumnName;
                             }
                             else
                             {
                                 if (t == 0)
                                 {
                                     var num1 = ds1.Tables[0].Rows[s - 1][t];
                                     textR.Text = num1.ToString();
                                 }
                                 else
                                 {
                                     var num1 = ds1.Tables[0].Rows[s - 1][t];
                                     var num2 = ds2.Tables[0].Rows[s - 1][t];
                                     textR.Text = (Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2)).ToString();
                                 }
                             }
                         }
                     }
                     shape1.Export(picturePath, Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatGIF, 400, 200, Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY);
                     shape1.Delete();
                     InsertPicture(slide, picturePath, 400, 335, 240, 120);
                     InsertText(slide, "Sales", 490, 295, 60, 35, 12);
                     break;
             }
             objSpace.ExportPicture(picturePath, "GIF", 260, 200);
             picturePath = pictureFolderPath + pictureName;
             InsertPicture(slide, picturePath, 60, y, 260, 200);
         }
    }
Esempio n. 19
0
        private ValueAxis AppendValueAxis()
        {
            ChartSpace chartSpace = this.chartPart.ChartSpace;
            Chart      chart      = chartSpace.GetFirstChild <Chart>() ?? chartSpace.AppendChild(new Chart());
            PlotArea   plotArea   = chart.GetFirstChild <PlotArea>() ?? chart.AppendChild(new PlotArea());

            uint id = plotArea.Elements <ValueAxis>().Select(axis => axis.AxisId.Val.Value).DefaultIfEmpty(417314071u).Max() + 1;

            ValueAxis valueAxis = plotArea.AppendChild(
                new ValueAxis()
            {
                AxisId = new AxisId()
                {
                    Val = id
                },
                Scaling = new Scaling()
                {
                    Orientation = new Orientation()
                    {
                        Val = OrientationValues.MinMax
                    }
                },
                Delete = new Delete()
                {
                    Val = false
                },
                AxisPosition = new AxisPosition()
                {
                    Val = AxisPositionValues.Left
                },
                MajorGridlines = new MajorGridlines()
                {
                    ChartShapeProperties = new ChartShapeProperties()
                    {
                        // TODO
                    }
                },
                NumberingFormat = new NumberingFormat()
                {
                    FormatCode = "General", SourceLinked = true
                },
                MajorTickMark = new MajorTickMark()
                {
                    Val = TickMarkValues.None
                },
                MinorTickMark = new MinorTickMark()
                {
                    Val = TickMarkValues.None
                },
                TickLabelPosition = new TickLabelPosition()
                {
                    Val = TickLabelPositionValues.NextTo
                },
                ChartShapeProperties = new ChartShapeProperties()
                                       .AppendChildFluent(new Drawing.NoFill())
                                       .AppendChildFluent(new Drawing.Outline().AppendChildFluent(new Drawing.NoFill()))
                                       .AppendChildFluent(new Drawing.EffectList()),
                TextProperties = new TextProperties()
                {
                    BodyProperties = new Drawing.BodyProperties(),
                    ListStyle      = new Drawing.ListStyle()
                }
                .AppendChildFluent(
                    new Drawing.Paragraph()
                {
                    ParagraphProperties = new Drawing.ParagraphProperties().AppendChildFluent(
                        new Drawing.DefaultRunProperties()
                    {
                        FontSize  = 1197,
                        Bold      = false,
                        Italic    = false,
                        Underline = Drawing.TextUnderlineValues.None,
                        Strike    = Drawing.TextStrikeValues.NoStrike,
                        Kerning   = 1200,
                        Baseline  = 0
                    }
                        .AppendChildFluent(
                            new Drawing.SolidFill()
                    {
                        SchemeColor = new Drawing.SchemeColor()
                        {
                            Val = Drawing.SchemeColorValues.Text1
                        }
                        .AppendChildFluent(new Drawing.LuminanceModulation()
                        {
                            Val = 65000
                        })
                        .AppendChildFluent(new Drawing.LuminanceOffset()
                        {
                            Val = 35000
                        })
                    }
                            )
                        .AppendChildFluent(new Drawing.LatinFont()
                    {
                        Typeface = "+mn-lt"
                    })
                        .AppendChildFluent(new Drawing.EastAsianFont()
                    {
                        Typeface = "+mn-ea"
                    })
                        .AppendChildFluent(new Drawing.ComplexScriptFont()
                    {
                        Typeface = "+mn-cs"
                    })
                        )
                }
                    )
            }
                .AppendChildFluent(new Crosses()
            {
                Val = CrossesValues.AutoZero
            })
                .AppendChildFluent(new CrossBetween()
            {
                Val = CrossBetweenValues.Between
            })
                );

            return(valueAxis);
        }
Esempio n. 20
0
        public string ColumnChart(Column column, Page page)
        {
            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();

            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);

            mychartSpace.Border.Color = column.ChartBorderColor;
            //设置图表类型,本例使用柱形
            mychart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
            //设置图表的一些属性
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption   = column.ChartTitle;
            mychart.Title.Font.Size = column.ChartTitleSize;
            mychart.Title.Font.Bold = column.ChartTitleBold;

            switch (column.LegendPosition)
            {
            case LegendPosition.Top:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionTop;
                break;

            case LegendPosition.Bottom:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
                break;

            case LegendPosition.Left:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;
                break;

            case LegendPosition.Right:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionRight;
                break;

            default:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionRight;
                break;
            }
            mychart.Legend.Interior.Color = column.LegendBgColor;
            mychart.Legend.Font.Size      = column.LegendFontSize;
            mychart.Legend.Border.Color   = column.LegendBorderColor;


            //设置x,y坐标

            mychart.Axes[1].HasTitle        = column.ShowYAxes;
            mychart.Axes[1].Title.Caption   = column.YAxesCaption;
            mychart.Axes[1].Title.Font.Size = 10;

            mychart.Axes[0].HasTitle      = column.ShowXAxes;
            mychart.Axes[0].Title.Caption = column.XAxesCaption;
            mychart.Axes[0].Font.Name     = "宋体";
            mychart.Axes[0].Font.Size     = 10;

            string seriesName = "";
            string strValue   = "";
            string category   = "";

            for (int i = 0; i < column.SeriesNames.Length; i++)
            {
                seriesName = column.SeriesNames[i];
                strValue   = "";
                category   = "";
                for (int j = 0; j < column.Values[i].Length; j++)
                {
                    strValue += column.Values[i][j].ToString() + "\t";
                }

                for (int j = 0; j < column.Categorys.Length; j++)
                {
                    category += column.Categorys[j] + "\t";
                }
                mychart.SeriesCollection.Add(i);
                mychart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, seriesName);
                mychart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, category);
                mychart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
                mychart.SeriesCollection[i].DataLabelsCollection.Add();
                mychart.SeriesCollection[i].DataLabelsCollection[0].HasValue = true;
                //mychart.SeriesCollection.Add(1);

                //if (column.DataColor != null)
                //{
                //    mychart.SeriesCollection[i].Points[0].Interior.Color = column.DataColor[i].ToString();
                //}
            }

            //生成图片
            //劉宏哲修改,先删除文件再创建文件。解决第一次生成图片以后,再次生成报错。时间:2010-04-21 9:44。

            string path = page.MapPath(".") + @"\" + column.PicName + ".gif";

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            mychartSpace.ExportPicture(path, "gif", column.ChartWidth, column.ChartHeight);

            //返回图片路径
            return(column.PicName + ".gif" + "?temp=" + System.DateTime.Now.Ticks.ToString() + "");
        }
Esempio n. 21
0
        public string PieChart(Pie pie, Page page)
        {
            //创建X坐标的值
            string[] str = pie.DataNames;

            //创建Y坐标的值,表示销售额
            double[] count       = pie.DataValues;
            string   strDataName = "";
            string   strData     = "";

            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();

            mychartSpace.Border.Color = pie.ChartBorderColor;

            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);

            //设置每块饼的数据
            for (int i = 0; i < count.Length; i++)
            {
                strDataName += str[i].ToString() + "\t";
                strData     += count[i].ToString() + "\t";
            }
            strDataName = strDataName.Substring(0, strDataName.Length - 1);
            strData     = strData.Substring(0, strData.Length - 1);

            //设置图表类型,本例使用饼
            switch (pie.PicChartType)
            {
            case PieType.Pie:
                mychart.Type = ChartChartTypeEnum.chChartTypePie;
                break;

            case PieType.Pie3D:
                mychart.Type = ChartChartTypeEnum.chChartTypePie3D;
                break;

            case PieType.Exploded:
                mychart.Type = ChartChartTypeEnum.chChartTypePieExploded;
                break;

            case PieType.Exploded3D:
                mychart.Type = ChartChartTypeEnum.chChartTypePieExploded3D;
                break;

            default:
                mychart.Type = ChartChartTypeEnum.chChartTypePie;
                break;
            }


            //设置图表的一些属性
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;


            //主题内容
            mychart.Title.Caption    = pie.ChartTitle;
            mychart.Title.Font.Size  = pie.ChartTitleSize;
            mychart.Title.Font.Bold  = pie.ChartTitleBold;
            mychart.Title.Font.Color = pie.ChartTitleColor;
            switch (pie.LegendPosition)
            {
            case LegendPosition.Top:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionTop;
                break;

            case LegendPosition.Bottom:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
                break;

            case LegendPosition.Left:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;
                break;

            case LegendPosition.Right:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionRight;
                break;

            default:
                mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionRight;
                break;
            }



            mychart.Legend.Interior.Color = pie.LegendBgColor;
            mychart.Legend.Font.Bold      = pie.LegenFontBold;
            mychart.Legend.Font.Size      = pie.LegendFontSize;
            mychart.Legend.Border.Color   = pie.LegendBorderColor;



            //添加图表块
            mychart.SeriesCollection.Add(0);
            //设置图表块的属性
            //分类属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName);
            //mychart.SeriesCollection[0].Interior.Color = "#C1DBEE";
            //mychart.SeriesCollection[1].Interior.Color = "#D1A00B";


            //值属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, strData);
            for (int j = 0; j < mychart.SeriesCollection[0].Points.Count; j++)
            {
                mychart.SeriesCollection[0].Points[j].Border.Color = pie.SeriesCollectionBorderColor;
                if (pie.DataColor != null)
                {
                    mychart.SeriesCollection[0].Points[j].Interior.Color = pie.DataColor[j].ToString();
                }
            }

            //显示百分比
            ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();

            mytb.HasPercentage = pie.HasPercentage;
            mytb.Font.Color    = pie.DataFontColor;
            mytb.Font.Size     = pie.DataFontSize;
            mytb.HasValue      = true;
            //生成图片
            //劉宏哲修改,先删除文件再创建文件。解决第一次生成图片以后,再次生成报错。时间:2010-04-21 9:44。
            string path = page.MapPath(".") + @"\" + pie.PicName + ".gif";

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            mychartSpace.ExportPicture(path, "gif", pie.ChartWidth, pie.ChartHeight);

            //返回图片路径
            return(pie.PicName + ".gif" + "?temp=" + System.DateTime.Now.Ticks.ToString() + "");
        }
        private void MakeLineChart(DataTable mDataTable)//string[] DataName,string[] Data,string[] Data1, string[] Data2)
        {
            //Y坐标轴

            //string[] DataName = { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
            //string[] DataName = { "一", "二", "三", "四", "五", "六", "日" };
            //第一条曲线的数据

            //int[] Data = { 0, 10, 20, 100, 40, 50, 60 };

            //第二条曲线的数据

            //int[] Data1 = { 100, 50, 41, 86 };

            //第三条曲线的数据

            // int[] Data2 = { 10, 50, 100, 30, 50, 60, 200 };

            string strValue1 = "";

            string strValue = "";

            string strValue2 = "";

            string strCateory = "";

            //循环取得数据并格式化为OWC10需要的格式,(加'\t')
            foreach (DataRow mRow in mDataTable.Rows)
            {
                strCateory += mRow[0].ToString() + '\t';
                strValue   += mRow[1].ToString() + '\t';
                strValue1  += mRow[2].ToString() + '\t';
            }



            //for (int i = 0; i < DataName.Length; i++)
            //{

            //    strCateory += DataName[i] + '\t';

            //}


            //for (int i = 0; i < Data.Length; i++)
            //{

            //    strValue += Data[i] + '\t';

            //}

            //for (int i = 0; i < Data1.Length; i++)
            //{

            //    strValue1 += Data1[i] + '\t';

            //}

            //for (int i = 0; i < Data2.Length; i++)
            //{

            //    strValue2 += Data2[i] + '\t';

            //}


            ChartSpace mySpace = new ChartSpace();
            ChChart    myChart = mySpace.Charts.Add(0);

            myChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;

            myChart.HasLegend     = true;
            myChart.HasTitle      = true;
            myChart.Title.Caption = "交易曲线图";

            myChart.Axes[0].HasTitle      = true;
            myChart.Axes[0].Title.Caption = mDataTable.Columns[0].Caption;
            myChart.Axes[1].HasTitle      = true;
            myChart.Axes[1].Title.Caption = "总额";


            myChart.SeriesCollection.Add(0);
            //myChart.
            myChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, mDataTable.Columns[1].Caption);
            myChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strCateory);
            ChDataLabels myLabels1 = myChart.SeriesCollection[0].DataLabelsCollection.Add();

            myLabels1.NumberFormat = "0.00";
            myLabels1.HasValue     = true;

            myChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
            if (strValue1 != "")
            {
                myChart.SeriesCollection.Add(1);
                myChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, mDataTable.Columns[2].Caption);
                myChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue1);
                ChDataLabels myLabels2 = myChart.SeriesCollection[1].DataLabelsCollection.Add();
                myLabels2.NumberFormat = "0.00";
                myLabels2.HasValue     = true;
            }
            //if (strValue2 !="")
            //{
            //    myChart.SeriesCollection.Add(2);
            //    myChart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue2);
            //    ChDataLabels myLabels3 = myChart.SeriesCollection[2].DataLabelsCollection.Add();
            //    myLabels3.NumberFormat = "0.00";
            //    myLabels3.HasValue = true;
            //}

            System.IO.File.Delete(@"C:\temp.gif");
            mySpace.ExportPicture(@"C:\temp.gif", "GIF", this.Width, this.Height);

            Image image = Image.FromFile(@"C:\temp.gif");

            pictureBox1.Image   = image;
            pictureBox1.Size    = image.Size;
            pictureBox1.Visible = true;
        }
Esempio n. 23
0
        //竖状柱状图+折线图
        public string ChartTypeColumnClustered4(string strDataName,Dictionary<string,string> list , string caption)
        {
            var mychartSpace = new ChartSpace();
            ChChart mychart = mychartSpace.Charts.Add(0);
            mychart.HasLegend = true;
            mychart.HasTitle = true;
            mychart.Title.Caption = caption;
            mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
            mychart.Axes[1].NumberFormat = "0%";

            var dicList = new string[list.Keys.Count];
            var i = 0;
            foreach (var dic in list)
            {
                dicList[i] = dic.Value;
                i++;
            }
            var type = dicList[0].Split('\t');

            var clearList="";
            for (var j = 0; j < type.Length-1; j++)
            {
                clearList += 1 - Convert.ToSingle(type[j]) + "\t";
            }
            clearList += 1 - Convert.ToSingle(type[type.Length - 1]);

            var chart1 = mychart.SeriesCollection.Add(0);
            chart1.Type = ChartChartTypeEnum.chChartTypeColumnStacked100;
            chart1.SetData(DimCategories, DataLiteral, strDataName);
            chart1.SetData(DimValues, DataLiteral, clearList);
            chart1.Interior.Color = ChartColorIndexEnum.chColorNone;
            chart1.Border.Color = ChartColorIndexEnum.chColorNone;
            chart1.Caption = "";

            var chart3 = mychart.SeriesCollection.Add(0);
            chart3.SetData(DimValues, DataLiteral, dicList[0]);
            chart3.Caption = "你的得分率";

            var chart2 = mychart.SeriesCollection.Add(0);
            chart2.Type = ChartChartTypeEnum.chChartTypeLineStackedMarkers;
            chart2.SetData(DimValues, DataLiteral, dicList[1]);
            chart2.Caption = "同层面得分率";

            var image = UrlPath("柱状折线图");
            mychartSpace.ExportPicture(image, "GIF", 400, 300);
            return image;
        }
Esempio n. 24
0
        //折线图--
        public string ChartTypeLineStackedMarkers(string strDataName, Dictionary<string, string> list, string caption)
        {
            var mychartSpace = new ChartSpace();
            var mychart = mychartSpace.Charts.Add(0);
            mychart.Type = ChartChartTypeEnum.chChartTypeLineStackedMarkers;
            //mychart.Axes[1].Line.Color = ChartColorIndexEnum.chColorNone;
            mychart.HasLegend = true;
            mychart.HasTitle = true;
            mychart.Title.Caption = caption;
            mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;

            string[] color = {"Red", "Blue", "Green", "Yellow"};

            var i = 0;
            foreach (var dic in list)
            {
                var keys = mychart.SeriesCollection.Add(0);
                keys.SetData(DimValues, DataLiteral, dic.Value);
                //keys.DataLabelsCollection.Add().HasValue = true;
                keys.Caption = dic.Key;
                //keys.Marker.Style = ChartMarkerStyleEnum.chMarkerStyleCircle;
                keys.Line.Color = color[i];
                keys.Ungroup(true);
                i++;
            }
            mychart.SeriesCollection[0].SetData(DimCategories, DataLiteral, strDataName);

            var image = UrlPath("折线图");
            mychartSpace.ExportPicture(image, "GIF", 800, 200);
            return image;
        }
    //---------------------------------------------------
    protected void DrawSlide_Sixteen()
    {
        int slideNum = segmentNumber / 2 + (segmentNumber % 2 == 0 ? 0 : 1);
         for (int i = 0; i < slideNum; i++)
         {
             slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
             PowerPoint.Slide slide = slides[slideIndex];
             UniformLayout(slide, meeting.getyear().Trim() + " & " + meeting.getnextyear().Trim() + "  Sales Forecast   by Products");
             int chartNum = 2;
             float x = 40;
             float x1 = 70;
             if ((i == slideNum - 1) && (segmentNumber % 2 == 1))
             {
                 chartNum = 1;
             }
             DataSet[] ds = new DataSet[chartNum];
             DataSet[] dsAdd = new DataSet[chartNum];
             bool slideIsNull = true;
             for (int j = 0; j < chartNum; j++)
             {
                 ds[j] = getSlide_Sixteen(alSegment[2 * i + j].ToString());
                 dsAdd[j] = getSlide_SixteenAdd(alSegment[2 * i + j].ToString());
                 if (ds[j] != null && ds[j].Tables.Count > 0 && ds[j].Tables[0].Rows.Count > 0)
                 {
                     slideIsNull = false;
                     string dimCategories = "";
                     string dimValues = "";
                     ChartSpace objSpace = new ChartSpace();
                     ChChart objChart = objSpace.Charts.Add(0);
                     objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
                     objChart.HasTitle = true;
                     objChart.HasLegend = true;
                     objChart.Title.Font.Size = 12;
                     objChart.Title.Font.Bold = true;
                     for (int m = 1; m < ds[j].Tables[0].Columns.Count; m++)
                     {
                         dimCategories += ds[j].Tables[0].Columns[m].ColumnName + "\t";
                     }
                     dimCategories = dimCategories.Substring(0, dimCategories.Length - 1);
                     for (int k = ds[j].Tables[0].Rows.Count - 1; k >= 0; k--)
                     {
                         dimValues = "";
                         for (int l = 1; l < ds[j].Tables[0].Columns.Count; l++)
                         {
                             var num1 = ds[j].Tables[0].Rows[k][l];
                             if (dsAdd[j] != null && dsAdd[j].Tables.Count > 0 && dsAdd[j].Tables[0].Rows.Count > 0)
                             {
                                 var num2 = dsAdd[j].Tables[0].Rows[k][l];
                                 dimValues += Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2) + "\t";
                             }
                             else
                                 dimValues += Convert.ToDouble(num1 is DBNull ? 0 : num1) + "\t";
                         }
                         dimValues = dimValues.Substring(0, dimValues.Length - 1);
                         objChart.SeriesCollection.Add(0);
                         objChart.SeriesCollection[0].Caption = ds[j].Tables[0].Rows[k][0].ToString();
                         objChart.Title.Caption = alSegment[2 * i + j].ToString() + " Products";
                         objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                                    +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimCategories);
                         objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                 +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
                     }

                     objSpace.ExportPicture(picturePath, "GIF", 300, 200);
                     picturePath = pictureFolderPath + pictureName;
                     InsertPicture(slide, picturePath, x, 80, 300, 200);

                     int rowCount = ds[j].Tables[0].Rows.Count;
                     int columnCount = ds[j].Tables[0].Columns.Count;
                     PowerPoint.Shape shape = slide.Shapes.AddTable(rowCount + 1, columnCount, 385, 300, 700, 200);

                     for (int s = 0; s < rowCount + 1; s++)
                     {
                         for (int t = 0; t < columnCount; t++)
                         {
                             PowerPoint.TextFrame textF = shape.Table.Cell(s + 1, t + 1).Shape.TextFrame;
                             textF.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
                             PowerPoint.TextRange textR = textF.TextRange;
                             textR.Font.Bold = MsoTriState.msoTrue;
                             textR.Font.Size = 4;
                             if (s == 0)
                             {
                                 textR.Text = ds[j].Tables[0].Columns[t].ColumnName;
                             }
                             else
                             {
                                 if (t == 0)
                                 {
                                     var num1 = ds[j].Tables[0].Rows[s - 1][t];
                                     textR.Text = num1.ToString();
                                 }
                                 else
                                 {
                                     var num1 = ds[j].Tables[0].Rows[s - 1][t];
                                     if (dsAdd[j] != null && dsAdd[j].Tables.Count > 0 && dsAdd[j].Tables[0].Rows.Count > 0)
                                     {
                                         var num2 = dsAdd[j].Tables[0].Rows[s - 1][t];
                                         textR.Text = (Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2)).ToString();
                                     }
                                     else
                                         textR.Text = (Convert.ToDouble(num1 is DBNull ? 0 : num1)).ToString();
                                 }
                             }
                         }
                     }
                     shape.Export(picturePath, Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatGIF, 480, 240, Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY);
                     shape.Delete();
                     InsertPicture(slide, picturePath, x1, 340, 240, 120);
                     x1 = 410;
                     x = 380;
                 }
             }
             if (slideIsNull == true)
                 --slideIndex;
         }
    }
Esempio n. 26
0
        void setChartData(ChartPart chartPart1, ChartDataHolder[] ChartDataSlide)
        {
            ChartSpace chartSpace = chartPart1.ChartSpace;

            DocumentFormat.OpenXml.Drawing.Charts.Chart chart1 = chartSpace.GetFirstChild <DocumentFormat.OpenXml.Drawing.Charts.Chart>();
            PlotArea plotArea1 = chart1.GetFirstChild <PlotArea>();
            BarChart barChart1 = plotArea1.GetFirstChild <BarChart>();

            //BarChartSeries barChartSeries1 = barChart1.Elements<BarChartSeries>().ElementAtOrDefault(2);
            for (int i = 0; i < barChart1.Elements <BarChartSeries>().Count(); i++)
            {
                BarChartSeries barChartSeries = barChart1.Elements <BarChartSeries>().ElementAtOrDefault(i);
                ChartDataSlide dataModel      = ChartDataSlide.ElementAtOrDefault(i).chartData;

                SeriesText seriesText = barChartSeries.Elements <SeriesText>().ElementAtOrDefault(0);
                if (seriesText != null)
                {
                    var stringReference = seriesText.Descendants <StringReference>().FirstOrDefault();
                    var stringCache     = stringReference.Descendants <StringCache>().FirstOrDefault();
                    var stringPoint     = stringCache.Descendants <StringPoint>().FirstOrDefault();
                    var barLabel        = stringPoint.GetFirstChild <NumericValue>();
                    barLabel.Text = ChartDataSlide.ElementAtOrDefault(i).seriesText;
                }

                if (barChartSeries != null)
                {
                    Values          values1          = barChartSeries.GetFirstChild <Values>();
                    NumberReference numberReference1 = values1.GetFirstChild <NumberReference>();
                    NumberingCache  numberingCache1  = numberReference1.GetFirstChild <NumberingCache>();

                    NumericPoint numericPoint1 = numberingCache1.GetFirstChild <NumericPoint>();
                    NumericPoint numericPoint2 = numberingCache1.Elements <NumericPoint>().ElementAt(1);
                    NumericPoint numericPoint3 = numberingCache1.Elements <NumericPoint>().ElementAt(2);

                    NumericValue numericValue1 = numericPoint1.GetFirstChild <NumericValue>();
                    //numericValue1.Text = ".50";
                    if (numericValue1 != null)
                    {
                        numericValue1.Text = dataModel.Interaction.ToString();
                    }


                    NumericValue numericValue2 = numericPoint2.GetFirstChild <NumericValue>();
                    //numericValue2.Text = ".10";
                    if (numericValue2 != null)
                    {
                        numericValue2.Text = dataModel.Knowlegde.ToString();
                    }


                    NumericValue numericValue3 = numericPoint3.GetFirstChild <NumericValue>();
                    //numericValue3.Text = ".40";
                    if (numericValue3 != null)
                    {
                        numericValue3.Text = dataModel.Image.ToString();
                    }
                }
            }

            chartSpace.Save();
        }
Esempio n. 27
0
        public string PieChart(Pie pie, Page page)
        {
            //创建X坐标的值
            string[] str = pie.DataNames;

            //创建Y坐标的值,表示销售额
            double[] count = pie.DataValues;
            string strDataName = "";
            string strData = "";

            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();
            mychartSpace.Border.Color = pie.ChartBorderColor;

            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);

            //设置每块饼的数据
            for (int i = 0; i < count.Length; i++)
            {
                strDataName += str[i].ToString() + "\t";
                strData += count[i].ToString() + "\t";
            }
            strDataName = strDataName.Substring(0, strDataName.Length - 1);
            strData = strData.Substring(0, strData.Length - 1);

            //设置图表类型,本例使用饼
            switch (pie.PicChartType)
            {
                case PieType.Pie:
                    mychart.Type = ChartChartTypeEnum.chChartTypePie;
                    break;
                case PieType.Pie3D:
                    mychart.Type = ChartChartTypeEnum.chChartTypePie3D;
                    break;
                case PieType.Exploded:
                    mychart.Type = ChartChartTypeEnum.chChartTypePieExploded;
                    break;
                case PieType.Exploded3D:
                    mychart.Type = ChartChartTypeEnum.chChartTypePieExploded3D;
                    break;
                default:
                    mychart.Type = ChartChartTypeEnum.chChartTypePie;
                    break;
            }

            //设置图表的一些属性
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;

            //主题内容
            mychart.Title.Caption = pie.ChartTitle;
            mychart.Title.Font.Size = pie.ChartTitleSize;
            mychart.Title.Font.Bold = pie.ChartTitleBold;
            mychart.Title.Font.Color = pie.ChartTitleColor;
            switch (pie.LegendPosition)
            {
                case LegendPosition.Top:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionTop;
                    break;
                case LegendPosition.Bottom:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
                    break;
                case LegendPosition.Left:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;
                    break;
                case LegendPosition.Right:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionRight;
                    break;
                default:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionRight;
                    break;
            }

            mychart.Legend.Interior.Color = pie.LegendBgColor;
            mychart.Legend.Font.Bold = pie.LegenFontBold;
            mychart.Legend.Font.Size = pie.LegendFontSize;
            mychart.Legend.Border.Color = pie.LegendBorderColor;

            //添加图表块
            mychart.SeriesCollection.Add(0);
            //设置图表块的属性
            //分类属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
            (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName);
            //mychart.SeriesCollection[0].Interior.Color = "#C1DBEE";
            //mychart.SeriesCollection[1].Interior.Color = "#D1A00B";

            //值属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
            (int)ChartSpecialDataSourcesEnum.chDataLiteral, strData);
            for (int j = 0; j < mychart.SeriesCollection[0].Points.Count; j++)
            {
                mychart.SeriesCollection[0].Points[j].Border.Color = pie.SeriesCollectionBorderColor;
                if (pie.DataColor != null)
                {
                    mychart.SeriesCollection[0].Points[j].Interior.Color = pie.DataColor[j].ToString();
                }
            }

            //显示百分比
            ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            mytb.HasPercentage = pie.HasPercentage;
            mytb.Font.Color = pie.DataFontColor;
            mytb.Font.Size = pie.DataFontSize;
            mytb.HasValue = true;
            //生成图片
            //劉宏哲修改,先删除文件再创建文件。解决第一次生成图片以后,再次生成报错。时间:2010-04-21 9:44。
            string path = page.MapPath(".") + @"\" + pie.PicName + ".gif";
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            mychartSpace.ExportPicture(path, "gif", pie.ChartWidth, pie.ChartHeight);

            //返回图片路径
            return pie.PicName + ".gif" + "?temp=" + System.DateTime.Now.Ticks.ToString() + "";
        }
Esempio n. 28
0
        //竖状柱状图--优势科目、弱势科目分析
        public string ChartTypeColumnClustered()
        {
            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();
            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);
            //设置图表类型,本例使用柱状图
            mychart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;

            //设置图表的一些属性
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = "test";
            //添加图表块
            mychart.SeriesCollection.Add(0);
            //设置图例位置为底端
            mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionTop;

            //设置图表块的属性
            //分类属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "语文\t数学\t英语\t物理\t化学\t生物");
            //值属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "100\t120\t143\t170\t135\t143");

            ChSeries chSeries = mychart.SeriesCollection.Add(0);
            chSeries.Type = ChartChartTypeEnum.chChartTypeLineMarkers;
            chSeries.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                             "100\t120\t90\t120\t110\t132");
            //chSeries.Interior.SetPresetGradient(ChartGradientStyleEnum.chGradientFromCenter,
            //    ChartGradientVariantEnum.chGradientVariantCenter,ChartPresetGradientTypeEnum.chGradientChrome);

            chSeries = mychart.SeriesCollection.Add(0);
            chSeries.Type = ChartChartTypeEnum.chChartTypeLineMarkers;
            chSeries.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                             "120\t150\t70\t150\t120\t112");

            chSeries = mychart.SeriesCollection.Add(0);
            chSeries.Type = ChartChartTypeEnum.chChartTypeLineMarkers;
            chSeries.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                             "150\t130\t40\t150\t130\t132");

            //显示百分比
            //ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            //mytb.HasPercentage = true;

            var image = UrlPath("柱状图");

            //生成图片
            mychartSpace.ExportPicture(image, "GIF", 400, 300);

            return image;
        }
Esempio n. 29
0
        public string ColumnChart(Column column, Page page)
        {
            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();

            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);
            mychartSpace.Border.Color = column.ChartBorderColor;
            //设置图表类型,本例使用柱形
            mychart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
            //设置图表的一些属性
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = column.ChartTitle;
            mychart.Title.Font.Size = column.ChartTitleSize;
            mychart.Title.Font.Bold = column.ChartTitleBold;

            switch (column.LegendPosition)
            {
                case LegendPosition.Top:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionTop;
                    break;
                case LegendPosition.Bottom:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
                    break;
                case LegendPosition.Left:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;
                    break;
                case LegendPosition.Right:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionRight;
                    break;
                default:
                    mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionRight;
                    break;
            }
            mychart.Legend.Interior.Color = column.LegendBgColor;
            mychart.Legend.Font.Size = column.LegendFontSize;
            mychart.Legend.Border.Color = column.LegendBorderColor;

            //设置x,y坐标

            mychart.Axes[1].HasTitle = column.ShowYAxes;
            mychart.Axes[1].Title.Caption = column.YAxesCaption;
            mychart.Axes[1].Title.Font.Size = 10;

            mychart.Axes[0].HasTitle = column.ShowXAxes;
            mychart.Axes[0].Title.Caption = column.XAxesCaption;
            mychart.Axes[0].Font.Name = "宋体";
            mychart.Axes[0].Font.Size = 10;

            string seriesName = "";
            string strValue = "";
            string category = "";

            for (int i = 0; i < column.SeriesNames.Length; i++)
            {
                seriesName = column.SeriesNames[i];
                strValue = "";
                category = "";
                for (int j = 0; j < column.Values[i].Length; j++)
                {
                    strValue += column.Values[i][j].ToString() + "\t";
                }

                for (int j = 0; j < column.Categorys.Length; j++)
                {
                    category += column.Categorys[j] + "\t";
                }
                mychart.SeriesCollection.Add(i);
                mychart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, seriesName);
                mychart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, category);
                mychart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
                mychart.SeriesCollection[i].DataLabelsCollection.Add();
                mychart.SeriesCollection[i].DataLabelsCollection[0].HasValue = true;
                //mychart.SeriesCollection.Add(1);

                //if (column.DataColor != null)
                //{
                //    mychart.SeriesCollection[i].Points[0].Interior.Color = column.DataColor[i].ToString();
                //}
            }

            //生成图片
            //劉宏哲修改,先删除文件再创建文件。解决第一次生成图片以后,再次生成报错。时间:2010-04-21 9:44。

            string path = page.MapPath(".") + @"\" + column.PicName + ".gif";
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            mychartSpace.ExportPicture(path, "gif", column.ChartWidth, column.ChartHeight);

            //返回图片路径
            return column.PicName + ".gif" + "?temp=" + System.DateTime.Now.Ticks.ToString() + "";
        }
 //----------------------------------------------------------------------------
 protected void DrawSlide_Ten()
 {
     slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
      PowerPoint.Slide slide = slides[slideIndex];
      UniformLayout(slide, "BOOKINGS BYREGIONS");
      DataSet ds = getSlide_Nine();
      if (ds.Tables[0].Rows.Count == 0)
          return;
      string[] titile = { meeting.getyear().Substring(2, 2) + " A", meeting.getnextyear().Substring(2, 2) + " F" };
      float[] x = { 60, 380 };
      for (int i = 0; i < 2; i++)
      {
          ChartSpace objSpace = new ChartSpace();
          ChChart objChart = objSpace.Charts.Add(0);
          objChart.Type = ChartChartTypeEnum.chChartTypePie3D;
          objChart.HasTitle = true;
          objChart.Title.Font.Size = 12;
          objChart.Title.Font.Bold = true;
          objChart.Title.Caption = "All Products " + titile[i];
          objChart.HasLegend = true;
          string dimValues = "";
          double total = 0;
          for (int j = 0; j < regionNumber; j++)
          {
              var num = ds.Tables[0].Rows[0][j + 1];
              if (num is DBNull)
                  total += 0;
              else
                  total += (double)num;
          }
          for (int j = 0; j < regionNumber; j++)
          {
              var num = ds.Tables[0].Rows[0][j + 1];
              if (num is DBNull)
                  dimValues += "0\t";
              else
                  dimValues += string.Format("{0:F}", 100 * (double)num / total) + "\t";
          }
          dimValues = dimValues.Substring(0, dimValues.Length - 1);
          objChart.SeriesCollection.Add(0);
          objChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;
          objChart.SeriesCollection[0].DataLabelsCollection.Add();
          objChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
          objChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
          objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                 +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimRegionCategories);
          objSpace.Charts[0].SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                  +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
          objSpace.ExportPicture(picturePath, "GIF", 300, 250);
          picturePath = pictureFolderPath + pictureName;
          InsertPicture(slide, picturePath, x[i], 120, 300, 250);
      }
 }
Esempio n. 31
0
        //横状柱状图
        public string ChartTypeBarClustered()
        {
            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();
            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);

            //设置图表的一些属性
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = "test";
            mychart.Axes[1].NumberFormat = "0%";//显示%

            //设置图例位置为底端
            mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
            //添加图表块
            var chart1 = mychart.SeriesCollection.Add(0);
            //设置图表块的属性
            chart1.Type = ChartChartTypeEnum.chChartTypeBarClustered;
            //分类属性
            chart1.SetData(ChartDimensionsEnum.chDimCategories,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, "解答题\t填空题\t选择题");
            //值属性
            chart1.SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, "0.7\t0.26\t0.48");
            //chart1.Interior.Color = Color.Red;

            //var chart2 = mychart.SeriesCollection.Add(0);
            //chart2.Type = ChartChartTypeEnum.chChartTypeScatterLine;
            //chart2.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, "0.82\t0.14\t0.27");

            //var chart2 = mychart.SeriesCollection.Add(0);
            //////chart2.Line.Color = ChartColorIndexEnum.chColorNone;
            //chart2.Type = ChartChartTypeEnum.chChartTypeLineMarkers;
            //chart1.SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, "0.82\t0.14\t0.27");
            //chart2.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, "解答题\t填空题\t选择题");
            //chart2.Marker.Style = ChartMarkerStyleEnum.chMarkerStyleStar;
            //chart2.Caption = "";
            ////chart2.Interior.Color = Color.Red;

            //var trend = chart2.Trendlines.Add();
            //trend.Type = ChartTrendlineTypeEnum.chTrendlineTypeLinear;
            //trend.Caption = "ds";
            //trend.IsDisplayingEquation = false;
            //trend.IsDisplayingRSquared = false;
            ////主次网格线不显示
            //chChart.Axes[1].HasMinorGridlines = false;
            //chChart.Axes[1].HasMajorGridlines = false;
            ////设定Y轴格式
            //chChart.Axes[1].NumberFormat = "0%";
            ////去掉线
            //chChart.SeriesCollection[3].Line.Color = ChartColorIndexEnum.chColorNone;
            ////标记形状
            //chChart.SeriesCollection[3].Marker.Style = ChartMarkerStyleEnum.chMarkerStyleDiamond;
            //显示百分比
            //ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            //mytb.HasPercentage = true;

            var name = "横坐标柱状图" + DateTime.Now.Ticks;
            var image = UrlPath(name);
            //生成图片
            mychartSpace.ExportPicture(image, "GIF", 400, 300);

            return image;
        }
    //-----------------------------------------------------------------------
    protected void DrawSlide_TwentyNine()
    {
        for (int i = 0; i < segmentNumber; i++)
         {
             DataSet ds_operation = getOperation(alSegment[i].ToString());
             if (ds_operation.Tables.Count > 0 && ds_operation.Tables[0].Rows.Count > 0)
             {
                 int operationIndex = 0;
                 int slideNum = ds_operation.Tables[0].Rows.Count / 2 + (ds_operation.Tables[0].Rows.Count % 2 == 0 ? 0 : 1);

                 for (int j = 0; j < slideNum; j++)
                 {
                     float x = 60;
                     slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
                     PowerPoint.Slide slide = slides[slideIndex];
                     UniformLayout(slide, meeting.getyear().Trim() + " & " + meeting.getnextyear().Trim() + " " + alSegment[i].ToString().Trim() + " PRODUCTS SALES");
                     int chartNum = 2;
                     if ((j == slideNum - 1) && (ds_operation.Tables[0].Rows.Count % 2 != 0))
                         chartNum = 1;
                     for (int k = 0; k < chartNum; k++)
                     {
                         DataSet ds = getSlide_TwentyNine(alSegment[i].ToString(), ds_operation.Tables[0].Rows[operationIndex][0].ToString());
                         DataSet dsAdd = getSlide_TwentyNineAdd(alSegment[i].ToString(), ds_operation.Tables[0].Rows[operationIndex][0].ToString());
                         if (ds != null)
                         {
                             ChartSpace objSpace = new ChartSpace();
                             ChChart objChart = objSpace.Charts.Add(0);
                             objChart.Type = ChartChartTypeEnum.chChartTypeArea;
                             objChart.HasTitle = true;
                             objChart.HasLegend = true;
                             objChart.Title.Font.Size = 12;
                             objChart.Title.Font.Bold = true;
                             objChart.Title.Caption = ds_operation.Tables[0].Rows[operationIndex][1].ToString();
                             operationIndex++;
                             string dimCategories = "";

                             for (int l = 1; l < ds.Tables[0].Columns.Count; l++)
                             {
                                 dimCategories += ds.Tables[0].Columns[l].ColumnName + "\t";
                             }
                             dimCategories = dimCategories.Substring(0, dimCategories.Length - 1);
                             for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
                             {
                                 string dimValues = "";
                                 for (int n = 1; n < ds.Tables[0].Columns.Count; n++)
                                 {
                                     var num1 = ds.Tables[0].Rows[m][n];
                                     if (dsAdd != null)
                                     {
                                         var num2 = dsAdd.Tables[0].Rows[m][n];
                                         dimValues += (Convert.ToDouble(num1 is DBNull ? 0 : num1)
                                                     + Convert.ToDouble(num2 is DBNull ? 0 : num2)).ToString() + "\t";
                                     }
                                     else
                                         dimValues += (num1 is DBNull ? "0\t" : num1.ToString() + "\t");
                                 }
                                 dimValues = dimValues.Substring(0, dimValues.Length - 1);
                                 objChart.SeriesCollection.Add(0);
                                 objChart.SeriesCollection[0].Caption = ds.Tables[0].Rows[m][0].ToString();
                                 objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                                        +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimCategories);
                                 objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                         +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
                             }
                             objSpace.ExportPicture(picturePath, "GIF", 260, 200);
                             picturePath = pictureFolderPath + pictureName;
                             InsertPicture(slide, picturePath, x, 80, 260, 200);

                             int rowCount = ds.Tables[0].Rows.Count;
                             int columnCount = ds.Tables[0].Columns.Count;
                             PowerPoint.Shape shape = slide.Shapes.AddTable(rowCount + 1, columnCount, 385, 300, 700, 200);

                             for (int s = 0; s < rowCount + 1; s++)
                             {
                                 for (int t = 0; t < columnCount; t++)
                                 {
                                     PowerPoint.TextFrame textF = shape.Table.Cell(s + 1, t + 1).Shape.TextFrame;
                                     textF.HorizontalAnchor = Microsoft.Office.Core.MsoHorizontalAnchor.msoAnchorCenter;
                                     PowerPoint.TextRange textR = textF.TextRange;
                                     textR.Font.Bold = MsoTriState.msoTrue;
                                     textR.Font.Size = 4;
                                     if (s == 0)
                                     {
                                         textR.Text = ds.Tables[0].Columns[t].ColumnName;
                                     }
                                     else
                                     {
                                         if (t == 0)
                                         {
                                             var num1 = ds.Tables[0].Rows[s - 1][t];
                                             textR.Text = num1.ToString();
                                         }
                                         else
                                         {
                                             var num1 = ds.Tables[0].Rows[s - 1][t];
                                             if (dsAdd != null)
                                             {
                                                 var num2 = dsAdd.Tables[0].Rows[s - 1][t];
                                                 textR.Text = (Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2)).ToString();
                                             }
                                             else
                                             {
                                                 textR.Text = Convert.ToDouble(num1 is DBNull ? 0 : num1).ToString();
                                             }
                                         }
                                     }
                                 }
                             }
                             shape.Export(picturePath, Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatGIF, 480, 240, Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY);
                             shape.Delete();
                             InsertPicture(slide, picturePath, x + 20, 340, 240, 120);
                             x = 380;

                             x = 380;
                         }
                     }
                 }

             }
         }
    }
Esempio n. 33
0
        //竖状柱状图--各分数段人数比例分析
        public string ChartTypeColumnClustered4()
        {
            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();
            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);

            //设置图表类型,本例使用柱状图
            mychart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
            //设置图表的一些属性
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = "test";
            //添加图表块
            mychart.SeriesCollection.Add(0);
            //设置图表块的属性
            //分类属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, "1\t2\t3\t4\t5\t6\t7");
            //值属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, "200\t100\t343\t270");

            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "200\t100\t343\t270");
            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "200\t100\t343\t270");
            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "200\t100\t343\t270");

            //ChSeries chSeries = mychart.SeriesCollection.Add(0);
            //chSeries.Type = ChartChartTypeEnum.chChartTypeSmoothLine;
            //chSeries.Ungroup(true);

            //ChAxis chAxis = mychart.Axes.Add(chSeries.Scalings[ChartDimensionsEnum.chDimValues]);
            //chAxis.Position = ChartAxisPositionEnum.chAxisPositionRight;

            ////给定系列的值
            //chSeries.SetData
            //    (ChartDimensionsEnum.chDimValues,
            //     (int)ChartSpecialDataSourcesEnum.chDataLiteral, "0\t21\t0\t0\t");

            //chSeries = mychart.SeriesCollection.Add(0);
            //chSeries.Type = ChartChartTypeEnum.chChartTypeLineMarkers;
            //chSeries.Ungroup(true);

            //chAxis = mychart.Axes.Add(chSeries.Scalings[ChartDimensionsEnum.chDimValues]);
            //chAxis.Position = ChartAxisPositionEnum.chAxisPositionRight;

            ////给定系列的值
            //chSeries.SetData
            //    (ChartDimensionsEnum.chDimValues,
            //     (int)ChartSpecialDataSourcesEnum.chDataLiteral, "100\t220\t90\t150\t323\t434");

            //显示百分比
            //ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            //mytb.HasPercentage = true;

            var image = UrlPath("柱状图");
            //生成图片
            mychartSpace.ExportPicture(image, "GIF", 400, 300);

            return image;
        }
    //---------------------------------------------------------------------------------
    protected void DrawSlide_Two()
    {
        slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
        PowerPoint.Slide slide = slides[slideIndex];
        UniformLayout(slide, "Sales Forcast");

        ChartSpace objSpace = new ChartSpace();
        ChChart objChart = objSpace.Charts.Add(0);
        objChart.Type = ChartChartTypeEnum.chChartTypeColumnStacked;
        objChart.HasLegend = true;

        string dimCategories = "";
        DataSet dsAdd = getSlide_TwoAdd();
        DataSet ds = getSlide_Two();
        if (ds != null)
        {
            for (int k = 0; k < ds.Tables[0].Rows.Count; k++)
            {
                string str = ds.Tables[0].Rows[k][0].ToString();
                if (k != ds.Tables[0].Rows.Count - 1)
                    dimCategories += str + "\t";
                else
                    dimCategories += meeting.getnextyear().Trim() + " E/B\t";
            }
            dimCategories = dimCategories.Substring(0, dimCategories.Length - 1);
            for (int i = 0; i < segmentNumber; i++)
            {
                string dimValues = "";
                for (int g = 0; g < ds.Tables[0].Rows.Count; g++)
                {
                    var num1 = ds.Tables[0].Rows[g][i + 1];
                    if (dsAdd != null)
                    {
                        var num2 = dsAdd.Tables[0].Rows[g][i + 1];
                        dimValues += (Convert.ToDouble(num1 is DBNull ? 0 : num1) + Convert.ToDouble(num2 is DBNull ? 0 : num2)).ToString() + "\t";
                    }
                    else
                        dimValues += Convert.ToDouble(num1 is DBNull ? 0 : num1).ToString() + "\t";
                }
                dimValues = dimValues.Substring(0, dimValues.Length - 1);
                objChart.SeriesCollection.Add(i);
                objChart.SeriesCollection[i].Caption = alSegment[i].ToString();

                objChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimCategories,
                       +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimCategories);
                objChart.SeriesCollection[i].SetData(ChartDimensionsEnum.chDimValues,
                        +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
            }
            picturePath = pictureFolderPath + pictureName;
            objSpace.ExportPicture(picturePath, "GIF", 500, 350);
            InsertPicture(slide, picturePath, 60, 160, 600, 350);
            float startPosition = 37;
            double preyearTotal = 0;
            double yearTotal = 0;
            double nextyearTotal = 0;
            for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
            {
                double total = 0;
                for (int n = 1; n < ds.Tables[0].Columns.Count; n++)
                {
                    var num1 = ds.Tables[0].Rows[m][n];
                    total = Convert.ToDouble(num1 is DBNull ? 0 : num1);
                    if (dsAdd != null)
                    {
                        var num2 = dsAdd.Tables[0].Rows[m][n];
                        total += Convert.ToDouble(num2 is DBNull ? 0 : num2);
                    }
                }
                switch (m)
                {
                    case 0:
                        preyearTotal = total;
                        break;
                    case 1:
                        yearTotal = total;
                        break;
                    case 4:
                        nextyearTotal = total;
                        break;
                }
                startPosition += 80;
                InsertText(slide, total.ToString(), startPosition, 80, 50, 20, 10);
            }
            InsertText(slide, "Eur 0’", 600, 20, 50, 30, 14);
            slide.Shapes.AddShape(MsoAutoShapeType.msoShapeCurvedDownArrow, 130, 105, 100, 50);
            slide.Shapes.AddShape(MsoAutoShapeType.msoShapeCurvedDownArrow, 220, 105, 265, 50);

            string recent = String.Format("{0:N1}", 100 * (nextyearTotal - yearTotal) / yearTotal);
            InsertText(slide, recent, 310, 130, 50, 30, 14);
            InsertText(slide, meeting.getyear() + " Standard Exchange", 550, 515, 150, 20, 10);
        }
    }
        private void MakeLineChart(DataTable mDataTable)//string[] DataName,string[] Data,string[] Data1, string[] Data2)
        {
            string strValue1 = "";

            string strValue = "";

            string strValue2 = "";

            string strCateory = "";

            //循环取得数据并格式化为OWC10需要的格式,(加'\t')
            foreach (DataRow mRow in mDataTable.Rows)
            {
                strCateory += mRow[0].ToString() + '\t';
                strValue   += mRow[1].ToString() + '\t';
                strValue1  += mRow[2].ToString() + '\t';
            }



            ChartSpace mySpace = new ChartSpace();
            ChChart    myChart = mySpace.Charts.Add(0);

            myChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;

            myChart.HasLegend = true;
            myChart.HasTitle  = true;
            if (cbDate.Checked == true)
            {
                myChart.Title.Caption = dtpStart.Value.ToString("yyyy年MM月dd日--") + dtpEnd.Value.ToString("yyyy年MM月dd日") + cmbCompareType.Text + "交易曲线图";
            }
            else
            {
                myChart.Title.Caption = "交易曲线图";
            }


            myChart.Axes[0].HasTitle      = true;
            myChart.Axes[0].Title.Caption = mDataTable.Columns[0].Caption;
            myChart.Axes[1].HasTitle      = true;
            myChart.Axes[1].Title.Caption = "总额";


            myChart.SeriesCollection.Add(0);
            //myChart.
            myChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, mDataTable.Columns[1].Caption);
            myChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strCateory);
            ChDataLabels myLabels1 = myChart.SeriesCollection[0].DataLabelsCollection.Add();

            myLabels1.NumberFormat = "0.00";
            myLabels1.HasValue     = true;

            myChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
            if (strValue1 != "")
            {
                myChart.SeriesCollection.Add(1);
                myChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, mDataTable.Columns[2].Caption);
                myChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue1);
                ChDataLabels myLabels2 = myChart.SeriesCollection[1].DataLabelsCollection.Add();
                myLabels2.NumberFormat = "0.00";
                myLabels2.HasValue     = true;
            }
            //if (strValue2 !="")
            //{
            //    myChart.SeriesCollection.Add(2);
            //    myChart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue2);
            //    ChDataLabels myLabels3 = myChart.SeriesCollection[2].DataLabelsCollection.Add();
            //    myLabels3.NumberFormat = "0.00";
            //    myLabels3.HasValue = true;
            //}
            //if (pictureBox1.Image != null)
            //{
            //    pictureBox1.Image.Dispose();
            //}
            string mPath = Application.StartupPath + @"temp.gif"; //临时图片保存地址

            System.IO.File.Delete(mPath);
            mySpace.ExportPicture(mPath, "GIF", pictureBox1.Width, pictureBox1.Height);

            //Image image = Image.FromFile(@"C:\temp.gif");

            //Image image1 = (Image)image.Clone();
            //image.Dispose();
            FileStream mFs = File.OpenRead(mPath);

            pictureBox1.Image = Image.FromStream(mFs);
            mFs.Close();
            //pictureBox1.Size = image.Size;
            //pictureBox1.Visible = true;
        }
    //--------------------------------------------------------
    protected void DrawSlide_Four()
    {
        int slideNum = 0;
         int chartsNum = 0;
         slideNum = (segmentNumber / 2) + (segmentNumber % 2 == 0 ? 0 : 1);
         for (int j = 0; j < slideNum; j++)
         {
             bool isNull = false;
             slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
             PowerPoint.Slide slide = slides[slideIndex];
             UniformLayout(slide, "HP " + meeting.getyear().Trim() + " - " + meeting.getnextyear().Trim() + " Bookings");
             InsertText(slide, "5 Top Countries", 215, 50, 260, 35, 24);
             DataSet[] ds = new DataSet[4];
             DataSet[] ds_FourTotal = new DataSet[4];
             ds[0] = getSlide_Four(meeting.getyear(), alSegment[2 * j].ToString());
             ds_FourTotal[0] = getSlide_FourTotal(meeting.getyear(), alSegment[2 * j].ToString());
             ds[1] = getSlide_Four(meeting.getnextyear(), alSegment[2 * j].ToString());
             ds_FourTotal[1] = getSlide_FourTotal(meeting.getnextyear(), alSegment[2 * j].ToString());
             if ((2 * j + 1) < segmentNumber)
             {
                 ds[2] = getSlide_Four(meeting.getyear(), alSegment[2 * j + 1].ToString());
                 ds_FourTotal[2] = getSlide_FourTotal(meeting.getyear(), alSegment[2 * j + 1].ToString());
                 ds[3] = getSlide_Four(meeting.getnextyear(), alSegment[2 * j + 1].ToString());
                 ds_FourTotal[3] = getSlide_FourTotal(meeting.getnextyear(), alSegment[2 * j + 1].ToString());
             }
             chartsNum = (segmentNumber % 2 == 1 && j == (slideNum - 1) ? 2 : 4);
             for (int k = 0; k < chartsNum; k++)
             {
                 if (ds[k].Tables.Count > 0 && ds[k].Tables[0].Rows.Count > 0)
                 {
                     isNull = true;
                     ChartSpace objSpace = new ChartSpace();
                     ChChart objChart = objSpace.Charts.Add(0);
                     objChart.Type = ChartChartTypeEnum.chChartTypePie3D;
                     objChart.HasLegend = true;
                     objChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;
                     if (k == 0)
                     {
                         objChart.HasTitle = true;
                         objChart.Title.Caption = alSegment[2 * j].ToString().Trim();
                     }
                     if (k == 2)
                     {
                         objChart.HasTitle = true;
                         objChart.Title.Caption = alSegment[2 * j + 1].ToString().Trim();
                     }
                     objChart.SeriesCollection.Add(0);
                     //objChart.SeriesCollection[0].Caption = titile.ToString();
                     objChart.SeriesCollection[0].DataLabelsCollection.Add();

                     string dimCategories = "";
                     string dimValues = "";
                     double total = (double)ds_FourTotal[k].Tables[0].Rows[0][0];
                     double total1 = 0;
                     for (int m = 0; m < ds[k].Tables[0].Rows.Count; m++)
                     {
                         total1 += (double)ds[k].Tables[0].Rows[m][1];
                         dimCategories += ds[k].Tables[0].Rows[m][0].ToString() + "\t";
                         dimValues += String.Format("{0:F}", 100 * (double)ds[k].Tables[0].Rows[m][1] / total) + "\t";
                     }
                     dimCategories += "Others";
                     dimValues += String.Format("{0:F}", 100 * (total - total1) / total);

                     objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                            +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimCategories);
                     objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                         +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValues);
                     objChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
                     objChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
                     objChart.SeriesCollection[0].DataLabelsCollection[0].Position = Microsoft.Office.Interop.Owc11.ChartDataLabelPositionEnum.chLabelPositionCenter;
                     objSpace.ExportPicture(picturePath, "GIF", 260, 200);
                     picturePath = pictureFolderPath + pictureName;
                     if (ds[0].Tables[0].Rows.Count == 0 && ds[1].Tables[0].Rows.Count == 0)
                     {
                         x_four[2] = 215;
                         x_four[3] = 215;
                     }
                     InsertPicture(slide, picturePath, x_four[k], y_four[k], 260, 180);
                 }
             }
             slide.Shapes.AddLine(0, 290, 720, 290);
             InsertText(slide, meeting.getyear().Trim(), 95, 100, 60, 25, 14);
             InsertText(slide, meeting.getnextyear().Trim(), 95, 320, 60, 25, 14);
             if (isNull == false)
             {
                 slideIndex--;
             }
         }
    }
    /*Draw PieChart */
    protected void DrawPieChart()
    {
        Image[] thisimage = { Image1, Image2, Image7, Image6, Image3 };
        string[] fileName = new string[5];
        for (int i = 0; i < 5; i++)
        {
            ChartSpace objSpace = new ChartSpace();
            ChChart objChart = objSpace.Charts.Add(0);
            objChart.Type = ChartChartTypeEnum.chChartTypePie3D;//chChartTypeColumnClustered
            objChart.HasTitle = true;
            objChart.Title.Font.Size = 12;
            objChart.Title.Caption = GetTitle(i);
            objChart.Title.Font.Bold = true;
            objChart.SeriesCollection.Add(0);
            objChart.HasLegend = true;

            objChart.SeriesCollection[0].DataLabelsCollection.Add();
            objChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
            objChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
            objChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionAutomatic;

            string dimCatgories = GetDimCategories(i);
            string dimVales = GetDimValues(i);

            objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                   +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimCatgories);

            objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                    +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimVales);

            Random ro = new Random();
            int a = ro.Next();
            dateI = a.ToString();

            fileName[i] = "pchart" + i.ToString() + dateI + ".gif";
            string filePath = Server.MapPath("~");
            filePath = filePath + @"\ChartImages\" + fileName[i];
            objSpace.ExportPicture(filePath, "gif", 250, 200);
            thisimage[i].ImageUrl = "~/ChartImages/" + fileName[i];
            if (dimVales != null)
            {
                thisimage[i].Visible = true;
            }
            thisimage[i].Dispose();
        }
    }
    //--------------------------------------------------------------------------
    protected void DrawSlide_Nine()
    {
        slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
         PowerPoint.Slide slide = slides[slideIndex];
         UniformLayout(slide, "BOOKING BY REGIONS");
         ChartSpace objSpace = new ChartSpace();
         ChChart objChart = objSpace.Charts.Add(0);
         DataSet ds_dimValues = getSlide_Nine();
         if (ds_dimValues.Tables[0].Rows.Count > 0)
         {

             objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
             //string dimCategories = "";
             string dimValuesYear = "";
             string dimValuesNextYear = "";

             for (int k = 1; k < ds_dimValues.Tables[0].Columns.Count; k++)
             {
                 var num1 = ds_dimValues.Tables[0].Rows[0][k];
                 var num2 = ds_dimValues.Tables[0].Rows[1][k];
                 if (num1 is DBNull)
                     dimValuesYear += "0\t";
                 else
                     dimValuesYear += num1.ToString() + "\t";
                 if (num2 is DBNull)
                     dimValuesNextYear += "0\t";
                 else
                     dimValuesNextYear += num2.ToString() + "\t";
             }
             dimValuesYear = dimValuesYear.Substring(0, dimValuesYear.Length - 1);
             dimValuesNextYear = dimValuesNextYear.Substring(0, dimValuesNextYear.Length - 1);

             objChart.SeriesCollection.Add(0);
             objChart.SeriesCollection.Add(1);
             objChart.HasLegend = true;
             objChart.HasTitle = true;
             objChart.Title.Font.Size = 12;
             objChart.Title.Font.Bold = true;
             objChart.Title.Caption = "All Region";
             objChart.SeriesCollection[0].Caption = meeting.getyear().Substring(2, 2).Trim() + " A";
             objChart.SeriesCollection[1].Caption = meeting.getnextyear().Substring(2, 2).Trim() + " F";

             objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                    +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimRegionCategories);
             objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                     +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValuesYear);

             objChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimCategories,
                    +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimRegionCategories);
             objChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues,
                     +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValuesNextYear);
         }
         objSpace.ExportPicture(picturePath, "GIF", 500, 400);
         picturePath = pictureFolderPath + pictureName;
         InsertPicture(slide, picturePath, 80, 120, 500, 400);
    }
Esempio n. 39
0
        //饼图
        public string ChartTypePie()
        {
            //创建X坐标的值,表示月份
            int[] Month = { 1, 2, 3, 4, 5, 6 };
            //创建Y坐标的值,表示销售额
            double[] Count = { 120, 240, 220, 343, 32, 54 };
            string strDataName = "";
            string strData = "";

            //创建图表空间
            var mychartSpace = new ChartSpace();
            //在图表空间内添加一个图表对象
            var mychart = mychartSpace.Charts.Add(0);

            //设置每块饼的数据
            for (int i = 0; i < Count.Length - 1; i++)
            {
                strDataName += Month[i] + "\t";
                strData += Count[i].ToString() + "\t";
            }
            strDataName += Month[Count.Length - 1];
            strData += Count[Count.Length - 1].ToString();

            //设置图表类型,本例使用饼图
            mychart.Type = ChartChartTypeEnum.chChartTypePie;
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = "test";
            //添加图表块
            mychart.SeriesCollection.Add(0);
            //分类属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName);
            //值属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, strData);

            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "200\t100\t343\t270\t235\t343");

            //给第一个扇区设置自定义背景图片
            mychart.SeriesCollection[0].Points[0].Interior.SetTextured("E:\\Projects\\DotNetNuke\\images\\add.gif", ChartTextureFormatEnum.chTile, 1, ChartTexturePlacementEnum.chFrontSides);
            //给第二个扇区设置从中心向四周辐射的单色渐变
            mychart.SeriesCollection[0].Points[1].Interior.SetOneColorGradient(ChartGradientStyleEnum.chGradientFromCenter, ChartGradientVariantEnum.chGradientVariantStart, 0.3, "Blue");
            //给第三个扇区设置倾斜双色渐变
            mychart.SeriesCollection[0].Points[2].Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientDiagonalDown, ChartGradientVariantEnum.chGradientVariantCenter, "Green", "Red");
            //给第四个扇区设置OWC预设的纹理,并设置纹理的背景色为淡绿色,前景色为红色
            //OWC提供了很多纹理,这是其中一种
            //具体的纹理样式可以参看帮助中的ChartPatternTypeEnum枚举
            mychart.SeriesCollection[0].Points[3].Interior.SetPatterned(ChartPatternTypeEnum.chPatternDiagonalBrick, "Red", "LightGreen");
            //给第五个扇区设置OWC预设的倾斜,
            //OWC提供了许多种的倾斜,这是其中一种
            //具体的倾斜可以参看帮助中的ChartPresetGradientTypeEnum枚举
            mychart.SeriesCollection[0].Points[4].Interior.SetPresetGradient(ChartGradientStyleEnum.chGradientDiagonalUp, ChartGradientVariantEnum.chGradientVariantEdges, ChartPresetGradientTypeEnum.chGradientGoldII);

            //显示百分比
            ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            mytb.HasPercentage = true;

            var image = UrlPath("饼图");
            //生成图片
            mychartSpace.ExportPicture(image, "GIF", 400, 300);
            return image;
        }
    // -------------------------------------------------------------
    protected void DrawSlide_Seven()
    {
        int slideNum = segmentNumber / 3 + (segmentNumber % 3 == 0 ? 0 : 1);
         for (int i = 0; i < slideNum; i++)
         {
             bool isNull = false;
             slides.Add(++slideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
             PowerPoint.Slide slide = slides[slideIndex];
             UniformLayout(slide, "BOOKING BY REGIONS");
             int chartNum = 3;
             if (i == (slideNum - 1))
             {
                 switch (segmentNumber % 3)
                 {
                     case 1:
                         chartNum = 1;
                         break;
                     case 2:
                         chartNum = 2;
                         break;
                 }
             }

             DataSet[] ds = new DataSet[chartNum];
             for (int j = 0; j < chartNum; j++)
             {
                 float[] x = { 60, 370, 215 };
                 float[] y = { 80, 80, 380 };
                 ds[j] = getSlide_Seven(alSegment[3 * i + j].ToString());
                 if (ds[j].Tables.Count > 0 && ds[j].Tables[0].Rows.Count > 0)
                 {
                     isNull = true;
                     ChartSpace objSpace = new ChartSpace();
                     ChChart objChart = objSpace.Charts.Add(0);
                     objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
                     string dimValuesYear = "";
                     string dimValuesNextYear = "";
                     for (int k = 0; k < regionNumber; k++)
                     {
                         dimValuesYear += ds[j].Tables[0].Rows[0][k + 1].ToString().Trim() + "\t";
                         if (ds[j].Tables[0].Rows.Count > 1)
                             dimValuesNextYear += ds[j].Tables[0].Rows[1][k + 1].ToString().Trim() + "\t";
                         else
                             dimValuesNextYear += " \t";
                     }
                     for (int l = 0; l < 2; l++)
                     {
                         objChart.SeriesCollection.Add(l);
                         objChart.HasTitle = true;
                         objChart.HasLegend = true;
                         objChart.Title.Font.Size = 12;
                         objChart.Title.Font.Bold = true;

                         objChart.Title.Caption = alSegment[3 * i + j].ToString().Trim() + " Regions";
                         if (ds[j].Tables[0].Rows.Count > 1)
                         {
                             objChart.SeriesCollection[l].Caption = ds[j].Tables[0].Rows[l][0].ToString();
                             objChart.SeriesCollection[l].SetData(ChartDimensionsEnum.chDimCategories,
                                        +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimRegionCategories);
                         }
                     }
                     objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                 +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValuesYear);
                     objChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues,
                                 +(int)ChartSpecialDataSourcesEnum.chDataLiteral, dimValuesNextYear);

                     objSpace.ExportPicture(picturePath, "GIF", 500, 400);
                     picturePath = pictureFolderPath + pictureName;
                     if (chartNum == 3)
                     {
                         if (ds[0].Tables.Count == 0 || ds[0].Tables[0].Rows.Count == 0)
                         {
                             x[1] = x[0];
                             y[1] = y[0];
                         }
                         if (ds[0].Tables.Count == 0 || ds[0].Tables[0].Rows.Count == 0)
                         {
                             x[2] = x[1];
                             y[2] = y[1];
                         }
                     }
                     InsertPicture(slide, picturePath, x[j], y[j], 500, 400);
                 }

             }
             if (isNull == false)
             {
                 slideIndex--;
             }
         }
    }
Esempio n. 41
0
        /// <summary>
        /// 雷达图--学科均衡性分析
        /// </summary>
        /// <param name="strDataName">分类管理名字</param>
        /// <param name="data1">元数据</param>
        /// <param name="data2">比较数据</param>
        /// <returns></returns>
        public string ChartTypeRadarLine(string strDataName, string data1, string data2)
        {
            //创建图表空间
            var mychartSpace = new ChartSpace();
            //在图表空间内添加一个图表对象
            var mychart = mychartSpace.Charts.Add(0);
            //设置图表类型,本例使用雷达图
            mychart.Type = ChartChartTypeEnum.chChartTypeRadarLineFilled;
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = "test";
            //添加图表块
            var chart1 = mychart.SeriesCollection.Add(0);
            //分类属性
            chart1.SetData(ChartDimensionsEnum.chDimCategories,
                           (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName);
            //值属性
            chart1.SetData(ChartDimensionsEnum.chDimValues,
                           (int)ChartSpecialDataSourcesEnum.chDataLiteral, data1);

            chart1.Interior.Color = "red";

            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, data2);

            //显示百分比
            ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            //mytb.HasPercentage = true;

            var image = UrlPath("雷达");

            //生成图片
            mychartSpace.ExportPicture(image, "GIF", 400, 300);

            return image;
        }
Esempio n. 42
0
        //void InitBasicStylePart(WorkbookPart workbookPart) {
        //	WorkbookStylesPart stylesPart;
        //	if (!workbookPart.GetPartsOfType<WorkbookStylesPart>().Any()) {
        //		stylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
        //		stylesPart.Stylesheet = new Stylesheet();
        //		var stylesheet = stylesPart.Stylesheet;
        //		stylesheet.Fonts = new DocumentFormat.OpenXml.Spreadsheet.Fonts(
        //			new Font(
        //				new FontSize() { Val = 11 },
        //				new Color() { Theme = 1 }
        //			)
        //		);

        //		stylesheet.CellStyleFormats = new CellStyleFormats();
        //		stylesheet.CellStyleFormats.Append(new CellFormat());
        //		stylesheet.CellFormats = new CellFormats();
        //	}
        //	var cellFormat = stylesheet.CellFormats.Elements<CellFormat>().FirstOrDefault(cf => cf.FormatId == cellStyle.FormatId)
        //	   ?? stylesheet.CellFormats.AppendChild(new CellFormat() {
        //		   FormatId = cellStyle.FormatId,
        //	   });


        //	if (stylesheet.CellStyles == null) {
        //		stylesheet.CellStyles = new CellStyles();
        //	}
        //	var cellStyles = stylesheet.CellStyles;
        //	var cellStyle = cellStyles.Elements<CellStyle>().FirstOrDefault(cs => cs.Name == "Hyperlink")
        //		?? cellStyles.AppendChild(new CellStyle() {
        //			Name = "Hyperlink",
        //			BuiltinId = 8,
        //			FormatId = 0 //index 0 from cellstyleformats
        //					});



        //}

        void Save(SpreadsheetDocument spreadsheetDocument)
        {
            //Create workbook parts
            var workbookPart = spreadsheetDocument.AddWorkbookPart();
            //Sets workbook
            var workbook = new Workbook();

            workbookPart.Workbook = workbook;

            //Shared string
            var sharedStringPart = workbookPart.AddNewPart <SharedStringTablePart>();

            sharedStringPart.SharedStringTable = new SharedStringTable();

            //Set theme
            using (var stream = GetType().GetTypeInfo().Assembly.GetManifestResourceStream("Genexcel.Resources.Office.theme1.xml")) {
                using (var reader = new StreamReader(stream)) {
                    var xml = reader.ReadToEnd();
                    workbookPart.AddNewPart <ThemePart>();
                    workbookPart.ThemePart.Theme = new Theme(xml);
                }
            }

            //Set styles
            using (var stream = GetType().GetTypeInfo().Assembly.GetManifestResourceStream("Genexcel.Resources.Office.styles.xml")) {
                using (var reader = new StreamReader(stream)) {
                    var xml = reader.ReadToEnd();
                    workbookPart.AddNewPart <WorkbookStylesPart>();
                    workbookPart.WorkbookStylesPart.Stylesheet = new Stylesheet(xml);
                }
            }


            //Adiciona lista sheets
            var sheets = workbook.AppendChild(new Sheets());

            //Adiciona as planilhas ao workbook
            uint sheetId            = 1;
            int  sharedStringsIndex = 0;

            foreach (var s in _sheets)
            {
                //Criar worksheet part no workbookpart
                var worksheetPart = workbookPart.AddNewPart <WorksheetPart>();
                var worksheet     = new Worksheet();
                //Columns
                if (s.HasCustomColumn)
                {
                    var columns = new Columns();
                    worksheet.Append(columns);
                    Column        currentColElement = null;
                    Models.Column currentColModel   = new Models.Column();                  //fake current
                    for (uint i = 0; i < s.Columns.Length; i++)
                    {
                        var col = s.Columns[i];
                        if (col == currentColModel)
                        {
                            currentColElement.Max = i + 1;
                        }
                        else
                        {
                            currentColElement = new Column()
                            {
                                //Style = 1,
                                Min = i + 1,
                                Max = i + 1,
                                //CustomWidth = false,
                                Width = Models.Column.DEFAULT_WIDTH
                            };
                            if (col != null)
                            {
                                currentColElement.CustomWidth = true;
                                currentColElement.Width       = col.Width;
                            }
                            columns.Append(currentColElement);
                        }
                        currentColModel = col;
                    }

                    //Column currentColumnElement = null;
                    //Models.Column currentColumnModel = null;
                    //foreach (var col in s.Columns) {
                    //	Column colElement;
                    //	if(col == currentColumnModel) { colElement = currentColumnElement }
                    //	if(col == null) {

                    //	}
                    //	columns.Append(new Column() {
                    //		Min = (uint)col.Min,
                    //		Max = (uint)col.Max,
                    //		Width = col.Width,
                    //		Style = 1,
                    //		CustomWidth = true
                    //	});
                    //}
                }
                var sheetData = new SheetData();
                worksheet.Append(sheetData);
                worksheetPart.Worksheet = worksheet;

                var name = s.Name ?? "Plan";
                name = name.Length > _sheetNameLengthLimit?
                       name.Substring(0, _sheetNameLengthLimit) :
                           name;

                // Append a new worksheet and associate it with the workbook.
                var sheet = new DocumentFormat.OpenXml.Spreadsheet.Sheet()
                {
                    Id      = workbookPart.GetIdOfPart(worksheetPart),
                    SheetId = sheetId++,
                    Name    = name
                };
                sheets.Append(sheet);



                Dictionary <uint, Row>    dctRows  = new Dictionary <uint, Row>();
                Dictionary <string, Cell> dctCells = new Dictionary <string, Cell>();
                foreach (var c in s.GetCells())
                {
                    // Insert cell A1 into the new worksheet.
                    Cell cell;                    // = InsertCellInWorksheet(ColTranslate(c.Col), (uint)c.Row, worksheetPart);
                    //Worksheet worksheet = worksheetPart.Worksheet;
                    //SheetData sheetData = worksheet.GetFirstChild<SheetData>();
                    var    columnName    = ColTranslate(c.Col);
                    var    rowIndex      = (uint)c.Row;
                    string cellReference = columnName + rowIndex;

                    // If the worksheet does not contain a row with the specified row index, insert one.
                    Row row;
                    if (dctRows.ContainsKey(rowIndex))
                    {
                        row = dctRows[rowIndex];
                    }
                    //else if (sheetData.Elements<Row>().Where(r => r.RowIndex == rowIndex).Count() != 0) {
                    //	row = sheetData.Elements<Row>().Where(r => r.RowIndex == rowIndex).First();
                    //}
                    else
                    {
                        row = new Row()
                        {
                            RowIndex = rowIndex
                        };
                        sheetData.Append(row);
                        dctRows[rowIndex] = row;
                    }

                    // If there is not a cell with the specified column name, insert one.
                    //if (row.Elements<Cell>().Where(c => c.CellReference.Value == columnName + rowIndex).Count() > 0) {
                    //return row.Elements<Cell>().Where(c => c.CellReference.Value == cellReference).First();
                    //}
                    if (dctCells.ContainsKey(cellReference))
                    {
                        cell = dctCells[cellReference];
                    }
                    else
                    {
                        // Cells must be in sequential order according to CellReference. Determine where to insert the new cell.
                        //Cell refCell = null;
                        //foreach (var cell in row.Elements<Cell>()) {
                        //	if (string.Compare(cell.CellReference.Value, cellReference, true) > 0) {
                        //		refCell = cell;
                        //		break;
                        //	}
                        //}

                        var newCell = new Cell()
                        {
                            CellReference = cellReference
                        };
                        //row.InsertBefore(newCell, refCell);
                        row.Append(newCell);

                        dctCells[cellReference] = newCell;
                        //worksheet.Save();
                        cell = newCell;
                    }

                    var value = c.Value;
                    if (value is string)
                    {
                        int index;
                        var str = value.ToString();
                        //str = "TESTE VELOCIDADE";
                        if (_dctSharedStrings.ContainsKey(str))
                        {
                            index = _dctSharedStrings[str];
                        }
                        else
                        {
                            index = sharedStringsIndex++;
                            sharedStringPart.SharedStringTable.AppendChild(new SharedStringItem(new DocumentFormat.OpenXml.Spreadsheet.Text(str)));
                            //shareStringPart.SharedStringTable.Save();
                            _dctSharedStrings[str] = index;
                        }
                        //int index = InsertSharedStringItem(value.ToString(), sharedStringPart);

                        cell.CellValue = new CellValue(index.ToString());
                        cell.DataType  = new EnumValue <CellValues>(CellValues.SharedString);
                    }
                    else if (value  is int ||
                             value is decimal ||
                             value is long ||
                             value is short ||
                             value is double ||
                             value is float ||
                             value is byte)
                    {
                        var toString = value.GetType().GetTypeInfo()
                                       .GetDeclaredMethods("ToString")
                                       .First(m => m.GetParameters().Any(p => p.ParameterType == typeof(IFormatProvider)));                 //.GetMethod("ToString", new Type[] { typeof(CultureInfo) }).GetMethodInfo();
                        var formattedValue = toString.Invoke(value, new object[] { new CultureInfo("en-US") }).ToString();
                        cell.CellValue = new CellValue(formattedValue);
                        cell.DataType  = new EnumValue <CellValues>(CellValues.Number);
                    }

                    if (!string.IsNullOrWhiteSpace(c.Hyperlink))
                    {
                        var rId = $"r{Guid.NewGuid().ToString()}";
                        //if (workbookPart.GetPartsOfType<Relat>().Any()) {
                        //	shareStringPart = worksheet.getp.GetPartsOfType<SharedStringTablePart>().First();
                        //} else {
                        //	shareStringPart = workbookPart.AddNewPart<SharedStringTablePart>();
                        //}
                        var rel        = worksheetPart.AddHyperlinkRelationship(new Uri(c.Hyperlink), true, rId);
                        var hyperlinks = worksheet.Elements <Hyperlinks>().FirstOrDefault();
                        if (hyperlinks == null)
                        {
                            hyperlinks = worksheet.AppendChild(new Hyperlinks());
                        }
                        hyperlinks.Append(new DocumentFormat.OpenXml.Spreadsheet.Hyperlink()
                        {
                            Reference = cell.CellReference,
                            Id        = rId
                        });

                        cell.StyleIndex = 2;                        //Hyperlink, should be an enum
                    }
                }


                //Charts
                foreach (var ch in s.Charts)
                {
                    //https://msdn.microsoft.com/en-us/library/office/cc820055.aspx#How the Sample Code Works
                    // Add a new drawing to the worksheet.
                    var drawingsPart = worksheetPart.AddNewPart <DrawingsPart>();
                    worksheetPart.Worksheet.Append(new Drawing()
                    {
                        Id = worksheetPart.GetIdOfPart(drawingsPart)
                    });
                    worksheetPart.Worksheet.Save();
                    var chartPart  = drawingsPart.AddNewPart <ChartPart>();
                    var chartSpace = new ChartSpace();
                    chartPart.ChartSpace = chartSpace;
                    chartSpace.Append(new Date1904()
                    {
                        Val = false
                    });
                    chartSpace.Append(new EditingLanguage()
                    {
                        Val = "en-US"
                    });
                    chartSpace.Append(new RoundedCorners()
                    {
                        Val = false
                    });
                    var chart = chartSpace.AppendChild(new DocumentFormat.OpenXml.Drawing.Charts.Chart());
                    //chartSpace.Append(new ChartShapeProperties(
                    //						new SolidFill(
                    //							new SchemeColor() { Val = SchemeColorValues.Background1 }
                    //						),
                    //						new DocumentFormat.OpenXml.Drawing.Outline(
                    //							new SolidFill(
                    //								new SchemeColor(
                    //									new LuminanceModulation() { Val = 15000 },
                    //									new LuminanceOffset() { Val = 85000 }
                    //								) { Val = SchemeColorValues.Text1 }
                    //							)
                    //						) {
                    //							Width = 9525,
                    //							CapType = LineCapValues.Flat,
                    //							CompoundLineType = CompoundLineValues.Single,
                    //							Alignment = PenAlignmentValues.Center
                    //						}
                    //				));

                    //Dont know
                    chart.AppendChild(new Title(
                                          new Overlay()
                    {
                        Val = false
                    },
                                          new ChartShapeProperties(
                                              new NoFill(),
                                              new DocumentFormat.OpenXml.Drawing.Outline(new NoFill()),
                                              new EffectList()
                                              ),
                                          new DocumentFormat.OpenXml.Drawing.Charts.TextProperties(
                                              new BodyProperties()
                    {
                        Rotation            = 0,
                        UseParagraphSpacing = true,
                        VerticalOverflow    = TextVerticalOverflowValues.Ellipsis,
                        Vertical            = TextVerticalValues.Horizontal,
                        Wrap         = TextWrappingValues.Square,
                        Anchor       = TextAnchoringTypeValues.Center,
                        AnchorCenter = true,
                    },
                                              new Paragraph(
                                                  new ParagraphProperties(
                                                      new DefaultRunProperties(
                                                          new SolidFill(
                                                              new SchemeColor(
                                                                  new LuminanceModulation()
                    {
                        Val = 65000
                    },
                                                                  new LuminanceOffset()
                    {
                        Val = 35000
                    }
                                                                  )
                    {
                        Val = SchemeColorValues.Text1
                    }
                                                              ),
                                                          new LatinFont()
                    {
                        Typeface = "+mn-lt"
                    },
                                                          new EastAsianFont()
                    {
                        Typeface = "+mn-ea"
                    },
                                                          new ComplexScriptFont()
                    {
                        Typeface = "+mn-cs"
                    }
                                                          )
                    {
                        FontSize  = 1400,
                        Bold      = false,
                        Italic    = false,
                        Underline = TextUnderlineValues.None,
                        Strike    = TextStrikeValues.NoStrike,
                        Kerning   = 1200,
                        Baseline  = 0
                    }
                                                      )
                                                  )
                                              )
                                          ));

                    //Allow showing title on top
                    chart.AppendChild(new AutoTitleDeleted()
                    {
                        Val = false
                    });

                    //Create plot area
                    var plotArea = chart.AppendChild(new PlotArea());

                    var layout = plotArea.AppendChild(new Layout());
                    if (ch is Models.AreaChart || ch is Models.BarChart)
                    {
                        #region init chart
                        var chObject = ch as Models.Chart;
                        OpenXmlCompositeElement chartElement;
                        if (ch is Models.AreaChart)
                        {
                            chartElement = plotArea.AppendChild(
                                //Dont know what extensions are for
                                new AreaChart(new Grouping()
                            {
                                Val = GroupingValues.Standard
                            })
                                );
                        }
                        else
                        {
                            chartElement = plotArea.AppendChild(
                                //Dont know what extensions are for
                                new BarChart(
                                    new BarDirection()
                            {
                                Val = BarDirectionValues.Column
                            },
                                    new BarGrouping()
                            {
                                Val = BarGroupingValues.Clustered
                            })
                                );
                        }
                        chartElement.AppendChild(new VaryColors()
                        {
                            Val = false
                        });
                        #endregion

                        #region data
                        foreach (var dts in chObject.Data.Datasets)
                        {
                            var index = (uint)chObject.Data.Datasets.IndexOf(dts);
                            OpenXmlCompositeElement chartSeries;
                            if (ch is Models.AreaChart)
                            {
                                chartSeries = chartElement.AppendChild(new AreaChartSeries());
                            }
                            else
                            {
                                chartSeries = chartElement.AppendChild(new BarChartSeries());
                            }
                            chartSeries.Append(
                                new Index()
                            {
                                Val = index
                            },
                                new Order()
                            {
                                Val = index
                            },
                                new SeriesText()
                            {
                                NumericValue = new NumericValue(dts.Title)
                            },
                                new ChartShapeProperties(
                                    new SolidFill(new SchemeColor()
                            {
                                Val = SchemeColorValues.Accent1
                            }),
                                    new DocumentFormat.OpenXml.Drawing.Outline(new NoFill()),
                                    new EffectList()
                                    )
                                );

                            if (ch is Models.BarChart)
                            {
                                chartSeries.Append(new InvertIfNegative()
                                {
                                    Val = false
                                });
                            }


                            //Eixo x (labels)
                            var categoryAxisData = chartSeries.AppendChild(new CategoryAxisData());
                            var strLit           = categoryAxisData.AppendChild(new StringLiteral());
                            strLit.Append(new PointCount()
                            {
                                Val = (uint)chObject.Data.Labels.Count
                            });
                            foreach (var lbl in chObject.Data.Labels)
                            {
                                strLit.AppendChild(new StringPoint()
                                {
                                    Index = (uint)chObject.Data.Labels.IndexOf(lbl)
                                })
                                .Append(new NumericValue(lbl));
                            }

                            var values = chartSeries.AppendChild(new DocumentFormat.OpenXml.Drawing.Charts.Values());
                            var numLit = values.AppendChild(new NumberLiteral());
                            numLit.Append(new FormatCode("General"));
                            numLit.Append(new PointCount()
                            {
                                Val = (uint)chObject.Data.Labels.Count
                            });
                            foreach (var lbl in chObject.Data.Labels)
                            {
                                var lblIndex = chObject.Data.Labels.IndexOf(lbl);
                                var val      = dts.Data.Count > lblIndex ? dts.Data[lblIndex] : 0;
                                numLit.AppendChild(new NumericPoint()
                                {
                                    Index = (uint)chObject.Data.Labels.IndexOf(lbl)
                                })
                                .Append(new NumericValue(val.ToString()));
                            }
                            //			numLit.AppendChild(new NumericPoint() { Index = new UInt32Value(0u) })
                            //	.Append
                            //(new NumericValue("28"));
                        }
                        #endregion

                        #region options?
                        //Not required for a valid xlsx
                        chartElement
                        .AppendChild(
                            new DataLabels(
                                new ShowLegendKey()
                        {
                            Val = false
                        },
                                new ShowValue()
                        {
                            Val = false
                        },
                                new ShowCategoryName()
                        {
                            Val = false
                        },
                                new ShowSeriesName()
                        {
                            Val = false
                        },
                                new ShowPercent()
                        {
                            Val = false
                        },
                                new ShowBubbleSize()
                        {
                            Val = false
                        }
                                )
                            );

                        if (ch is Models.BarChart)
                        {
                            chartElement.Append(new GapWidth()
                            {
                                Val = 219
                            });
                            chartElement.Append(new Overlap()
                            {
                                Val = -27
                            });
                        }
                        #endregion

                        #region Axis
                        chartElement.Append(new AxisId()
                        {
                            Val = 48650112u
                        });
                        chartElement.Append(new AxisId()
                        {
                            Val = 48672768u
                        });

                        // Add the Category Axis.
                        var catAx = plotArea
                                    .AppendChild(
                            new CategoryAxis(
                                new AxisId()
                        {
                            Val = 48650112u
                        },
                                new Scaling(
                                    new Orientation()
                        {
                            Val = DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax
                        }
                                    ),
                                new Delete()
                        {
                            Val = false
                        },
                                new AxisPosition()
                        {
                            Val = AxisPositionValues.Bottom
                        },
                                new DocumentFormat.OpenXml.Drawing.Charts.NumberingFormat()
                        {
                            FormatCode   = "General",
                            SourceLinked = true
                        },
                                new MajorTickMark()
                        {
                            Val = ch is Models.AreaChart ? TickMarkValues.Outside : TickMarkValues.None
                        },
                                new MinorTickMark()
                        {
                            Val = TickMarkValues.None
                        },
                                new TickLabelPosition()
                        {
                            Val = TickLabelPositionValues.NextTo
                        },
                                new ChartShapeProperties(
                                    new NoFill(),
                                    new DocumentFormat.OpenXml.Drawing.Outline(
                                        new SolidFill(
                                            new SchemeColor(
                                                new LuminanceModulation()
                        {
                            Val = 15000
                        },
                                                new LuminanceOffset()
                        {
                            Val = 85000
                        }
                                                )
                        {
                            Val = SchemeColorValues.Text1
                        }
                                            )
                                        )
                        {
                            Width            = 9525,
                            CapType          = LineCapValues.Flat,
                            CompoundLineType = CompoundLineValues.Single,
                            Alignment        = PenAlignmentValues.Center
                        }
                                    ),
                                new DocumentFormat.OpenXml.Drawing.Charts.TextProperties(
                                    new BodyProperties()
                        {
                            Rotation            = -60000000,
                            UseParagraphSpacing = true,
                            VerticalOverflow    = TextVerticalOverflowValues.Ellipsis,
                            Vertical            = TextVerticalValues.Horizontal,
                            Wrap         = TextWrappingValues.Square,
                            Anchor       = TextAnchoringTypeValues.Center,
                            AnchorCenter = true,
                        },
                                    new Paragraph(
                                        new ParagraphProperties(
                                            new DefaultRunProperties(
                                                new SolidFill(
                                                    new SchemeColor(
                                                        new LuminanceModulation()
                        {
                            Val = 65000
                        },
                                                        new LuminanceOffset()
                        {
                            Val = 35000
                        }
                                                        )
                        {
                            Val = SchemeColorValues.Text1
                        }
                                                    ),
                                                new LatinFont()
                        {
                            Typeface = "+mn-lt"
                        },
                                                new EastAsianFont()
                        {
                            Typeface = "+mn-ea"
                        },
                                                new ComplexScriptFont()
                        {
                            Typeface = "+mn-cs"
                        }
                                                )
                        {
                            FontSize  = 900,
                            Bold      = false,
                            Italic    = false,
                            Underline = TextUnderlineValues.None,
                            Strike    = TextStrikeValues.NoStrike,
                            Kerning   = 1200,
                            Baseline  = 0
                        }
                                            ),
                                        new EndParagraphRunProperties()
                        {
                            Language = "en-US"
                        }
                                        )
                                    ),
                                new CrossingAxis()
                        {
                            Val = 48672768U
                        },
                                new Crosses()
                        {
                            Val = CrossesValues.AutoZero
                        },
                                new AutoLabeled()
                        {
                            Val = true
                        },
                                new LabelAlignment()
                        {
                            Val = LabelAlignmentValues.Center
                        },
                                new LabelOffset()
                        {
                            Val = 100
                        },
                                new NoMultiLevelLabels()
                        {
                            Val = false
                        }
                                )
                            );

                        // Add the Value Axis.
                        var valAx = plotArea
                                    .AppendChild(
                            new ValueAxis(
                                new AxisId()
                        {
                            Val = 48672768u
                        },
                                new Scaling(new Orientation()
                        {
                            Val = DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax
                        }),
                                new Delete()
                        {
                            Val = false
                        },
                                new AxisPosition()
                        {
                            Val = AxisPositionValues.Left
                        },
                                new MajorGridlines(
                                    new ChartShapeProperties(
                                        new DocumentFormat.OpenXml.Drawing.Outline(
                                            new SolidFill(
                                                new SchemeColor(
                                                    new LuminanceModulation()
                        {
                            Val = 15000
                        },
                                                    new LuminanceOffset()
                        {
                            Val = 85000
                        }
                                                    )
                        {
                            Val = SchemeColorValues.Text1
                        }
                                                ),
                                            new Round()
                                            )
                        {
                            Width            = 9525,
                            CapType          = LineCapValues.Flat,
                            CompoundLineType = CompoundLineValues.Single,
                            Alignment        = PenAlignmentValues.Center
                        },
                                        new EffectList()
                                        )
                                    ),
                                new DocumentFormat.OpenXml.Drawing.Charts.NumberingFormat()
                        {
                            FormatCode   = "General",
                            SourceLinked = true
                        },
                                new MajorTickMark()
                        {
                            Val = TickMarkValues.None
                        },
                                new MinorTickMark()
                        {
                            Val = TickMarkValues.None
                        },
                                new TickLabelPosition()
                        {
                            Val = TickLabelPositionValues.NextTo
                        },
                                new ChartShapeProperties(
                                    new NoFill(),
                                    new DocumentFormat.OpenXml.Drawing.Outline(new NoFill()),
                                    new EffectList()
                                    ),
                                new DocumentFormat.OpenXml.Drawing.Charts.TextProperties(
                                    new BodyProperties()
                        {
                            Rotation            = -60000000,
                            UseParagraphSpacing = true,
                            VerticalOverflow    = TextVerticalOverflowValues.Ellipsis,
                            Vertical            = TextVerticalValues.Horizontal,
                            Wrap         = TextWrappingValues.Square,
                            Anchor       = TextAnchoringTypeValues.Center,
                            AnchorCenter = true,
                        },
                                    new Paragraph(
                                        new ParagraphProperties(
                                            new DefaultRunProperties(
                                                new SolidFill(
                                                    new SchemeColor(
                                                        new LuminanceModulation()
                        {
                            Val = 65000
                        },
                                                        new LuminanceOffset()
                        {
                            Val = 35000
                        }
                                                        )
                        {
                            Val = SchemeColorValues.Text1
                        }
                                                    ),
                                                new LatinFont()
                        {
                            Typeface = "+mn-lt"
                        },
                                                new EastAsianFont()
                        {
                            Typeface = "+mn-ea"
                        },
                                                new ComplexScriptFont()
                        {
                            Typeface = "+mn-cs"
                        }
                                                )
                        {
                            FontSize  = 900,
                            Bold      = false,
                            Italic    = false,
                            Underline = TextUnderlineValues.None,
                            Strike    = TextStrikeValues.NoStrike,
                            Kerning   = 1200,
                            Baseline  = 0
                        }
                                            ),
                                        new EndParagraphRunProperties()
                        {
                            Language = "en-US"
                        }
                                        )
                                    ),
                                new CrossingAxis()
                        {
                            Val = 48650112U
                        },
                                new Crosses()
                        {
                            Val = CrossesValues.AutoZero
                        },
                                new CrossBetween()
                        {
                            Val = ch is Models.AreaChart ? CrossBetweenValues.MidpointCategory : CrossBetweenValues.Between
                        })
                            );
                        // Add the chart Legend.
                        //Legend legend = chart.AppendChild(new Legend(new LegendPosition() { Val = new EnumValue<LegendPositionValues>(LegendPositionValues.Right) },
                        //	new Layout()));

                        chart.Append(new PlotVisibleOnly()
                        {
                            Val = true
                        });
                        chart.Append(new DisplayBlanksAs()
                        {
                            Val = ch is Models.AreaChart ? DisplayBlanksAsValues.Zero : DisplayBlanksAsValues.Gap
                        });
                        chart.Append(new ShowDataLabelsOverMaximum()
                        {
                            Val = false
                        });
                        #endregion

                        // Save the chart part.
                        chartPart.ChartSpace.Save();
                    }

                    #region position?
                    // Position the chart on the worksheet using a TwoCellAnchor object.
                    drawingsPart.WorksheetDrawing = new WorksheetDrawing();
                    TwoCellAnchor twoCellAnchor = drawingsPart.WorksheetDrawing.AppendChild(new TwoCellAnchor());
                    twoCellAnchor.Append(new DocumentFormat.OpenXml.Drawing.Spreadsheet.FromMarker(new ColumnId("0"),
                                                                                                   new ColumnOffset("0"),
                                                                                                   new RowId("0"),
                                                                                                   new RowOffset("0")));
                    twoCellAnchor.Append(new DocumentFormat.OpenXml.Drawing.Spreadsheet.ToMarker(new ColumnId("8"),
                                                                                                 new ColumnOffset("0"),
                                                                                                 new RowId("15"),
                                                                                                 new RowOffset("0")));

                    // Append a GraphicFrame to the TwoCellAnchor object.
                    var graphicFrame = twoCellAnchor.AppendChild(new DocumentFormat.OpenXml.Drawing.Spreadsheet.GraphicFrame());
                    graphicFrame.Macro = "";

                    graphicFrame.Append(new DocumentFormat.OpenXml.Drawing.Spreadsheet.NonVisualGraphicFrameProperties(
                                            new DocumentFormat.OpenXml.Drawing.Spreadsheet.NonVisualDrawingProperties()
                    {
                        Id   = new UInt32Value(2u),
                        Name = "Chart 1"
                    }, new DocumentFormat.OpenXml.Drawing.Spreadsheet.NonVisualGraphicFrameDrawingProperties()));

                    graphicFrame.Append(new Transform(new Offset()
                    {
                        X = 0L, Y = 0L
                    },
                                                      new Extents()
                    {
                        Cx = 0L, Cy = 0L
                    }));

                    graphicFrame.Append(new Graphic(new GraphicData(new ChartReference()
                    {
                        Id = drawingsPart.GetIdOfPart(chartPart)
                    })
                    {
                        Uri = "http://schemas.openxmlformats.org/drawingml/2006/chart"
                    }));

                    twoCellAnchor.Append(new ClientData());
                    #endregion

                    // Save the WorksheetDrawing object.
                    drawingsPart.WorksheetDrawing.Save();
                }
            }

            var validator = new OpenXmlValidator();
            var errors    = validator.Validate(spreadsheetDocument);
            if (errors.Any())
            {
                var sbError = new StringBuilder();
                sbError.Append("ERROR: ");
                foreach (var e in errors)
                {
                    sbError.Append($"***{e.Node.ToString()}:{e.Description}***");
                }
                throw new Exception(sbError.ToString());
            }

            workbook.Save();

            // Close the document.
            spreadsheetDocument.Close();
        }
Esempio n. 43
0
        public void MainTemplete()
        {
            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();
            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);
            //设置图表类型
            mychart.Type = ChartChartTypeEnum.chChartTypeLineStackedMarkers;

            //旋转
            //mychart.Rotation = 360;
            //mychart.Inclination = 10;
            //背景颜色
            //mychart.PlotArea.Interior.Color = "red";
            //底色
            //mychart.PlotArea.Floor.Interior.Color = "green";
            //mychart.Overlap = 50;

            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = "test";
            //设置图例位置
            mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;
            //添加图表块
            //分类属性
            const ChartDimensionsEnum category = ChartDimensionsEnum.chDimValues;
            const int dataSources = (int)ChartSpecialDataSourcesEnum.chDataLiteral;

            var chart1 = mychart.SeriesCollection.Add(0);
            //X柱
            chart1.SetData(ChartDimensionsEnum.chDimCategories, dataSources, "T1\tT2\tT3\tT4\tT5\tT6\tT7\tT8\t本次考试");
            //分类名字
            chart1.SetData(ChartDimensionsEnum.chDimSeriesNames, dataSources, "总分");
            //赋值
            chart1.SetData(category, dataSources, "-0.1\t-0.8\t-0.1\t0.3\t0.3\t1\t1.5\t1.1\t-0.6");
            //chart1.Ungroup(true);
            //chart1.Interior.Color = "red";

            //ChSeries chSeries = mychart.SeriesCollection.Add(0);
            //chSeries.Type = ChartChartTypeEnum.chChartTypeSmoothLine;
            //ChAxis chAxis = mychart.Axes.Add(chSeries.Scalings[ChartDimensionsEnum.chDimValues]);
            //chAxis.Position = ChartAxisPositionEnum.chAxisPositionRight;

            var chart2 = mychart.SeriesCollection.Add(0);
            chart2.SetData(category, dataSources, "-0.2\t-0.7\t-0.1\t0.3\t0.4\t1\t1.1\t1.1\t-0.6");
            chart2.Ungroup(true);
            chart2.Caption = "平均分";
            // chart2.Line.Color = ChartColorIndexEnum.chColorNone;//不要线

            var chart3 = mychart.SeriesCollection.Add(0);
            chart3.SetData(ChartDimensionsEnum.chDimSeriesNames, dataSources, "二次平均");
            chart3.SetData(category, dataSources, "-0.3\t-0.6\t-1.3\t0.3\t0.5\t1\t1.1\t1.1\t-0.6");
            chart3.Ungroup(true);

            var chart4 = mychart.SeriesCollection.Add(0);
            chart4.SetData(ChartDimensionsEnum.chDimSeriesNames, dataSources, "三次平均");
            chart4.SetData(category, dataSources, "-0.4\t-0.5\t-1.0\t0.3\t0.6\t1\t-1.1\t1.1\t-0.6");
            chart4.Ungroup(true);

            //mychart.Axes[0].HasMajorGridlines = true;//竖着的线
            //mychart.Axes[0].HasMinorGridlines = false;//竖着的线
            //mychart.Axes[0].HasTickLabels = false;//X坐标的值

            //mychart.Axes[1]X坐标

            //给定标题
            //objChart.HasTitle = true;
            //objChart.Title.Caption = topTitle;
            //objChart.Title.Font.Size = 18;
            //objChart.Title.Font.Bold = true;
            //objChart.Title.Font.Color = "#ff3300";//标题颜色

            //objChart.Interior.Color = "#003399";
            //objChart.PlotArea.BackWall.Interior.Color = "black";
            //objChart.PlotArea.Interior.Color = "green";
            ////objChart.PlotArea.Interior.Color = "black";//图表区域背景颜色

            //objChart.PlotArea.Floor.Interior.Color = "black";
            ////给定x,y轴的图示说明
            //objChart.Axes[0].HasTitle = true;

            //objChart.Axes[0].Title.Caption = xTitle;
            //objChart.Axes[0].Title.Font.Size = 15;
            //objChart.Axes[0].Title.Font.Bold = true;
            //objChart.Axes[0].Title.Font.Color = "#ff3300";

            //objChart.Axes[0].MajorGridlines.Line.Color = "white";
            //objChart.Axes[0].Font.Size = 14;
            //objChart.Axes[0].Font.Color = "#ff3300";//X轴刻度颜色
            //objChart.Axes[0].Font.Bold = true;
            //objChart.Axes[0].MajorTickMarks = OWC11.ChartTickMarkEnum.chTickMarkAutomatic;

            //趋势图
            //var trend = chart2.Trendlines.Add();
            //trend.Type = ChartTrendlineTypeEnum.chTrendlineTypeLinear;
            //trend.Caption = "ds";
            //trend.IsDisplayingEquation = false;
            //trend.IsDisplayingRSquared = false;

            //Explosion:返回或设置指定饼图或圆环图扇面的分离程度值。有效范围为 0 到 1000。分离程度值等于图表半径的百分比
            //objChart.SeriesCollection[0].Points[2].Explosion = 45;

            //将柱状图的第一条柱设置为红色
            //Point:代表图中的一部分,比如柱图的一条柱,饼图的一个扇区
            //Interior:表示指定对象的内部
            //mychart.SeriesCollection[0].Points[0].Interior.Color = "Red";

            //给第一个扇区设置自定义背景图片
            //objChart.SeriesCollection[0].Points[0].Interior.SetTextured("E:\\Projects\\DotNetNuke\\images\\add.gif", ChartTextureFormatEnum.chTile,1,ChartTexturePlacementEnum.chFrontSides);
            //给第二个扇区设置从中心向四周辐射的单色渐变
            //objChart.SeriesCollection[0].Points[1].Interior.SetOneColorGradient(ChartGradientStyleEnum.chGradientFromCenter,ChartGradientVariantEnum.chGradientVariantStart,0.3,"Blue");
            //给第三个扇区设置倾斜双色渐变
            //objChart.SeriesCollection[0].Points[2].Interior.SetTwoColorGradient(ChartGradientStyleEnum.chGradientDiagonalDown,ChartGradientVariantEnum.chGradientVariantCenter,"Green","Red");
            //给第四个扇区设置OWC预设的纹理,并设置纹理的背景色为淡绿色,前景色为红色
            //OWC提供了很多纹理,这是其中一种
            //具体的纹理样式可以参看帮助中的ChartPatternTypeEnum枚举
            // objChart.SeriesCollection[0].Points[3].Interior.SetPatterned(ChartPatternTypeEnum.chPatternDiagonalBrick,"Red","LightGreen");
            //给第五个扇区设置OWC预设的倾斜,
            //OWC提供了许多种的倾斜,这是其中一种
            //具体的倾斜可以参看帮助中的ChartPresetGradientTypeEnum枚举
            // objChart.SeriesCollection[0].Points[4].Interior.SetPresetGradient(ChartGradientStyleEnum.chGradientDiagonalUp,ChartGradientVariantEnum.chGradientVariantEdges,ChartPresetGradientTypeEnum.chGradientGoldII);

            //  objChart.SeriesCollection[0].Trendlines.Add();
            //   是否显示函数
            // objChart.SeriesCollection[0].Trendlines[0].IsDisplayingEquation = true;
            //   是否显示平方
            // objChart.SeriesCollection[0].Trendlines[0].IsDisplayingRSquared = true;
            //   设置趋势线标题
            // objChart.SeriesCollection[0].Trendlines[0].Caption = "TrendLine";
            //   设置趋势线类型,
            //   OWC提供了4种趋势线类型,具体可参看帮助的ChartTrendlineTypeEnum枚举
            // objChart.SeriesCollection[0].Trendlines[0].Type = OWC11.ChartTrendlineTypeEnum.chTrendlineTypePolynomial;

            //var trend = chart2.Trendlines.Add();
            //trend.Type = ChartTrendlineTypeEnum.chTrendlineTypeLinear;
            //trend.Caption = "ds";
            //trend.IsDisplayingEquation = false;
            //trend.IsDisplayingRSquared = false;
            ////主次网格线不显示
            //chChart.Axes[1].HasMinorGridlines = false;
            //chChart.Axes[1].HasMajorGridlines = false;
            ////设定Y轴格式
            //chChart.Axes[1].NumberFormat = "0%";
            ////去掉线
            //chChart.SeriesCollection[3].Line.Color = ChartColorIndexEnum.chColorNone;
            ////标记形状
            //chChart.SeriesCollection[3].Marker.Style = ChartMarkerStyleEnum.chMarkerStyleDiamond;
            //显示百分比
            //ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            //mytb.HasPercentage = true;

            //ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            //mytb.HasBubbleSize = false;
            //显示百分比
            //mytb.HasPercentage = true;
            //显示值
            //mytb.HasValue = true;

            var image = UrlPath("折线图");
            //生成图片
            mychartSpace.ExportPicture(image, "GIF", 800, 200);
        }
Esempio n. 44
0
        //竖状柱状图--上线率分析
        public string ChartTypeColumnClustered5()
        {
            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();
            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);

            //设置图表类型,本例使用柱状图
            mychart.Type = ChartChartTypeEnum.chChartTypeColumnStacked;
            //设置图表的一些属性
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = "test";
            //添加图表块
            mychart.SeriesCollection.Add(0);
            //设置图表块的属性
            const ChartDimensionsEnum category = ChartDimensionsEnum.chDimValues;
            const int dataSources = (int)ChartSpecialDataSourcesEnum.chDataLiteral;

            //分类属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, dataSources, "本科线");
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, dataSources,
                                                "总分\t语文\t数学\t英语\t物理\t化学\t生物");
            //值属性
            mychart.SeriesCollection[0].SetData(category, dataSources, "6%\t6%\t4%\t4%\t0%\t8%\t2%");
            mychart.SeriesCollection[0].Ungroup(true);

            var chart2 = mychart.SeriesCollection.Add(0);
            chart2.SetData(ChartDimensionsEnum.chDimSeriesNames, dataSources, "一本线");
            chart2.SetData(category, dataSources, "16%\t66%\t45%\t4%\t3%\t8%\t2%");
            //chart2.Ungroup(true);

            //显示值
            ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            mytb.HasValue = true;
            mytb = mychart.SeriesCollection[1].DataLabelsCollection.Add();
            mytb.HasValue = true;

            var image = UrlPath("柱状图");
            //生成图片
            mychartSpace.ExportPicture(image, "GIF", 400, 300);

            return image;
        }
Esempio n. 45
0
        /// <summary>
        /// 雷达图--学科均衡性分析
        /// </summary>
        /// <param name="strDataName">分类管理名字</param>
        /// <param name="data1">元数据</param>
        /// <param name="data2">比较数据</param>
        /// <returns></returns>
        public string ChartTypeRadarLine(string strDataName, string data1,string data2)
        {
            var mychartSpace = new ChartSpace();
            var mychart = mychartSpace.Charts.Add(0);
            mychart.Type = ChartChartTypeEnum.chChartTypeRadarLineFilled;
            mychart.HasTitle = false;

            var chart1 = mychart.SeriesCollection.Add(0);
            chart1.SetData(DimCategories, DataLiteral, strDataName);
            chart1.SetData(DimValues, DataLiteral, data2);
            chart1.Interior.Color = Color.Red;

            var chart2 =  mychart.SeriesCollection.Add(0);
            chart2.SetData(DimValues, DataLiteral, data1);
            chart2.Interior.Color = Color.Blue;

            var image = UrlPath("雷达");
            mychartSpace.ExportPicture(image, "GIF", 400, 300);
            return image;
        }
    /*Draw HistoGram */
    protected void DrawHistoGram()
    {
        ChartSpace objSpace = new ChartSpace();
        ChChart objChart = objSpace.Charts.Add(0);
        objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;

        objChart.HasTitle = true;
        objChart.Title.Font.Size = 12;
        objChart.Title.Caption = GetTitle(5);
        objChart.Title.Font.Bold = true;
        objChart.SeriesCollection.Add(0);
        objChart.SeriesCollection.Add(1);
        objChart.HasLegend = true;

        objChart.SeriesCollection[0].Caption = year.Substring(2, 2) + " A";

        objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames,
                +Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), year.Substring(2, 2) + " A");
        objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
               +(int)ChartSpecialDataSourcesEnum.chDataLiteral, GetDimCategories(3));
        objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                +(int)ChartSpecialDataSourcesEnum.chDataLiteral, GetDimValues(5));

        objChart.SeriesCollection[1].Caption = nextyear.Substring(2, 2) + " F";

        objChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimSeriesNames,
                +Convert.ToInt32(ChartSpecialDataSourcesEnum.chDataLiteral), nextyear.Substring(2, 2) + " F");
        objChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimCategories,
               +(int)ChartSpecialDataSourcesEnum.chDataLiteral, GetDimCategories(3));
        objChart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues,
                +(int)ChartSpecialDataSourcesEnum.chDataLiteral, GetDimValues(6));

        Random ro = new Random();
        int a = ro.Next();
        dateI = a.ToString();

        string fileName = "pchart8" + dateI + ".gif";
        string filePath = Server.MapPath("~");
        filePath += "\\ChartImages\\" + fileName;
        objSpace.ExportPicture(filePath, "GIF", 250, 200);
        Image8.ImageUrl = filePath.ToString();
        Image8.ImageUrl = "~/ChartImages/" + fileName;
        Image8.Visible = true;
    }
Esempio n. 47
0
        //折线图--成绩波动分析
        public string ChartTypeLineStackedMarkers(string name)
        {
            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();
            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);
            //设置图表类型
            mychart.Type = ChartChartTypeEnum.chChartTypeLineStackedMarkers;

            mychart.Axes[1].Line.Color = ChartColorIndexEnum.chColorNone;

            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = name;
            //设置图例位置
            mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionLeft;
            //添加图表块
            //分类属性
            const ChartDimensionsEnum category = ChartDimensionsEnum.chDimValues;
            const int dataSources = (int)ChartSpecialDataSourcesEnum.chDataLiteral;

            var chart1 = mychart.SeriesCollection.Add(0);
            //X柱
            chart1.SetData(ChartDimensionsEnum.chDimCategories, dataSources, "T1\tT2\tT3\tT4\tT5\tT6\tT7\tT8\t本次考试");
            //分类名字
            //chart1.SetData(ChartDimensionsEnum.chDimSeriesNames, dataSources, "总分");
            //赋值
            chart1.SetData(category, dataSources, "-0.1\t-0.8\t-0.1\t0.3\t0.3\t1\t1.5\t1.1\t-0.6");
            chart1.Ungroup(true);
            chart1.Caption = name;

            var chart2 = mychart.SeriesCollection.Add(0);
            chart2.Caption = "平均分";
            chart2.SetData(category, dataSources, "-0.2\t-0.7\t-0.1\t0.3\t0.4\t1\t1.1\t1.1\t-0.6");
            chart2.Ungroup(true);

            var chart4 = mychart.SeriesCollection.Add(0);
            chart4.SetData(category, dataSources, "-0.4\t-0.5\t-1.0\t0.3\t0.6\t1\t-1.1\t1.1\t-0.6");
            chart4.Ungroup(true);
            chart4.Caption = "三次平均";

            //ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            //mytb.HasBubbleSize = false;
            //显示百分比
            //mytb.HasPercentage = true;

            var path = "折线图" + DateTime.Now.Ticks;
            var image = UrlPath(path);
            //生成图片
            mychartSpace.ExportPicture(image, "GIF", 800, 200);

            return image;
        }
Esempio n. 48
0
        public static Image Generador_Grafico(System.Web.UI.WebControls.Image imagen, string nombreGrafico, TipoGraficos isEnum, string lgEjeX, string lgEjeY, params string[] strEntrada)
        {
            bool errorConfiguracion = false;
            bool ejes           = false;
            int  cantidadSeries = 0;

            //ChartSpaceClass objetoGraficoOffice = new ChartSpaceClass();
            ChartSpace objetoGraficoOffice = new ChartSpace();

            objetoGraficoOffice.DataSourceType          = ChartDataSourceTypeEnum.chDataSourceTypeSpreadsheet;
            objetoGraficoOffice.HasChartSpaceTitle      = true;
            objetoGraficoOffice.ChartSpaceTitle.Caption = nombreGrafico.ToUpper();
            objetoGraficoOffice.ChartSpaceTitle.Font.set_Name("Tahoma");
            objetoGraficoOffice.ChartSpaceTitle.Font.set_Size(12);
            objetoGraficoOffice.ChartSpaceTitle.Font.set_Bold(true);
            WCChart mapa = objetoGraficoOffice.Charts.Add(0);
            WCAxis  Ejes;

            mapa.HasLegend = true;
            mapa.HasTitle  = false;
            if (isEnum == TipoGraficos.PIE)
            {
                mapa.Type = ChartChartTypeEnum.chChartTypePie;
                mapa.SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, "Elementos");
                //revisamos cual es la serie y cuales son los datos
                //serie , A\tB\tC
                //datos , 1\t2\t3
                for (int i = 0; i < strEntrada.Length; i++)
                {
                    string[] separador = strEntrada[i].Split(',');
                    if (separador[0].ToLower().Trim() == "serie")
                    {
                        mapa.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, separador[1]);
                    }
                    if (separador[0].ToLower().Trim() == "datos")
                    {
                        mapa.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, separador[1]);
                        WCDataLabels dlValues = mapa.SeriesCollection[0].DataLabelsCollection.Add();
                        dlValues.HasPercentage = true;
                        dlValues.HasValue      = false;
                    }
                }
            }
            if (isEnum == TipoGraficos.COLUMNAS || isEnum == TipoGraficos.LINEAS || isEnum == TipoGraficos.BARRAS || isEnum == TipoGraficos.AREA)
            {
                if (isEnum == TipoGraficos.COLUMNAS)
                {
                    mapa.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
                }
                if (isEnum == TipoGraficos.LINEAS)
                {
                    mapa.Type = ChartChartTypeEnum.chChartTypeLineStacked;
                }
                if (isEnum == TipoGraficos.BARRAS)
                {
                    mapa.Type = ChartChartTypeEnum.chChartTypeBarClustered;
                }
                if (isEnum == TipoGraficos.AREA)
                {
                    mapa.Type = ChartChartTypeEnum.chChartTypeAreaStacked;
                }
                //serie,n,nombre serie
                //categoria,n,A\tB\tC
                //valores,n,1\t2\t3
                ejes = true;
                for (int i = 0; i < strEntrada.Length; i++)
                {
                    string[] separador = strEntrada[i].Split(',');
                    if ((separador[0].ToLower().Trim() == "serie") && !errorConfiguracion)
                    {
                        //Buscamos las categorias y valores asociados a esta serie
                        int indiceCategoria = BuscarIndice("categoria", separador[1].Trim(), strEntrada);
                        int indiceValor     = BuscarIndice("valores", separador[1].Trim(), strEntrada);
                        if (indiceCategoria == -1 || indiceValor == -1)
                        {
                            errorConfiguracion = true;
                        }
                        else
                        {
                            string[] sepCategoria = strEntrada[indiceCategoria].Split(',');
                            string[] sepValor     = strEntrada[indiceValor].Split(',');
                            mapa.SeriesCollection.Add(cantidadSeries);
                            mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, separador[2].Trim());
                            mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, sepCategoria[2].Trim());
                            mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, sepValor[2].Trim());
                            cantidadSeries += 1;
                        }
                    }
                }
            }
            if (isEnum == TipoGraficos.XY)
            {
                mapa.Type = ChartChartTypeEnum.chChartTypeScatterLine;
                //serie,n,nombreSerie
                //valores,n,X,1\t2\t3
                //valores,n,Y,2\t4\t7
                ejes = true;
                for (int i = 0; i < strEntrada.Length; i++)
                {
                    string[] separador = strEntrada[i].Split(',');
                    if ((separador[0].ToLower().Trim() == "serie") && !errorConfiguracion)
                    {
                        int indiceEjeX = BuscarIndice("valores", separador[1].Trim(), "X", strEntrada);
                        int indiceEjeY = BuscarIndice("valores", separador[1].Trim(), "Y", strEntrada);
                        if (indiceEjeY == -1 || indiceEjeX == -1)
                        {
                            errorConfiguracion = true;
                        }
                        else
                        {
                            string[] sepEjeX = strEntrada[indiceEjeX].Split(',');
                            string[] sepEjeY = strEntrada[indiceEjeY].Split(',');
                            mapa.SeriesCollection.Add(cantidadSeries);
                            mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, separador[2].Trim());
                            mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimXValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, sepEjeX[3].Trim());
                            mapa.SeriesCollection[cantidadSeries].SetData(ChartDimensionsEnum.chDimYValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, sepEjeY[3].Trim());
                            cantidadSeries += 1;
                        }
                    }
                }
            }
            if (ejes)
            {
                //Eje x
                Ejes               = mapa.Axes[(int)ChartAxisPositionEnum.chAxisPositionBottom];
                Ejes.HasTitle      = true;
                Ejes.Title.Caption = lgEjeX;
                Ejes.Title.Font.set_Name("Tahoma");
                Ejes.Title.Font.set_Size(8);
                Ejes.Title.Font.set_Bold(true);
                //Eje Y
                Ejes               = mapa.Axes[(int)ChartAxisPositionEnum.chAxisPositionLeft];
                Ejes.HasTitle      = true;
                Ejes.Title.Caption = lgEjeY;
                Ejes.Title.Font.set_Name("Tahoma");
                Ejes.Title.Font.set_Size(8);
                Ejes.Title.Font.set_Bold(true);
            }
            if (!errorConfiguracion)
            {
                try
                {
                    objetoGraficoOffice.ExportPicture(strAbsolutePath, "gif", 500, 400);
                }
                catch (Exception e) { exceptions += "<br>error:" + e.ToString(); }
                imagen.ImageUrl = ConfigurationManager.AppSettings["PathToGraphics"] + "esttemp.gif";
            }
            else
            {
                exceptions += "<br>error: Error de configuracion de series, categorias y valores";
            }
            return(imagen);
        }
Esempio n. 49
0
        //折线图2--成绩变化趋势分析
        public string ChartTypeLineStackedMarkers2()
        {
            //创建X坐标的值,表示月份
            int[] Month = { 1, 2, 3 };
            //创建Y坐标的值,表示销售额
            double[] Count = { 120, 240, 220 };
            string strDataName = "";
            string strData = "";

            //创建图表空间
            ChartSpace mychartSpace = new ChartSpace();
            //在图表空间内添加一个图表对象
            ChChart mychart = mychartSpace.Charts.Add(0);

            //设置每块饼的数据
            for (int i = 0; i < Count.Length - 1; i++)
            {
                strDataName += Month[i] + "\t";
                strData += Count[i].ToString() + "\t";
            }
            strDataName += Month[Count.Length - 1];
            strData += Count[Count.Length - 1].ToString();

            //设置图表类型,本例使用柱状图
            mychart.Type = ChartChartTypeEnum.chChartTypeLineStackedMarkers;
            //设置图表的一些属性
            //是否需要图例
            mychart.HasLegend = true;
            //是否需要主题
            mychart.HasTitle = true;
            //主题内容
            mychart.Title.Caption = "test";

            //设置图例位置为底端
            mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
            //添加图表块
            mychart.SeriesCollection.Add(0);

            //设置图表块的属性
            //分类属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName);
            //值属性
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral, strData);

            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "200\t120\t343");
            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "100\t200\t143");
            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "300\t300\t243");
            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "400\t180\t303");
            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "230\t230\t313");
            mychart.SeriesCollection.Add(0);
            mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
                                                (int)ChartSpecialDataSourcesEnum.chDataLiteral,
                                                "290\t200\t349");

            //显示百分比
            //ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
            //mytb.HasPercentage = true;

            var image = UrlPath("折线图");
            //生成图片
            mychartSpace.ExportPicture(image, "GIF", 400, 300);

            return image;
        }