| 发表于:2007-03-12 08:49:233楼 得分:0 |
给你个例子 '用到microsoft chart control 这个控件 '下面代码放到类模块中 '******************** option explicit public introws ' 列数,用于设置图表中显示的列数。 public arrmpgandtank() ' mpg 和每桶升数 dim txtsql as string dim msgtext as string dim mrc as adodb.recordset dim msg as string '信息 public sub setupchart() txtsql = "select * from zhfxsjb1 where xmxx_id= " & xmid set mrc = EXECutesql(txtsql, msgtext) do while not mrc.eof mrc.movenext introws = introws + 1 loop ' 配置图表。 with frmfhstt.chtsample .rowcount = introws ' 在设置图表数据之前,必须设置行数。 .columncount = 2 ' 两列。第一列显示“每升公里数”,第二列显示使用的升数。 .columnlabelcount = 2 'columnlabelcount返回或设置与图表关联的数据网格中的列的标签级别数 ' 在右上角为这个图设置图例。 ' 然后为图例设置坐标。 .legend.location.locationtype = vtchlocationtyperight 'legend它包含有关小图标的外观及其描述图表系列的伴随文字的信息。 'location该对象描述文本图表元素的位置 'locationtype返回或设置显示图表元素的标准位置 'vtchlocationtypetop为图表元素提供了以下位置选项(顶部) .legend.vtfont.style = vtfontstylebold 'vtfont该对象描述用于显示图表文本的字体 'vtfontstylebold字体应用粗体属性 .legend.location.rect.max.set 7560, 5132 .legend.location.rect.min.set 3004, 4864 'rect该对象定义坐标点 end with end sub public sub poptwoarray(byref thisarray) ' 用两个序列组织成任意的数组。第三个元素用于获得日期值。 redim thisarray(1 to introws, 1 to 3) dim i as integer 'redim 'redim用于为动态数组变量重新分配存储空间 txtsql = "select * from zhfxsjb1 where xmxx_id= " & xmid set mrc = EXECutesql(txtsql, msgtext) i = 1 if mrc.recordcount > 0 then do while not mrc.eof ' 获得 date 值。 'thisarray(i, 1) = cstr(mrc.fields(6)) 'thisarray(i, 1) = format(mrc.fields(2), "##.## ") ' 获得值。 thisarray(i, 2) = format(mrc.fields(60), "##.## ") '自然电位曲线 thisarray(i, 1) = format(mrc.fields(62), "##.## ") '阴极保护电位曲线 'format返回 variant (string),其中含有一个表达式,它是根据格式表达式中的指令来格式化的 mrc.movenext i = i + 1 if i > introws then exit do end if loop set mrc = nothing end if end sub public sub twocolchart() ' 使用 arrmpgandtank 数组来创建一个两行的图表。 with frmfhstt.chtsample .chartdata = arrmpgandtank 'chartdata绘制图表最简单的方法就是创建数字型的数组,然后将 chartdata 属性设为该数组 ' .title = "防护势态图 " .columnlabelcount = 1 'columnlabelcount返回或设置与图表关联的数据网格中的列的标签级别数 .columncount = 2 'columncount返回或设置与图表关联的当前数据网格中的列数 .column = 1 ' .columnlabel = "阴极保护电位 " 'columnlabel返回或设置与图表数据网格中的列关联的标签文本 .column = 2 ' .columnlabel = "自然电位 " .refresh end with end sub '************************ | | |
|