Exemplo n.º 1
0
        private void ChartDraw2(string title_name)
        {
            chart             = ws2.Charts.Add();
            chart.ChartType   = ExcelChartType.Line;
            chart.DataRange   = ws2.Range["A1:I7"];
            chart.LeftColumn  = 12;
            chart.TopRow      = 7;
            chart.RightColumn = 20;
            chart.BottomRow   = 22;
            //标题名称
            chart.ChartTitle            = title_name;
            chart.ChartTitleArea.IsBold = true;
            chart.ChartTitleArea.Size   = 12;
            //设置横坐标的标题
            chart.PrimaryCategoryAxis.Title            = "时间";
            chart.PrimaryCategoryAxis.Font.IsBold      = true;
            chart.PrimaryCategoryAxis.TitleArea.IsBold = true;


            //y
            chart.PrimaryValueAxis.Title                       = "数值";
            chart.PrimaryValueAxis.HasMajorGridLines           = false;
            chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90;
            chart.PrimaryValueAxis.MinValue                    = 0;
            chart.PrimaryValueAxis.TitleArea.IsBold            = true;
            //循环绘制
            foreach (Spire.Xls.Charts.ChartSerie cs in chart.Series)
            {
                cs.Format.Options.IsVaryColor = true;
                cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
            }
            Image[] image = wb2.SaveChartAsImage(ws2);
            image[0].Save(pic_fuyun_path, ImageFormat.Png);
        }