关闭

关闭

关闭

封号提示

内容

首页 chartControl.doc

chartControl.doc

chartControl.doc

上传者: ahnuczg002 2012-07-19 评分 0 0 0 0 0 0 暂无简介 简介 举报

简介:本文档为《chartControldoc》,可适用于IT/计算机领域,主题内容包含'绘制饼状图    PublicFunctionDrawPie(ByValdtAsDataTable)        DimcountAsInteg符等。

'绘制饼状图    PublicFunctionDrawPie(ByValdtAsDataTable)        DimcountAsInteger=dtRowsCount        Ifcount>Then            InitChartControl("")            ChartControlSeriesClear()            DimiAsInteger            DimseriesAsNewSeries("股权结构饼状图",ViewTypePieD)            DimnumAsInteger=            '为控件循环绑定值            Ifcount>Then                DimnewDtAsDataTable=ShowOther(dt,num)                Fori=TonewDtRowsCount                    seriesPointsAdd(NewSeriesPoint(newDtRows(i)("股东名称")ToString(),NewDouble(){newDtRows(i)("投资比例")}))                Next            Else                Fori=TodtRowsCount                    seriesPointsAdd(NewSeriesPoint(dtRows(i)("股东名称")ToString(),NewDouble(){dtRows(i)("投资比例")}))                    If(NotdtRows(i)Is("投资比例"))Then                        If(dtRows(i)("投资比例")<)Then                            num=                        EndIf                    EndIf                Next            EndIf            If(num>)Then                seriesLabelVisible=False'设置饼状图上的文字是否显示                seriesLegendPointOptionsPointView=PointViewArgumentAndValues'设置说明格式                seriesLegendPointOptionsValueNumericOptionsFormat=NumericFormatPercent                'seriesLegendPointOptionsValueNumericOptions            Else                seriesLabelVisible=True                seriesLegendPointOptionsPointView=PointViewArgument  '设置说明格式                seriesLabelFont=NewFont("宋体",F,SystemDrawingFontStyleBold)                seriesLabelLineLength=            EndIf            seriesLabelBorderVisible=False'设置饼状图上的文字是否加边框            seriesPointOptionsValueNumericOptionsFormat=NumericFormatPercent     '设置文字显示格式                   'seriesShowInLegend=True                   CType(seriesLabel,PieSeriesLabel)Position=PieSeriesLabelPositionOutside            'seriesSeriesPointsSorting=SortingModeDescending'为饼状图排序            'CType(seriesView,PieDSeriesView)ExplodeMode=PieExplodeModeAll  '设置块与块之间的间隙            'CType(seriesView,PieDSeriesView)ExplodedDistancePercentage=   '设置块与块之间的间隙:大小            ChartControlSeriesAdd(series)            ChartControlExportToImage("C:OSF股权结构饼状图png",SystemDrawingImagingImageFormatJpeg)            '添加标签然后向标签处添加图片            DimreftrueAsObject=True            DimreffalseAsObject=False            DimbmkAsWordBookmark=odocBookmarksItem()            DimrmkAsObject=bmk            DimstartAsObject=bmkStart            DimendAsObject=bmkEnd            odocRange(start,end)InlineShapesAddPicture("C:OSF股权结构饼状图png",reffalse,reftrue,missing)        EndIf    EndFunction     '绘制柱状图    PublicFunctionDrawBar(ByValdtAsDataTable)        ChartControlSeriesClear()        InitChartControl("员工人数")        DimiAsInteger        DimseriesAsNewSeries("员工人数",ViewTypeBar)        seriesPointsAdd(NewSeriesPoint("",NewDouble(){}))        seriesPointsAdd(NewSeriesPoint("  ",NewDouble(){}))        Fori=TodtRowsCount            seriesPointsAdd(NewSeriesPoint(dtRows(i)("实际完成时间")ToString(),NewDouble(){dtRows(i)("员工人数")}))        Next        seriesShowInLegend=False    '设置是否显示说明        seriesLabelVisible=True    '设置是否显示引线文字        '((GanttSeriesView)seriesView)BarWidth=        CType(seriesView,SideBySideBarSeriesView)BarWidth=        ChartControlSeriesAdd(series)        ChartControlExportToImage("C:OSF员工人数柱状图png",SystemDrawingImagingImageFormatJpeg)        '添加标签然后向标签处添加图片        DimreftrueAsObject=True        DimreffalseAsObject=False        DimbmkAsWordBookmark=odocBookmarksItem()        DimrmkAsObject=bmk        DimstartAsObject=bmkStart        DimendAsObject=bmkEnd        odocRange(start,end)InlineShapesAddPicture("C:OSF员工人数柱状图png",reffalse,reftrue,missing)    EndFunction      '股东数量超过个的股东显示为其他    FunctionShowOther(ByValdtAsDataTable,ByRefcountAsInteger)        DimnewDtAsDataTable=NewDataTable("newTable")        newDt=dtClone()        DimdrAsDataRow        DimiAsInteger        DimnumAsDouble=        DimnoAsDouble=        count=        Fori=TodtRowsCount            If(i<)Then                dr=newDtNewRow()                dr("股东名称")=dtRows(i)("股东名称")                dr("投资比例")=dtRows(i)("投资比例")                newDtRowsAdd(dr)                If(NotdtRows(i)Is("投资比例"))Then                    no=CDbl(dr("投资比例"))                    If(CDbl(dtRows(i)("投资比例"))<)Then                        count=                    EndIf                EndIf                         Else                If(NotdtRows(i)Is("投资比例"))Then                    num=dtRows(i)("投资比例")                EndIf            EndIf        Next        If(num<)Then            count=        EndIf        dr=newDtNewRow()        dr("股东名称")="其他"        dr("投资比例")=num        newDtRowsAdd(dr)        If(MathRound(numno)<>)Then            dr=newDtNewRow()            dr("股东名称")="未知股东"            dr("投资比例")=(nonum)            newDtRowsAdd(dr)            If(MathRound((numno))<)Then                count=            EndIf        EndIf             ReturnnewDt    EndFunction      '初始化控件ChartControl    FunctionInitChartControl(ByValtitleAsString)        ChartControlWidth=        ChartControlHeight=        Iftitle<>""Then            DimchartTitleAsChartTitle=NewDevExpressXtraChartsChartTitle()            chartTitleText=title            chartTitleFont=NewFont("宋体",F,SystemDrawingFontStyleBold)            ChartControlTitlesClear()            ChartControlTitlesAdd(chartTitle)        EndIf    EndFunction     '初始化控件ChartControl    FunctionInitChartControl(ByValtitleAsString)        ChartControlWidth=        ChartControlHeight=        Iftitle<>""Then            DimchartTitleAsChartTitle=NewDevExpressXtraChartsChartTitle()            chartTitleText=title            chartTitleFont=NewFont("宋体",F,SystemDrawingFontStyleBold)            ChartControlTitlesClear()            ChartControlTitlesAdd(chartTitle)        EndIf    EndFunction     '初始化控件ChartControl    FunctionInitChartControl(ByValtitleAsString)        ChartControlWidth=        ChartControlHeight=        Iftitle<>""Then            DimchartTitleAsChartTitle=NewDevExpressXtraChartsChartTitle()            chartTitleText=title            chartTitleFont=NewFont("宋体",F,SystemDrawingFontStyleBold)            ChartControlTitlesClear()            ChartControlTitlesAdd(chartTitle)        EndIf    EndFunction    '初始化控件ChartControl    FunctionInitChartControl(ByValtitleAsString)        ChartControlWidth=        ChartControlHeight=        Iftitle<>""Then            DimchartTitleAsChartTitle=NewDevExpressXtraChartsChartTitle()            chartTitleText=title            chartTitleFont=NewFont("宋体",F,SystemDrawingFontStyleBold)            ChartControlTitlesClear()            ChartControlTitlesAdd(chartTitle)        EndIf    EndFunction  调用      '添加股权结构饼状图            DimsqlAsString="select*fromCH股权结构whereCrediteyesNO='"Trim(CrediteyesNO)"'orderby投资比例DESC"            DimmydtAsDataTable=myconnGNZXdataset(sql)Tables()            IfmydtRowsCount>Then                DrawPie(mydt)            EndIf  调用  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''            '绘制员工人数柱状图            mysqi="selecttopCH人员结构*,国内订单表实际完成时间as长时间,convert(varchar,国内订单表实际完成时间,)as实际完成时间fromCH人员结构innerjoin国内订单表on  CH人员结构CrediteyesNO=国内订单表CrediteyesNO"            mysqi="whereCH人员结构CrediteyesNO='"Trim(CrediteyesNO)"'orderby国内订单表实际完成时间desc"            DimBardtAsDataTable=myconnGNZXdataset(mysqi)Tables()            If(BardtRowsCount>)Then                If(NotBardtRows()Is("员工人数"))Then                    DrawBar(Bardt)                EndIf            EndIf  ChartControl使用经验总结分类: MSChart: 人阅读 评论() 收藏 举报近日开始学习和研究这个新奇的控件。一.什么是图表上面这张表中所示的就是一张图表的所有组成。从中我们可以看出图表的五大元素为:附注(Annotations)、图表区(ChartAreas)、图例(Legends)、列(Series)、标题(Titles)。二.如何把Chart控件添加到VS工具箱这三个文件可以从微软网站下载到或是在我的附件中下载。安装的顺序图中排列顺序其中MSChartexe就是图表控件的安装程序MSChartLPchsexe是语言包MsChartVisualStudioAddonexe是扩展安装。都安装完成后打开VS在工具箱中任意处右击"选择项"将下图中所示的两项打上勾即可在工具箱中的Data栏中看到Chart控件。我们可以把它移动到"数据"栏中如下图所示:三.创建一个最简单的图表在设计视图中从工具箱中拖拽Chart控件至页面如下图所示:如果在这个时候预览网页的话是什么也看不见的是一张图表因为它没有数据所以我们要给它赋值并设置相关属性。下同是整个Chart控件的页面代码如何给它赋值大家可以研究一下这段代码。<asp:ChartID="Chart"runat="server">   <Annotations>       <asp:LineAnnotationName="LineAnnotation">       <asp:LineAnnotation>   <Annotations>   <Series>       <asp:SeriesName="Series">           <points>               <asp:DataPointYValues="">               <asp:DataPointYValues="">               <asp:DataPointYValues="">               <asp:DataPointYValues="">               <asp:DataPointYValues="">               <asp:DataPointYValues="">               <asp:DataPointYValues="">               <asp:DataPointYValues="">           <points>       <asp:Series>   <Series>   <ChartAreas>       <asp:ChartAreaName="ChartArea">       <asp:ChartArea>   <ChartAreas><asp:Chart>上面这段代码是直接在aspx文件中书写下面要介绍的是在vb文件中添加数据:   PrivateSubPageLoad(ByValsenderAsSystemObject,ByValeAsSystemEventArgs)HandlesMyBaseLoad       '创建列       DimseriesAsNewSeries("曲线")       seriesChartType=SeriesChartTypeSpline       seriesBorderWidth=       seriesShadowOffset=       '给列赋值       seriesPointsAddY()       seriesPointsAddY()       seriesPointsAddY()       seriesPointsAddY()       seriesPointsAddY()       seriesPointsAddY()       seriesPointsAddY()       seriesPointsAddY()       '将上述创建并赋过值的列添加到图表控件的Series集合中       ChartSeriesAdd(series)   EndSub'PageLoad四.图表类型(ChartStyle) Chart控件提供了丰富的图表类型如柱状、条状、由线、饼图、雷达图等等并可以随时在D和D之间切换。下面所示的是部分图表类型的截图:INCLUDEPICTURE"http:writeblogcsdnnetUploadsDAjpg"*MERGEFORMATINET                (D柱形图)                                   (D条形图)INCLUDEPICTURE"http:writeblogcsdnnetUploadsDECjpg"*MERGEFORMATINET                (D线图)                                   (D饼图)图表类型的设置是是在Series集合中的在代码中的写法如下:ChartSeries("Series名")ChartType=有了这么多的选择就为我们不同的需求提供了大大的方便。五.Chart控件显示数据库中的数据在讲绑定之前先给大家看一张表这张表介绍了在什么样的情况下用什么样的绑定方法十分有用。下面就来分别介绍这张表中介绍到的种种绑定方法。在写示例之前我要说明一下我用到的两张表。MyTest表:SALESCOUNTS表:使用DataBindTable方法   ProtectedSubPageLoad(ByValsenderAsObject,ByValeAsSystemEventArgs)HandlesMeLoad       '绑定一个简单的数据源X轴表示文字型Y轴表示数字型       UsingconectAsNewSqlConnection(ConfigurationManagerConnectionStrings("NTTrafficConnectionString")ConnectionString)           DimCommandAsSqlCommand=NewSqlCommand("SELECTname,scoreFROMMyTest",conect)           conectOpen()           DimreaderAsSqlDataReader=CommandExecuteReader(CommandBehaviorCloseConnection)           ChartDataBindTable(reader,"name")           readerClose()           conectClose()       EndUsing   EndSub结果:使用DataBind方法   ProtectedSubPageLoad(ByValsenderAsObject,ByValeAsSystemEventArgs)HandlesMeLoad       '用databind方法       UsingconectAsNewSqlConnection(ConfigurationManagerConnectionStrings("NTTrafficConnectionString")ConnectionString)           DimMyCommandAsSqlCommand=NewSqlCommand("SELECTname,scoreFROMMyTest",conect)           ChartDataSource=MyCommand           ChartSeries("Series")XValueMember="name"           ChartSeries("Series")YValueMembers="score"           ChartSeries("Series")ChartType=SeriesChartTypeLine           ChartSeries("Series")IsValueShownAsLabel=True           ChartDataBind()       EndUsing   EndSub效果:使用PointsDataBindX(Y)方法   ProtectedSubPageLoad(ByValsenderAsObject,ByValeAsSystemEventArgs)HandlesMeLoad       UsingconectAsNewSqlConnection(ConfigurationManagerConnectionStrings("NTTrafficConnectionString")ConnectionString)           DimCommandAsSqlCommand=NewSqlCommand("SELECTscoreFROMMyTest",conect)           conectOpen()           DimreaderAsSqlDataReader=CommandExecuteReader(CommandBehaviorCloseConnection)           'ChartDataBindTable(reader,"name")           ChartSeries("Series")PointsDataBindY(reader,"score")           'ChartSeries("Series")ChartType=SeriesChartTypeLine           ChartSeries("Series")IsValueShownAsLabel=True           readerClose()           conectClose()       EndUsing   EndSub效果:使用PointsDataBindXY方法   ProtectedSubPageLoad(ByValsenderAsObject,ByValeAsSystemEventArgs)HandlesMeLoad       UsingconectAsNewSqlConnection(ConfigurationManagerConnectionStrings("NTTrafficConnectionString")ConnectionString)           DimCommandAsSqlCommand=NewSqlCommand("SELECTname,scoreFROMMyTest",conect)           conectOpen()           DimreaderAsSqlDataReader=CommandExecuteReader(CommandBehaviorCloseConnection)           ChartSeries("Series")PointsDataBindXY(reader,"name",reader,"score")           ChartSeries("Series")ChartType=SeriesChartTypePie           'ChartSeries("Series")IsValueShownAsLabel=True           readerClose()           conectClose()       EndUsing   EndSub效果:使用PointsDataBind方法   ProtectedSubPageLoad(ByValsenderAsObject,ByValeAsSystemEventArgs)HandlesMeLoad       UsingconectAsNewSqlConnection(ConfigurationManagerConnectionStrings("NTTrafficConnectionString")ConnectionString)           DimCommandAsSqlCommand=NewSqlCommand("SELECT*FROMMyTest",conect)           conectOpen()           DimreaderAsSqlDataReader=CommandExecuteReader(CommandBehaviorCloseConnection)           ChartSeries("Series")PointsDataBind(reader,"Name","score","Tooltip=myhref,label=score")           ChartChartAreas("ChartArea")AreaDStyleEnableD=True           readerClose()           conectClose()       EndUsing   EndSub效果:使用DataBindCrossTable方法   ProtectedSubPageLoad(ByValsenderAsObject,ByValeAsSystemEventArgs)HandlesMeLoad       UsingconectAsNewSqlConnection(ConfigurationManagerConnectionStrings("NTTrafficConnectionString")ConnectionString)           DimCommandAsSqlCommand=NewSqlCommand("SELECT*FROMMyTest",conect)           conectOpen()           DimreaderAsSqlDataReader=CommandExecuteReader(CommandBehaviorCloseConnection)           ChartDataBindCrossTable(reader,"isclass","name","score","label=score")           'DataBindCrossTable(DataSource,SeriesGroup,xField,yFields,otherFields)           '下面一段为模仿原文写不明白为何要用marker           DimmarkerAsMarkerStyle=MarkerStyleStar           ForEachSerAsSeriesInChartSeries               SerChartType=SeriesChartTypeLine               SerShadowOffset=               SerBorderWidth=               SerMarkerSize=               SerMarkerStyle=marker               SerMarkerBorderColor=DrawingColorPink               marker=           Next           readerClose()           conectClose()       EndUsing   EndSub效果:DataBindSeriesByRows   ProtectedSubPageLoad(ByValsenderAsObject,ByValeAsSystemEventArgs)HandlesMeLoad       UsingconectAsNewSqlConnection(ConfigurationManagerConnectionStrings("NTTrafficConnectionString")ConnectionString)           DimCommandAsSqlCommand=NewSqlCommand("SELECT*FROMSALESCOUNTS",conect)           conectOpen()           DimmyDataAdapterAsNewSqlDataAdapter()           myDataAdapterSelectCommand=Command           DimmyDateSetAsNewDataSet()           myDataAdapterFill(myDateSet,"Query")           DimrowAsDataRow           ForEachrowInmyDateSetTables("Query")Rows               DimseriesNameAsString=row("SalesRep")ToString()'显示在右上角的legend为此处的吧?               ChartSeriesAdd(seriesName)               ChartSeries(seriesName)ChartType=SeriesChartTypeLine               ChartSeries(seriesName)BorderWidth=               ChartSeries(seriesName)IsValueShownAsLabel=True               DimcolIndexAsInteger               ForcolIndex=To(myDateSetTables("Query")ColumnsCount)                   DimcolumnNameAsString=myDateSetTables("Query")Columns(colIndex)ColumnName'获得列名                   DimYValAsInteger=CInt(row(columnName))'获得列数据                   ChartSeries(seriesName)PointsAddXY(columnName,YVal)               NextcolIndex           Nextrow           CommandConnectionClose()           conectClose()       EndUsing   EndSub效果:DataBindThenAlignAxisLabel   ProtectedSubPageLoad(ByValsenderAsObject,ByValeAsSystemEventArgs)HandlesMeLoad       DimyvalAsDouble()={,,}       DimxvalAsString()={"Peter","Andrew","Julie"}       DimyvalAsDouble()={,,}       DimxvalAsString()={"Peter","Andrew","Dave"}       DimyvalAsDouble()={,}       DimxvalAsString()={"Julie","Mary"}       ChartSeries("Series")PointsDataBindXY(xval,yval)       ChartSeries("Series")PointsDataBindXY(xval,yval)       ChartSeries("Series")PointsDataBindXY(xval,yval)       ForEachserAsSeriesInChartSeries           serLabel="#AXISLABEL"       Next       'AlignseriesusingtheirXaxislabels       IfAlignSeriesCheckedThen           ChartAlignDataPointsByAxisLabel()       EndIf   EndSubamespaceYLWS{publicpartialclassPeopleChartForm:Form{MainFormmainFormpublicPeopleChartForm(MainFormfrm){InitializeComponent()mainForm=frm}privatevoidPeopleChartFormLoad(objectsender,EventArgse){TODO:这行代码将数据加载到表“systemDataBaseDataSetPopulationBaseInfo”中。您可以根据需要移动或移除它。thispopulationBaseInfoTableAdapterFill(thissystemDataBaseDataSetPopulationBaseInfo)chartControlSeriesValueScaleType=ScaleTypeNumericalchartControlSeriesValueDataMembersAddRange(newstring{"总人口"})}privatevoidradioButtonCheckedChanged(objectsender,EventArgse)

用户评论(0)

0/200

精彩专题

上传我的资料

每篇奖励 +2积分

资料评价:

/18
1下载券 下载 加入VIP, 送下载券

意见
反馈

立即扫码关注

爱问共享资料微信公众号

返回
顶部