下面是我用 孟老大的例子改的。 为什么传入的是正值和 0 怎么画出来的图有负值呢?是不是什么设置不对? 还有如何让图从坐标的起始点画起呢????
'给定分类
ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimCategories, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory)
'给定值
ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue)strCategory值为"2006-08-18 2006-08-19 2006-08-20 2006-08-21 2006-08-22 2006-08-23 2006-08-24" String
strValue 值为"85 0 0 2 2 0 31" String另外100分贴:http://community.csdn.net/Expert/topic/4976/4976627.xml?temp=.4848596
'给定分类
ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimCategories, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory)
'给定值
ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue)strCategory值为"2006-08-18 2006-08-19 2006-08-20 2006-08-21 2006-08-22 2006-08-23 2006-08-24" String
strValue 值为"85 0 0 2 2 0 31" String另外100分贴:http://community.csdn.net/Expert/topic/4976/4976627.xml?temp=.4848596
我这里调试没有问题。代码如下<%@ Page Language="C#" %><%@ Import Namespace="Microsoft.Office.Interop.Owc11" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>无标题页</title>
</head><script runat="server"> protected void Page_Load(object sender, EventArgs e)
{
//创建ChartSpace对象来放置图表
Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass(); //在ChartSpace对象中添加图表,Add方法返回chart对象
Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0); //指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered; //指定图表是否需要图例
objChart.HasLegend = true; //给定标题
objChart.HasTitle = true;
objChart.Title.Caption = "上半年分布图"; //给定x,y轴的图示说明
objChart.Axes[0].HasTitle = true;
objChart.Axes[0].Title.Caption = "Y : 数量";
objChart.Axes[1].HasTitle = true;
objChart.Axes[1].Scaling.SplitMinimum = 100;
objChart.Axes[1].Title.Caption = "X : 月份"; //计算数据
/*categories 和 values 可以用tab分割的字符串来表示*/
string strSeriesName = "图例 1";
string strCategory = "2006-08-18" + "\t" + "2006-08-19" + "\t" + "2006-08-20" + "\t" + "2006-08-21" + "\t" + "2006-08-22" + "\t" + "2006-08-23" + "\t" + "2006-08-24";
string strValue = "85" + "\t" + "0" + "\t" + "0" + "\t" + "2" + "\t" + "2" + "\t" + "0" + "\t" + "31"; //添加一个series
objChart.SeriesCollection.Add(0); //给定series的名字
objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,
+(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName); //给定分类
objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
+(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory); //给定值
objChart.SeriesCollection[0].SetData
(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,
(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
//输出成GIF文件.
string strAbsolutePath = (Server.MapPath(".")) + "\\test.gif";
objCSpace.ExportPicture(strAbsolutePath, "GIF", 600, 450); //创建GIF文件的相对路径.
string strRelativePath = "./test.gif"; //把图片添加到placeholder.
string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
ChartHolder.Controls.Add(new LiteralControl(strImageTag));
}
</script><body>
<form id="Form1" method="post" runat="server">
<asp:PlaceHolder ID="ChartHolder" runat="server"></asp:PlaceHolder>
</form>
</body>
</html>
http://dotnet.aspx.cc/test.gif
http://dotnet.aspx.cc/test1.gif
//指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLineMarkers;chChartTypeSmoothLineMarkers,chChartTypeSmoothLine等会出现负值,这与这些图形的生成方法有关系。而使用chChartTypeLineMarkers类型则不会有负值