以文本方式查看主题
- Foxtable(狐表) (http://foxtable.com/bbs/index.asp)
-- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2)
---- 求助,关于双图表 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=33562)
|
-- 作者:晕了快扶我
-- 发布时间:2013/5/20 23:05:00
-- 求助,关于双图表
想画个双图表,效果是让采购额和销售额同时做出来,左边是销售额,用Bar,右边是采购额,用XYPOTPLOT,弄了一晚上都只能一个,而且Y轴也不对,高手来指点下
Dim d1 As Date = Date.Today Dim y As Integer = d1.Year \'指定年份 Dim m As Integer = d1.Month Dim w As Integer = d1.DayOfWeek Dim q As Integer = (d1.Month - 1) \\ 3 + 1 \'计算现在是第几个季度 Dim dt1 As New Date(y, 1, 1) Dim dt2 As New Date(y, 12, 31) Dim cmd As New SQLCommand cmd.C cmd.CommandText = "select * from {销售出库单主表}" Dim dt As DataTable = cmd.ExecuteReader Dim cmd1 As New SQLCommand cmd1.C cmd1.CommandText = "select * from {采购入库单主表}" Dim dv1 As DataTable = cmd1.ExecuteReader \'===============================取时间,动态加载出入表 Dim Chart As WinForm.Chart = e.Form.Controls("统计图表") Dim Series As WinForm.ChartSeries \'定义一个图系变量 Chart.VisualEffect = True Dim lst As List(Of String) = dt.GetUniqueValues("出库日期>= \'" & dt1 & "\'And 出库日期 <=\'" & dt2 & "\'", "月份") \'获得销售月份集合 Dim lst1 As List(Of String) = dv1.GetUniqueValues("到仓日期>= \'" & dt1 & "\'And 到仓日期 <=\'" & dt2 & "\'", "月份") \'获得采购月份集合 Chart.ChartType = ChartTypeEnum.Bar Chart.ChartType2 = ChartTypeEnum.XYPlot Chart.AxisX.ClearValueLabel Chart.AxisX.AnnoWithLabels = False Chart.SeriesList.Clear() \'清除图表原来的图系 Series = Chart.SeriesList.Add() \'增加一个图系 Series.Text = "销售额" Chart.SeriesList2.Clear() \'清除图表2原来的图系 Series = Chart.SeriesList2.Add() \'给图表2增加一个图系 Series.Text = "采购额" Series.Length = lst.Count \'设置图系的长度 For i As Integer = 0 To lst.Count - 1 \'指定每个数据点的位置 Series.X(i) = i \'指定水平坐标 Series.Y(i) = dt.Compute("Sum(总金额)","月份 = \'" & lst(i) & "\'") \'指定销售额垂直坐标
For p As Integer = 0 To lst1.count -1 Series.Y2(p) = dv1.Compute("Sum(总金额)","月份 = \'" & lst1(p) & "\'")‘指定采购额垂直坐标 Next Chart.AxisX.SetValueLabel(i, lst(i)&"月") \'指定字符表示 Next Chart.LegendVisible =True Series.DataLabelText = "{#YVAL}" Series.DataLabelText = "{#Y2VAL}" series.DataLabelCompass =LabelCompassEnum.NorthEast Chart.AxisX.AnnoWithLabels = True \'启用字符标示 Chart.AxisY.Text = "销售额" Chart.AxisY2.Text = "采购额"
[此贴子已经被作者于2013-5-20 23:09:19编辑过]
|
-- 作者:有点甜
-- 发布时间:2013/5/21 6:22:00
--
没有数据,怎么测试你的代码?
做个内部表或者access数据源的例子也可以啊
|
-- 作者:晕了快扶我
-- 发布时间:2013/5/21 11:34:00
--
例子
|
-- 作者:晕了快扶我
-- 发布时间:2013/5/21 12:34:00
--
顶
|
-- 作者:狐狸爸爸
-- 发布时间:2013/5/21 12:51:00
--
你只设置了一个图系的数据,当然只显示一个图。
Dim d1 As Date = Date.Today Dim y As Integer = d1.Year \'指定年份 Dim m As Integer = d1.Month Dim w As Integer = d1.DayOfWeek Dim q As Integer = (d1.Month - 1) \\ 3 + 1 \'计算现在是第几个季度 Dim dt1 As New Date(y, 1, 1) Dim dt2 As New Date(y, 12, 31) Dim cmd As New SQLCommand cmd.CommandText = "select * from {销售出库单主表}" Dim dt As DataTable = cmd.ExecuteReader Dim cmd1 As New SQLCommand cmd1.CommandText = "select * from {采购入库单主表}" Dim dv1 As DataTable = cmd1.ExecuteReader \'===============================取时间,动态加载出入表 Dim Chart As WinForm.Chart = e.Form.Controls("统计图表") Dim Series1 As WinForm.ChartSeries \'定义一个图系变量 Dim Series2 As WinForm.ChartSeries \'定义一个图系变量
Chart.VisualEffect = True Dim lst As List(Of String) = dt.GetUniqueValues("出库日期>= \'" & dt1 & "\'And 出库日期 <=\'" & dt2 & "\'", "月份") \'获得销售月份集合 Dim lst1 As List(Of String) = dv1.GetUniqueValues("到仓日期>= \'" & dt1 & "\'And 到仓日期 <=\'" & dt2 & "\'", "月份") \'获得采购月份集合 Chart.ChartType = ChartTypeEnum.Bar Chart.ChartType2 = ChartTypeEnum.XYPlot Chart.AxisX.ClearValueLabel Chart.AxisX.AnnoWithLabels = False Chart.SeriesList.Clear() \'清除图表原来的图系 Series1 = Chart.SeriesList.Add() \'增加一个图系 Series1.Text = "销售额" Chart.SeriesList2.Clear() \'清除图表2原来的图系 Series2 = Chart.SeriesList2.Add() \'给图表2增加一个图系 Series2.Text = "采购额" Series1.Length = lst.Count \'设置图系的长度 Series2.Length = lst.Count \'设置图系的长度 For i As Integer = 0 To lst.Count - 1 \'指定每个数据点的位置 Series1.X(i) = i \'指定水平坐标 Series2.X(i) = i \'指定水平坐标 Series1.Y(i) = dt.Compute("Sum(总金额)","月份 = \'" & lst(i) & "\'") \'指定销售额垂直坐标 For p As Integer = 0 To lst1.count -1 Series2.Y(p) = dv1.Compute("Sum(总金额)","月份 = \'" & lst1(p) & "\'")\'指定采购额垂直坐标 Next Chart.AxisX.SetValueLabel(i, lst(i)&"月") \'指定字符表示 Next Chart.LegendVisible =True Series1.DataLabelText = "{#YVAL}" Series1.DataLabelText = "{#Y2VAL}" Series2.DataLabelText = "{#YVAL}" Series2.DataLabelText = "{#Y2VAL}" series1.DataLabelCompass =LabelCompassEnum.NorthEast series2.DataLabelCompass =LabelCompassEnum.NorthEast Chart.AxisX.AnnoWithLabels = True \'启用字符标示 Chart.AxisY.Text = "销售额" Chart.AxisY2.Text = "采购额"
|
-- 作者:晕了快扶我
-- 发布时间:2013/5/21 13:21:00
--
狐爸,这样做出来总感觉怪怪的,如果共用一个X,Y轴,用BAR表示销售额,用XYPLOT表示采购额呢?
此主题相关图片如下:qq图片20130521132030.jpg
像教程里的双图表的第一种..
|
-- 作者:晕了快扶我
-- 发布时间:2013/5/21 13:25:00
--
此主题相关图片如下:qq图片20130521132441.jpg
现在作出来像这个样子的
|
-- 作者:晕了快扶我
-- 发布时间:2013/5/21 13:28:00
--
因为销售额的Y轴和采购额的Y轴差距不是很大,X轴又是共用的,示例里的是来自于同一张表,我就被搞晕了..
另外数值的显示怎么是乱码的?
|
-- 作者:狐狸爸爸
-- 发布时间:2013/5/21 14:19:00
--
你可以四舍五入:
Series1.Y(i) = math.Round(dt.Compute("Sum(总金额)","月份 = \'" & lst(i) & "\'") ,2)
|