using Spire.Xls;
using System.Drawing;
Workbook workbook =
new Workbook();
workbook.CreateEmptySheets(
1);
Worksheet sheet = workbook.Worksheets[
0];
sheet.Name =
"
偏差線和趨勢線演示
";
sheet.Range[
"
A1
"].Value =
"
月份
";
sheet.Range[
"
A2
"].Value =
"
一月
";
sheet.Range[
"
A3
"].Value =
"
二月
";
sheet.Range[
"
A4
"].Value =
"
三月
";
sheet.Range[
"
A5
"].Value =
"
四月
";
sheet.Range[
"
A6
"].Value =
"
五月
";
sheet.Range[
"
A7
"].Value =
"
六月
";
sheet.Range[
"
B1
"].Value =
"
計劃量
";
sheet.Range[
"
B2
"].NumberValue =
3.3;
sheet.Range[
"
B3
"].NumberValue =
2.5;
sheet.Range[
"
B4
"].NumberValue =
2.0;
sheet.Range[
"
B5
"].NumberValue =
3.7;
sheet.Range[
"
B6
"].NumberValue =
4.5;
sheet.Range[
"
B7
"].NumberValue =
4.0;
sheet.Range[
"
C1
"].Value =
"
實際量
";
sheet.Range[
"
C2
"].NumberValue =
3.8;
sheet.Range[
"
C3
"].NumberValue =
3.2;
sheet.Range[
"
C4
"].NumberValue =
1.7;
sheet.Range[
"
C5
"].NumberValue =
3.5;
sheet.Range[
"
C6
"].NumberValue =
4.5;
sheet.Range[
"
C7
"].NumberValue =
4.3;
//
生成折線圖,設置位置
Chart chart = sheet.Charts.Add(ExcelChartType.Line);
chart.DataRange = sheet.Range[
"
B1:B7
"];
chart.SeriesDataFromRange =
false;
chart.TopRow =
6;
chart.BottomRow =
25;
chart.LeftColumn =
2;
chart.RightColumn =
9;
chart.ChartTitle =
"
百分比正誤差偏差線和對數趨勢線示例
";
chart.ChartTitleArea.IsBold =
true;
chart.ChartTitleArea.Size =
12;
Spire.Xls.Charts.ChartSerie cs1 = chart.Series[
0];
cs1.CategoryLabels = sheet.Range[
"
A2:A7
"];
//
添加對數趨勢線
cs1.TrendLines.Add(TrendLineType.Logarithmic);
//
添加10%正誤差偏差線
cs1.ErrorBar(
true, ErrorBarIncludeType.Plus, ErrorBarType.Percentage,
10);
//
生成柱狀圖做爲對照組
Chart chart2 = sheet.Charts.Add(ExcelChartType.ColumnClustered);
chart2.DataRange = sheet.Range[
"
B1:C7
"];
chart2.SeriesDataFromRange =
false;
chart2.TopRow =
6;
chart2.BottomRow =
25;
chart2.LeftColumn =
10;
chart2.RightColumn =
17;
chart2.ChartTitle =
"
正負標準偏差偏差線和指數趨勢線示例
";
chart2.ChartTitleArea.IsBold =
true;
chart2.ChartTitleArea.Size =
12;
Spire.Xls.Charts.ChartSerie cs2 = chart2.Series[
0];
cs2.CategoryLabels = sheet.Range[
"
A2:A7
"];
//
添加標準偏差負偏差0.3的偏差線
cs2.ErrorBar(
true, ErrorBarIncludeType.Minus, ErrorBarType.StandardError,
0.3);
//
添加指數趨勢線
cs2.TrendLines.Add(TrendLineType.Exponential);
Spire.Xls.Charts.ChartSerie cs3 = chart2.Series[
1];
//
添加標準偏差正負偏差0.5的偏差線
cs3.ErrorBar(
true, ErrorBarIncludeType.Both, ErrorBarType.StandardError,
0.5);
workbook.SaveToFile(
"
S3.xlsx
", ExcelVersion.Version2010);
System.Diagnostics.Process.Start(
"
S3.xlsx
");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;
using System.Drawing;
namespace ConsoleApplication2
{
class Program
{
static
void Main(
string[] args)
{
Workbook workbook =
new Workbook();
workbook.CreateEmptySheets(
1);
Worksheet sheet = workbook.Worksheets[
0];
sheet.Name =
"
偏差線和趨勢線演示
";
sheet.Range[
"
A1
"].Value =
"
月份
";
sheet.Range[
"
A2
"].Value =
"
一月
";
sheet.Range[
"
A3
"].Value =
"
二月
";
sheet.Range[
"
A4
"].Value =
"
三月
";
sheet.Range[
"
A5
"].Value =
"
四月
";
sheet.Range[
"
A6
"].Value =
"
五月
";
sheet.Range[
"
A7
"].Value =
"
六月
";
sheet.Range[
"
B1
"].Value =
"
計劃量
";
sheet.Range[
"
B2
"].NumberValue =
3.3;
sheet.Range[
"
B3
"].NumberValue =
2.5;
sheet.Range[
"
B4
"].NumberValue =
2.0;
sheet.Range[
"
B5
"].NumberValue =
3.7;
sheet.Range[
"
B6
"].NumberValue =
4.5;
sheet.Range[
"
B7
"].NumberValue =
4.0;
sheet.Range[
"
C1
"].Value =
"
實際量
";
sheet.Range[
"
C2
"].NumberValue =
3.8;
sheet.Range[
"
C3
"].NumberValue =
3.2;
sheet.Range[
"
C4
"].NumberValue =
1.7;
sheet.Range[
"
C5
"].NumberValue =
3.5;
sheet.Range[
"
C6
"].NumberValue =
4.5;
sheet.Range[
"
C7
"].NumberValue =
4.3;
Chart chart = sheet.Charts.Add(ExcelChartType.Line);
chart.DataRange = sheet.Range[
"
B1:B7
"];
chart.SeriesDataFromRange =
false;
chart.TopRow =
6;
chart.BottomRow =
25;
chart.LeftColumn =
2;
chart.RightColumn =
9;
chart.ChartTitle =
"
百分比正誤差偏差線和對數趨勢線示例
";
chart.ChartTitleArea.IsBold =
true;
chart.ChartTitleArea.Size =
12;
Spire.Xls.Charts.ChartSerie cs1 = chart.Series[
0];
cs1.CategoryLabels = sheet.Range[
"
A2:A7
"];
cs1.TrendLines.Add(TrendLineType.Logarithmic);
cs1.ErrorBar(
true, ErrorBarIncludeType.Plus, ErrorBarType.Percentage,
10);
Chart chart2 = sheet.Charts.Add(ExcelChartType.ColumnClustered);
chart2.DataRange = sheet.Range[
"
B1:C7
"];
chart2.SeriesDataFromRange =
false;
chart2.TopRow =
6;
chart2.BottomRow =
25;
chart2.LeftColumn =
10;
chart2.RightColumn =
17;
chart2.ChartTitle =
"
正負標準偏差偏差線和指數趨勢線示例
";
chart2.ChartTitleArea.IsBold =
true;
chart2.ChartTitleArea.Size =
12;
Spire.Xls.Charts.ChartSerie cs2 = chart2.Series[
0];
cs2.CategoryLabels = sheet.Range[
"
A2:A7
"];
cs2.ErrorBar(
true, ErrorBarIncludeType.Minus, ErrorBarType.StandardError,
0.3);
cs2.TrendLines.Add(TrendLineType.Exponential);
Spire.Xls.Charts.ChartSerie cs3 = chart2.Series[
1];
cs3.ErrorBar(
true, ErrorBarIncludeType.Both, ErrorBarType.StandardError,
0.5);
workbook.SaveToFile(
"
S3.xlsx
", ExcelVersion.Version2010);
System.Diagnostics.Process.Start(
"
S3.xlsx
"); } } }