public PlaceHolder PlaceHolder1; //顯示圖像的控件
各個圖像的類別名稱如下:
PictureType 圖形種類 5 chChartTypeBarClustered 簇狀條形圖 0 NULL
PictureType 圖形種類 7 chChartTypeBarClustered3D 三維簇狀條形圖 0 NULL
PictureType 圖形種類 6 chChartTypeBarStacked 堆積條形圖 0 NULL
PictureType 圖形種類 8 chChartTypeBarStacked3D 三維堆積條形圖 0 NULL
PictureType 圖形種類 1 chChartTypeColumnClustered 簇狀柱形圖 0 NULL
PictureType 圖形種類 3 chChartTypeColumnClustered3D 三維簇狀柱形圖 0 NULL
PictureType 圖形種類 2 chChartTypeColumnStacked 堆積柱狀圖 1 NULL
PictureType 圖形種類 4 chChartTypeColumnStacked3D 三維堆積柱形圖 0 NULL
PictureType 圖形種類 13 chChartTypeLine 折線圖 0 NULL
PictureType 圖形種類 15 chChartTypeLineMarkers 數據點折線圖 0 NULL
PictureType 圖形種類 14 chChartTypeLineStacked 堆積折線圖 0 NULL
PictureType 圖形種類 16 chChartTypeLineStackedMarkers 堆積數據點折線圖 0 NULL
PictureType 圖形種類 17 chChartTypePie 餅圖 1 NULL
PictureType 圖形種類 19 chChartTypePie3D 三維餅圖 0 NULL
PictureType 圖形種類 18 chChartTypePieExploded 分離型餅圖 0 NULL
PictureType 圖形種類 20 chChartTypePieExploded3D 分離型三維餅圖 0 NULL
PictureType 圖形種類 9 chChartTypeSmoothLine 平滑線圖 0 NULL
PictureType 圖形種類 10 chChartTypeSmoothLineMarkers 數據點平滑線圖 0 NULL
PictureType 圖形種類 11 chChartTypeSmoothLineStacked 堆積平滑線圖 0 NULL
PictureType 圖形種類 12 chChartTypeSmoothLineStackedMarkers 堆積數據平滑線圖 0 NULL
取圖像的方法如下:
/// </summary>
/// <param name="dbDtViewWrk">傳遞的數據</param>
/// <param name="strAbsolutePath">絕對路徑</param>
/// <param name="strRelativePath">相對路徑</param>
/// <param name="ChartType">要畫的圖格式(餅圖或者折線圖等)</param>
/// <param name="strTitle">統計名稱</param>
public void PaintToImage(DataTable dbDtViewWrk, string strAbsolutePath, string strRelativePath, ChartChartTypeEnum ChartType, string strTitle)
{
string strSeriesName = "圖例";
//存放項目
string[] ItemsName = new string[dbDtViewWrk.Rows.Count];
//存放數據
string[] ItemsCount = new string[dbDtViewWrk.Rows.Count];
//刻度單位
int iUnit = 1;
//最大值
int iMaxValue = 0;
string strXdata = String.Empty;
string strYdata = String.Empty;
//為數組賦值
for (int i = 0; i < dbDtViewWrk.Rows.Count; i++)
{
ItemsName[i] = dbDtViewWrk.Rows[i][0].ToString(); //要統計的字段名字
ItemsCount[i] = dbDtViewWrk.Rows[i][5].ToString();//要統計的字段數據
}
//為x軸指定特定字符串,以便顯示數據
// string strXdata = String.Empty;
foreach (string strData in ItemsName)
{
strXdata += strData + "\t";
}
// string strYdata = String.Empty;
//為y軸指定特定的字符串,以便與x軸相對應
foreach (string strValue in ItemsCount)
{
strYdata += strValue + "\t";
if (int.Parse(strValue) > iMaxValue)
{
iMaxValue = int.Parse(strValue);
}
}
if (iMaxValue > 20)
{
iUnit = iMaxValue / 10;
}
//創建ChartSpace對象來放置圖表
ChartSpace laySpace = new ChartSpaceClass();
//在ChartSpace對象中添加圖表
ChChart InsertChart = laySpace.Charts.Add(0);
//底座顏色
InsertChart.PlotArea.Interior.Color = "white";
//指定繪制圖表的類型。類型可以通過OWC.ChartChartTypeEnum枚舉值得到
InsertChart.Type = ChartType;//柱形圖
//指定圖表是否需要圖例標注
InsertChart.HasLegend = true;
InsertChart.BarWidth = 0;
InsertChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
InsertChart.HasTitle = true;//為圖表添加標題
InsertChart.Title.Caption = strTitle;//標題名稱
//為x,y軸添加圖示說明
if (ChartType.ToString().IndexOf("ChartTypePie") == -1)
{
InsertChart.Axes[0].Font.Size = 11; //X軸
InsertChart.Axes[1].Font.Size = 11; //Y軸
InsertChart.Legend.Font.Size = 11;
InsertChart.Axes[0].HasTitle = true;
InsertChart.Axes[0].Title.Caption = "";//月份
InsertChart.Axes[1].HasTitle = true;
//InsertChart.Axes[1].Scaling.SplitMinimum = 200;
InsertChart.Axes[1].Title.Caption = "數量";
InsertChart.Axes[1].MajorUnit = iUnit; //刻度單位設置
InsertChart.Axes[1].Scaling.Minimum = 0;//最小刻度=0
}
//添加一個series系列
InsertChart.SeriesCollection.Add(0);
//給定series系列的名字
InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);
//給定分類
strXdata = strXdata.Substring(0, strXdata.Length - 1);
InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata);
//給定值
strYdata = strYdata.Substring(0, strYdata.Length - 1);
InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);
//添加標簽
ChDataLabels dls = InsertChart.SeriesCollection[0].DataLabelsCollection.Add();
if (ChartType.ToString().IndexOf("ChartTypePie") != -1)
{
dls.Position = ChartDataLabelPositionEnum.chLabelPositionCenter;
dls.HasPercentage = false;
//dls.HasValue = false;
dls.HasCategoryName = false;
//指定圖表是否需要圖例標注
InsertChart.HasLegend = true;
InsertChart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
}
//輸出文件.
int iImageLength = 0;
int iImageWidth = 0;
//從Config文件取得設置
//iImageLength = int.Parse(WebConfigurationManager.AppSettings["ShowImageLength"]);
//iImageWidth = int.Parse(WebConfigurationManager.AppSettings["ShowImageWidth"]);
iImageLength = 450;
iImageWidth = 300;
string strImageName = ChartType.ToString() + "_" + Guid.NewGuid().ToString("N") + ".png";
laySpace.ExportPicture(strAbsolutePath + strImageName, "PNG", 450, 300);
//把圖片添加到placeholder中,並在頁面上顯示
string strImageTag = "<IMG WIDTH='450' SRC='" + strRelativePath + strImageName + "'/>";
this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));
// return strImageTag;
}
a1 = 0x01; //0000 0001
a2 = 0x00; //0000 0000
a3 = 0x03; //0000 0011
a4 = 0x02; //0000 0010
b1 = a1 ^ a2; //0000 0001
b2 = a1 ^ a3; //0000 0010
b3 = a1 ^ a4; //0000 0011
^異或運算符,位值相同為0,不同為1,見上示例.
//
簡單實際問題舉例:
======\=======\=======
======a=======b=======
上面是2條電路,2個開關分別為a和b,打開狀態:\[1],關閉狀態:/[0].
若同時打開或者關閉,兩條電路均不通.
若a打開[1],b關閉[0],電路1通電
======\=======/=======
若a關閉[0],b打開[1],電路2通電
======/=======\=======
綜上,電路在a,b狀態相同時不通[0],在a,b不同時通電[1].
所謂素數是指除了1和它本身以外,不能被任何整數整除的數,例如17就是素數,因為它不能被2~16的任一整數整除。因此判斷一個整數m是否是素數,只需把m被2~m-1之間的每一個整數去除,如果都不能被整除,那麼m就是一個素數
另外判斷方法還可以簡化。m不必呗2~m-1之間的每一個整數去除,只需被2~√m之間的每一個整數去除就可以了。如果m不能被2~√m間任一整數整除,m必定是素數。例如判別17是是否為素數,只需使17被2~4之間的每一個整數去除,由於都不能整除,可以判定17是素數。(原因:因為如果m能被2~m-1之間任一整數整除,其二個因子必定有一個小於或等於√m,另一個大於或等於√m。例如16能被2,4,8整除,16=2*8,2小於4,8大於4,16=4*4,4=√16,因此只需判定在2~4之間有無因子即可)
#include<stdio.h>
#include<math.h>
void main()
{
int m,i,k;
printf("請輸入一個整數:");
scanf("%d",&m);
k=(int)sqrt(m);
for(i=2;i<=k;i++)
if(m%i==0)
break;
if(i>k)
printf("%d 是素數。\n",m);
else
printf("%d 不是素數。\n",m);
}