C# OWC11

public void OcwChart(int[] Data,string[] DataName,string Yname,string Xname,string ChartName,string Dname)
{
try
{
//创建ChartSpace对象
ChartSpaceClass mySpace = new ChartSpaceClass();
//添加图表
ChChart ChartMonth = mySpace.Charts.Add(0);
//指定图表类型
ChartMonth.Type = ChartChartTypeEnum.chChartTypeColumnClustered;
// ChartMonth.Type = ChartChartTypeEnum.chChartTypeLineMarkers;
ChartMonth.HasTitle = true;
ChartMonth.HasLegend = true;
ChartMonth.Title.Font.Bold = true;
ChartMonth.Title.Font.Size = 12;
ChartMonth.Title.Font.Color = "#ff3300";

ChartMonth.Axes[0].HasTitle = true;
//横轴名称
ChartMonth.Axes[0].Title.Caption = Xname;

ChartMonth.Axes[1].HasTitle = true;
//纵轴名称
ChartMonth.Axes[1].Title.Caption = Yname;

ChartMonth.Axes[0].Title.Font.Bold = true;
ChartMonth.Axes[0].Title.Font.Color = "#995540";
ChartMonth.Axes[1].Title.Font.Bold = true;
ChartMonth.Axes[1].Title.Font.Color = "#994400";




//图表名称
ChartMonth.Title.Caption = ChartName;

////生成横轴的名称
//int data_i = 0;
//for (int i = 0; i < 6; i++)
//{
// DataName[data_i] = string.Format("{0:" + string.Format("{0:D2}", i) + "\r\n月\r\n" + "}", (i + 1).ToString());
// data_i++;
//}
string strValue = "";
string strCateory = "";

//将数据格式化
for (int i = 0; i < DataName.Length; i++)
{
strCateory += DataName[i] + '\t';
}

for (int i = 0; i < Data.Length; i++)
{
strValue += Data[i].ToString() + '\t';
}

//添加序列
ChartMonth.SeriesCollection.Add(0);
ChartMonth.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Dname);
ChartMonth.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strCateory);
ChartMonth.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue);

//输出图表
string strAbsolutePath = Application.StartupPath + @"\rate.gif";
// mySpace.ExportPicture(strAbsolutePath, "GIF", pictureBox1.Width, pictureBox1.Height);
// pictureBox1.ImageLocation = strAbsolutePath;
}
catch (Exception ex)
{
MessageBox.Show("流量图显示错误:" + ex.Message);
}

}

posted @ 2017-09-03 20:31  赵老  阅读(553)  评论(0编辑  收藏  举报