设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 3122|回复: 5
打印 上一主题 下一主题

[窗体] 利用office chart 制作完美图表

[复制链接]
跳转到指定楼层
1#
发表于 2015-4-16 22:53:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 roych 于 2015-4-17 08:51 编辑

access自带的图表要存数据,导致文件急剧膨胀,利用office chart,制作出赏心悦目的趋势图,柱状图。科学得很。
Private Const conn = "Provider=SQLOLEDB.1;Password=密码;Persist Security Info=True;User ID=sa;Initial Catalog=数据库名;Data Source=SQL服务器地址"
  Dim QsSql As String
      Dim chConstants
      QsSql = "SELECT 日期,铝粉,精钛产品量,入库量,低价钛 FROM dbo.精制每日汇总 WHERE 日期 BETWEEN '" & Forms!精制查询分析!DateS & "' And '" & Forms!精制查询分析!DateE & "';"
      Me.ChartSpace1.ConnectionString = conn
      Me.ChartSpace1.CommandText = QsSql      
      Set chConstants = Me.ChartSpace1.Constants
    '单个图表,多个序列
       Me.ChartSpace1.HasMultipleCharts = False
       Me.ChartSpace1.PlotAllAggregates = chConstants.chPlotAggregatesSeries     
     '多个图表,每图表一个序列
     'ChartSpace1.HasMultipleCharts = True
     'ChartSpace1.PlotAllAggregates = chConstants.chPlotAggregatesCharts
      Me.ChartSpace1.SetData chConstants.chDimCategories, chConstants.chDataBound, "日期"
      Me.ChartSpace1.SetData chConstants.chDimValues, chConstants.chDataBound, Array("铝粉", "精钛产品量", "入库量", "低价钛")
      Me.ChartSpace1.SetData chConstants.chDimFormatValues, chConstants.chDataBound, Array("铝粉", "精钛产品量", "入库量", "低价钛")
     '设置序列型号
      Me.ChartSpace1.Charts(0).Type = 6  '13折线,0为柱状
     '设置序列线的颜色
      Me.ChartSpace1.Charts(0).SeriesCollection(0).Line.Color = "red"
      Me.ChartSpace1.Charts(0).SeriesCollection(1).Line.Color = "blue"
      Me.ChartSpace1.Charts(0).SeriesCollection(2).Line.Color = 16711935
      Me.ChartSpace1.Charts(0).SeriesCollection(3).Line.Color = "yellow"
     '设置序列线的宽度
      Me.ChartSpace1.Charts(0).SeriesCollection(0).Line.Weight = 1
      Me.ChartSpace1.Charts(0).SeriesCollection(1).Line.Weight = 1
      Me.ChartSpace1.Charts(0).SeriesCollection(2).Line.Weight = 1
      Me.ChartSpace1.Charts(0).SeriesCollection(3).Line.Weight = 1
     '设置序列的图例名称
      Me.ChartSpace1.HasChartSpaceLegend = True
      Me.ChartSpace1.Charts(0).SeriesCollection(0).Caption = "铝粉"
      Me.ChartSpace1.Charts(0).SeriesCollection(1).Caption = "在产品量"
      Me.ChartSpace1.Charts(0).SeriesCollection(2).Caption = "产量"
      Me.ChartSpace1.Charts(0).SeriesCollection(3).Caption = "低价钛"
      With ChartSpace1.ChartSpaceLegend
        .Position = chConstants.chLegendPositionTop
        .Font.Color = 0
        .Font.Size = 9
      End With

     '设置图表标题
      Me.ChartSpace1.HasChartSpaceTitle = True
         With ChartSpace1.ChartSpaceTitle
           .Caption = "产量及铝粉趋势图"
           .Font.Size = 12
           .Font.Color = "#000000"
           .Font.Bold = True
         End With
End Sub


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享分享 分享淘帖 订阅订阅
2#
发表于 2015-4-17 08:10:53 | 只看该作者
分享一下小例子更好!谢谢
3#
发表于 2015-4-17 10:32:24 | 只看该作者
本帖最后由 roych 于 2015-4-17 10:35 编辑

怎么说呢?用控件草草测试了一下,比起Access自带的Graph来,Office Chart最大的缺陷在于无法混合图表类型(如:柱状图-折线图)。有时间再用代码测试。印象中,之前的Microsoft Chart也挺好用的,但Access 2010似乎不再支持这个控件了。

4#
发表于 2015-4-17 17:12:04 | 只看该作者
谢谢分享
回复

使用道具 举报

5#
发表于 2016-4-9 23:39:19 | 只看该作者
支持原创
回复

使用道具 举报

6#
发表于 2016-7-10 00:21:51 | 只看该作者
好好好呵呵呵呵呵
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-17 08:29 , Processed in 0.108593 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表