代码如下:
28 string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t'+"4" + '\t' + "5" + '\t' + "6" + '\t';
29 string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t'+"10" + '\t' + "12" + '\t' + "6" + '\t';
30
31 //声明对象
32 Microsoft.Office.Interop.Owc11.ChartSpace ThisChart = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();
33 Microsoft.Office.Interop.Owc11.ChChart ThisChChart = ThisChart.Charts.Add(0);
34 Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = ThisChChart.SeriesCollection.Add(0);
35
36 //显示图例
37 ThisChChart.HasLegend = true;
38 //标题
39 ThisChChart.HasTitle = true;
40 ThisChChart.Title.Caption = "统计图";
41
42 //给定x,y轴图示说明
43 ThisChChart.Axes[0].HasTitle = true;
44 ThisChChart.Axes[1].HasTitle = true;
45 ThisChChart.Axes[0].Title.Caption = "月份";
46 ThisChChart.Axes[1].Title.Caption = "数量";
47
48 //图表类型
49 ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D;
50 //旋转
51 ThisChChart.Rotation = 360;
52 ThisChChart.Inclination = 10;
53 //背景颜色
54 ThisChChart.PlotArea.Interior.Color = "red";
55 //底色
56 ThisChChart.PlotArea.Floor.Interior.Color = "green";
57
58 ThisChChart.Overlap = 50;
59
60 /**/////给定series的名字
61 ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),"日期");
62 //给定分类
63 ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strCategory);
64 //给定值
65 ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strValue);
66 //导出图像文件
67 try
68 {
69
70 ThisChart.ExportPicture(Server.MapPath("chart.gif"),"gif",600,350);
71 Response.Write( "<IMG SRC='" + Server.MapPath("chart.gif") + "'/>");
72 }
73 catch(Exception ee)
74 {
75
76 }其中 x轴的刻度是:
string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t'+"4" + '\t' + "5" + '\t' + "6" + '\t';
要显示的曲线的值是:
string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t'+"10" + '\t' + "12" + '\t' + "6" + '\t';现在我需要显示的曲线是中间断了一截的,即9 , 8, 12,6 ,中间的4和10不显示,既断开为两段曲线,可我无论怎么尝试,
曲线总是连续的,求解决方法
28 string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t'+"4" + '\t' + "5" + '\t' + "6" + '\t';
29 string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t'+"10" + '\t' + "12" + '\t' + "6" + '\t';
30
31 //声明对象
32 Microsoft.Office.Interop.Owc11.ChartSpace ThisChart = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();
33 Microsoft.Office.Interop.Owc11.ChChart ThisChChart = ThisChart.Charts.Add(0);
34 Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = ThisChChart.SeriesCollection.Add(0);
35
36 //显示图例
37 ThisChChart.HasLegend = true;
38 //标题
39 ThisChChart.HasTitle = true;
40 ThisChChart.Title.Caption = "统计图";
41
42 //给定x,y轴图示说明
43 ThisChChart.Axes[0].HasTitle = true;
44 ThisChChart.Axes[1].HasTitle = true;
45 ThisChChart.Axes[0].Title.Caption = "月份";
46 ThisChChart.Axes[1].Title.Caption = "数量";
47
48 //图表类型
49 ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D;
50 //旋转
51 ThisChChart.Rotation = 360;
52 ThisChChart.Inclination = 10;
53 //背景颜色
54 ThisChChart.PlotArea.Interior.Color = "red";
55 //底色
56 ThisChChart.PlotArea.Floor.Interior.Color = "green";
57
58 ThisChChart.Overlap = 50;
59
60 /**/////给定series的名字
61 ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),"日期");
62 //给定分类
63 ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strCategory);
64 //给定值
65 ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strValue);
66 //导出图像文件
67 try
68 {
69
70 ThisChart.ExportPicture(Server.MapPath("chart.gif"),"gif",600,350);
71 Response.Write( "<IMG SRC='" + Server.MapPath("chart.gif") + "'/>");
72 }
73 catch(Exception ee)
74 {
75
76 }其中 x轴的刻度是:
string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t'+"4" + '\t' + "5" + '\t' + "6" + '\t';
要显示的曲线的值是:
string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t'+"10" + '\t' + "12" + '\t' + "6" + '\t';现在我需要显示的曲线是中间断了一截的,即9 , 8, 12,6 ,中间的4和10不显示,既断开为两段曲线,可我无论怎么尝试,
曲线总是连续的,求解决方法
chChartTypeScatterLine 不带结点的曲线而且在曲线时填充值的时候也有问题如果你安装了office 2003 可以看
C:\Program Files\Common Files\Microsoft Shared\Web Components\11\2052\OWCVBA11.CHM帮助文档
private void LoadChart(string staid, int[,] DayTide ,string sDate )
{
//创建ChartSpace对象来放置图表
OWC11.ChartSpace objCSpace = new OWC11.ChartSpaceClass(); //在ChartSpace对象中添加图表,Add方法返回chart对象
OWC11.ChChart objChart = objCSpace.Charts.Add (0); //指定图表的类型。类型由OWC11.ChartChartTypeEnum枚举值得到
objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeSmoothLine;
objChart.Interior.Color = "LightSkyBlue";
objChart.PlotArea.Interior.Color = "LightSkyBlue";
//指定坐标轴上刻度线标签之间的分类数为 4(每半点在X轴标示出来)
objChart.Axes[0].TickLabelSpacing = 12 ;
objChart.Axes[0].TickMarkSpacing = 6 ; System.DateTime Yesterday = System.DateTime.Today.AddDays(-1) ; //给定标题
objChart.HasTitle = true; if (sDate == DateTime.Now.ToString("yyyy-MM-dd"))
{
objChart.Title.Caption = Yesterday.ToString("yyyy-MM-dd") + "至" + DateTime.Now.ToString("yyyy-MM-dd") + staid + "水文站潮位图(潮高:厘米)" ;
}
else
{
objChart.Title.Caption = Convert.ToDateTime(sDate).AddDays(-1).ToString("yyyy-MM-dd") + "至" + sDate + staid + "水文站潮位图(潮高:厘米)" ;
} //给定x,y轴的图示说明
objChart.Axes[0].HasTitle = true;
objChart.Axes[0].Title.Caption = "时间(时)"; string strCategory = "";
string strValue = ""; for (int i = 0; i< 48 ; i++ )
{
if (i != 0 )
{
if (i >= 24)
{
strCategory = strCategory + Convert.ToString(i - 24) + " " ;
}
else
{
strCategory = strCategory + i.ToString() ;
}
}
for (int j =0; j<12 ; j++ )
{
if ( i == 47 && j == 11)
{
strCategory = strCategory + "24" +'\t';
}
else
{
if ( j % 2 == 0 && j != 0 )
{
strCategory = strCategory + Convert.ToString(j/2) + "."+ GetNum(i) + '\t';
}
else
{
strCategory = strCategory +'\t';
}
} if ( CompTime(i,j,sDate) == false )
{
strValue = strValue + '\t'+ '\t';
}
else
{
//数据非法的处理
if ( DayTide[i,j] == 9998 || DayTide[i,j] == 9999 )
{
strValue = strValue + '\t' + '\t';
}
else
{
strValue = strValue + DayTide[i,j].ToString() + '\t';
}
}
}
}
//添加一个series
objChart.SeriesCollection.Add(0);
//给定分类
objChart.SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimCategories,
+ (int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory); //给定值
objChart.SeriesCollection[0].SetData
(OWC11.ChartDimensionsEnum.chDimValues,
(int)OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue); //设定曲线的颜色
objChart.SeriesCollection[0].Line.Color = "green";
//是否显示X坐标的网格线
objChart.Axes[0].HasMajorGridlines = true ;
objChart.Axes[1].HasMajorGridlines = true ;
objChart.Axes[0].MajorGridlines.Line.Color = "white" ;
objChart.Axes[1].MajorGridlines.Line.Color = "white" ;
//在曲线上显示各个整点对应潮位图
Random r = new Random( DateTime.Now.Millisecond );
int kk = r.Next(1, 10000); //输出成GIF文件.
string strAbsolutePath = (Server.MapPath(".")) + "\\i\\"+ staid + kk.ToString() +".gif"; if (File.Exists(strAbsolutePath))
{
File.Delete(strAbsolutePath);
} objCSpace.ExportPicture(strAbsolutePath, "GIF", 600, 302); //创建GIF文件的相对路径.
string strRelativePath = "./i/"+ staid + kk.ToString() +".gif"; //把图片添加到placeholder.
string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
ChartHolder.Controls.Add(new LiteralControl(strImageTag));
}当数据为9998或者9999的时候曲线需要断开不让它显示.