|
本帖最后由 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
|
|