owc charting class
随便写了一个charting的class ,用owc画的,总觉得owc画图不是很漂亮,不过还能对付看吧!现在画图的控件也很多,免费的不多,想自己开发一个吧,能力有限,也没那个时间,觉得owc还可以满足对质量不是要求很高的图的要求,主要是免费的,装了office就ok了。
下面还是给出代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OWC = Microsoft.Office.Interop.Owc11;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
/// <summary>
/// DrawChar 的摘要说明
/// </summary>
public class DrawChart
{
private string[] m_strSeries = null;
private string m_strCategory = string.Empty;
private string[] m_strValues = null;
private string m_strFileName = string.Empty;
private int m_nCount = 0;
private string m_strChartTitle = string.Empty;
string m_strAbsolutePath = string.Empty;
string m_strPhysicalPath = string.Empty;
OWC.ChartChartTypeEnum m_chartType;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
/// <summary>
///
/// </summary>
/// <param name="strSeries">做标注的时候用的名字</param>
/// <param name="strCategory">横坐标上的值</param>
/// <param name="strValues">纵坐标上的值(可以是数组表示的,有多个曲线)</param>
/// <param name="charTitle">图的名</param>
/// <param name="AbsolutePath">Server.MapPath = D:\My Study\c#\web\DssWeb\Report\</param>
/// <param name="PhysicalPath">Request.PhysicalApplicationPath = http://10.12.1.55/dssweb/Report/</param>
/// <param name="fileName">图片名</param>
/// <param name="Count">所画线的个数</param>
/// <param name="chartType">图类型</param>
public DrawChart(string[] strSeries, string strCategory, string[] strValues, string charTitle,
string AbsolutePath,string PhysicalPath, string fileName, int Count, OWC.ChartChartTypeEnum chartType)
{
m_strSeries = strSeries;
m_strCategory = strCategory;
m_strValues = strValues;
m_strFileName = fileName;
m_strChartTitle = charTitle;
m_nCount = Count;
m_chartType = chartType;
m_strAbsolutePath = AbsolutePath;
m_strPhysicalPath = PhysicalPath;
}
public string Draw()
{
try
{
int GifWidth = 762;
int GifHeight = 240;
string ImgWidth = "762px";
OWC.ChartSpace objCSpace = new OWC.ChartSpaceClass();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//在ChartSpace对象中添加图表,Add方法返回chart对象
OWC.ChChart objChart = objCSpace.Charts.Add(0);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//指定图表是否需要图例
objChart.HasLegend = true;
objChart.Legend.Position = OWC.ChartLegendPositionEnum.chLegendPositionBottom;
objChart.Type = m_chartType;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (m_chartType == OWC.ChartChartTypeEnum.chChartTypePie3D)
{
GifWidth = 254;
GifHeight = 280;
ImgWidth = "254px";
objChart.Legend.Position = OWC.ChartLegendPositionEnum.chLegendPositionRight;
}
if (m_chartType == OWC.ChartChartTypeEnum.chChartTypeColumnClustered)
{
GifWidth = 506;
GifHeight = 280;
ImgWidth = "506px";
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//图形标题
objChart.HasTitle = true;
objChart.Title.Caption = m_strChartTitle;
objChart.Title.Font.Size = 10;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
for (int i = 0; i < m_nCount; i++)
{
string strValue = m_strValues[i];
string strSeriesName = m_strSeries[i];
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
int iSer = i;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//添加一个series
objChart.SeriesCollection.Add(iSer);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//给定series的名字
objChart.SeriesCollection[iSer].SetData(OWC.ChartDimensionsEnum.chDimSeriesNames,
+(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//给定分类,横轴
objChart.SeriesCollection[iSer].SetData(OWC.ChartDimensionsEnum.chDimCategories,
+(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, m_strCategory);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//给定各分类的数值,纵轴
objChart.SeriesCollection[iSer].SetData(OWC.ChartDimensionsEnum.chDimValues,
+(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
objChart.SeriesCollection[iSer].Line.set_Weight(OWC.LineWeightEnum.owcLineWeightThick);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 背景色
objChart.PlotArea.Interior.Color = OWC.ChartColorIndexEnum.chColorNone;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
objChart.Legend.Interior.SetTwoColorGradient(
Microsoft.Office.Interop.Owc11.ChartGradientStyleEnum.chGradientHorizontal,
Microsoft.Office.Interop.Owc11.ChartGradientVariantEnum.chGradientVariantEdges,
"LightGray", "White");
objChart.Legend.Border.Color = OWC.ChartColorIndexEnum.chColorNone;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
objCSpace.Interior.SetTwoColorGradient(
Microsoft.Office.Interop.Owc11.ChartGradientStyleEnum.chGradientHorizontal,
Microsoft.Office.Interop.Owc11.ChartGradientVariantEnum.chGradientVariantEdges,
"LightGray", "White");
objCSpace.Border.Color = OWC.ChartColorIndexEnum.chColorNone;
//输出成GIF文件.
m_strFileName = m_strFileName + ".gif";
m_strAbsolutePath = m_strAbsolutePath + m_strFileName;
objCSpace.ExportPicture(m_strAbsolutePath, "GIF", GifWidth, GifHeight);
string strImageUrl = @"<img src='" + m_strPhysicalPath + m_strFileName + "' width='" + ImgWidth + "' />";
return strImageUrl;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
DrawChart dc = new DrawChart(m_strSeries, m_strCategory, m_strValues, m_strChartTitle, m_strAbsolutePath,
m_strPhysicalPath, m_strFileName, m_nCount, m_chartType);
divChart.InnerHtml = dc.Draw();//divChart是在html页中随便一个div,当然runat=server了
下面还是给出代码:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
大家要注意:字符串strCategory 和 字符串数组strValues 项都是以"\t"分隔的字符串,但最后不能以"\t"结束。
例如:strCategory = "周一\t周二\t周三\t周四\t周五\t周六\t周日"
其中的颜色和图的底色都是可以自己改变的,这个主要起到起步的作用,希望谁看到能画出更漂亮的图。
类的使用:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)