以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  关于图表多视图,百分比显示为0%的困惑~求助  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=49836)

--  作者:wealthwind
--  发布时间:2014/4/24 18:21:00
--  关于图表多视图,百分比显示为0%的困惑~求助

按钮代码如下,是哪里设置错误了,显示一直是0%,没有显示真实达成率

 

生成图表按钮是:

 

Dim Cmd As new SQLCommand
Cmd.C
Cmd.CommandText = "select distinct 分区,年,月份,目标 from 目标 where " & CustomFilter
Dim dt1 As DataTable = Cmd.ExecuteReader
Dim dtb As New DataTableBuilder("统计")
dtb.AddDef("分区", Gettype(String), 50)
Dim prds As List(of String()) = dt1.GetUniqueValues("","年","月份")
Dim exp As String
Dim prd As String()
dtb.AddDef("目标总额", Gettype(Double))
dtb.AddDef("销售总额", Gettype(Double))
dtb.AddDef("达成率", Gettype(Double),"[销售总额]/[目标总额]")
For Each prd In prds
    dtb.AddDef(prd(0) & "_" & prd(1) & "_目标", Gettype(Double))
    dtb.AddDef(prd(0) & "_" & prd(1) & "_销售", Gettype(Double))
    exp = String.format("[{0}]/[{1}]",prd(0) & "_" & prd(1) & "_销售" ,prd(0) & "_" & prd(1) & "_目标" )
    dtb.AddDef(prd(0) & "_" & prd(1) & "_达成率", Gettype(Double),exp)
Next
dtb.Build()
Cmd.CommandText = "select 分区,year(日期) as 年,month(日期) as 月份,sum(金额) as 销售 from 订单 where " & CustomFilter & " group by 分区,year(日期),month(日期)"
Dim dt2 As DataTable = Cmd.ExecuteReader
Dim dr As DataRow
For Each cus As String In dt1.GetUniqueValues("","分区")
    dr = DataTables("统计").AddNew()
    dr("分区") = cus
    For Each prd In prds
        dr(prd(0) & "_" & prd(1) & "_目标") = dt1.Compute("Sum(目标)","分区 = \'" & cus & "\' And [年] = \'" & prd(0) & "\' and 月份 = \'"& prd(1) &"\'")
        dr(prd(0) & "_" & prd(1) & "_销售") = dt2.Compute("Sum(销售)","分区 = \'" & cus & "\' And [年] = \'" & prd(0) & "\' and 月份 = \'"& prd(1) &"\'")
    Next
    dr("目标总额") = dt1.Compute("Sum(目标)","分区 = \'" & cus & "\'")
    dr("销售总额") = dt2.Compute("Sum(销售)","分区 = \'" & cus & "\'")
Next
\'********************************
Dim nr As Row = Tables("统计").AddNew
nr(0) = "合计"
For Each c As Col In Tables("统计").Cols
    If c.IsNumeric AndAlso c.DataCol.Expression = "" Then
        nr(c.name) = Tables("统计").Compute("sum([" & c.Name & "])", Tables("统计").Cols(0).Name & " <> \'合计\'")
    MainTable = Tables("统计")
    For Each prd In prds
    DataTables("统计").DataCols(prd(0) & "_" & prd(1) & "_达成率").SetFormat("0.00%")
Next
DataTables("统计").DataCols("达成率").SetFormat("0.00%")

    End If
Next
Dim Chart As WinForm.Chart \'定义一个图表变量
Dim Series As WinForm.ChartSeries \'定义一个图系变量
Dim t As Table = Tables("统计") \'定义一个变量t引用数据表
Chart= e.Form.Controls("Chart1") \' 引用窗口中的图表
Chart.ChartType = ChartTypeEnum.Bar \'图表类型改为Bar(条形)
Chart.SeriesList.Clear() \'清除图表原来的图系
Series = Chart.SeriesList.Add() \'增加一个图系
Series.Length = (t.Cols.Count-3) / 3 \'图系的数据点数等于表的行数
Dim Series1 As WinForm.ChartSeries = Chart.SeriesList.Add()
Series1.Length = (t.Cols.Count-3) / 3 \'图系的数据点数等于表的行数
Dim Series2 As WinForm.ChartSeries = Chart.SeriesList2.Add() \'给图表2增加一个图系
Series2.Length = (t.Cols.Count-3) / 3 \'图系的数据点数等于表的行数
Chart.ChartType2 = ChartTypeEnum.XYPlot
Series.Text = "目标"
Series1.Text = "销售"
Series2.Text = "达成率"
Dim i As Integer = 0
For Each c As Col In Tables("统计").Cols
    If c.Name.EndsWith("目标") Then
        Series.X(i) = i \'指定水平坐标
        Series1.X(i) = i \'指定水平坐标
        Series2.X(i) = i \'指定水平坐标
        Series.Y(i) = nr(c.Name) \'指定垂直坐标
        Series1.Y(i) = nr(Tables("统计").Cols(c.Index+1).Name) \'指定垂直坐标
        Series2.Y(i) = nr(Tables("统计").Cols(c.Index+2).Name) \'指定垂直坐标
        Series2.DataLabelText =nr(Tables("统计").Cols(c.Index+2).Name) & "%"
        Chart.AxisX.SetValueLabel(i, c.Name.Split("_")(1)) \'指定字符表示
                i+=1
    End If
Next

Chart.AxisX.AnnoWithLabels = True \'启用字符标示
Chart.LegendVisible = True \'显示图列
Chart.LegendCompass= CompassEnum.South \'图列显示在南方(底端)
Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮
Chart.AxisY.Text = "金额"
Chart.AxisY2.Text = "比例"
Series.DataLabelText = "{#YVAL}"
Series1.DataLabelText = "{#YVAL}"
Series1.DataLabelBackColor = Color.Blue \'蓝底
Series1.DataLabelForeColor = Color.White \'白字
Series.DataLabelBackColor = Color.red \'红底
Series.DataLabelForeColor = Color.White \'白字
Series2.DataLabelBackColor = Color.green \'绿底
Series2.DataLabelForeColor = Color.White \'白字


图片点击可在新窗口打开查看此主题相关图片如下:360截图20140424182008656.jpg
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:360截图20140424182014562.jpg
图片点击可在新窗口打开查看

--  作者:有点甜
--  发布时间:2014/4/24 19:10:00
--  

 这句代码不能这样,只能这样写

 

Series2.DataLabelText ="{#YVAL}"


--  作者:wealthwind
--  发布时间:2014/4/24 19:45:00
--  
老师,你的回答,我没看懂啊???
--  作者:有点甜
--  发布时间:2014/4/24 19:46:00
--  
以下是引用wealthwind在2014-4-24 19:45:00的发言:
老师,你的回答,我没看懂啊???

 

意思全部只能这样写,无法加上百分号,也无法特殊处理。

 

Series.DataLabelText = "{#YVAL}"
Series1.DataLabelText = "{#YVAL}"

Series2.DataLabelText ="{#YVAL}"


--  作者:有点甜
--  发布时间:2014/4/24 19:48:00
--  

 百分号是肯定显示不了的,你可以把值乘以100来显示

 

 Series2.Y(i) = nr(Tables("统计").Cols(c.Index+2).Name) * 100 \'指定垂直坐标


--  作者:wealthwind
--  发布时间:2014/4/24 20:08:00
--  
老师,显示数值都不行啊,那段代码
--  作者:有点甜
--  发布时间:2014/4/24 20:23:00
--  

 看4楼,写代码,不解释


--  作者:wealthwind
--  发布时间:2014/4/24 21:49:00
--  
老师,帮我改一下,我试了几次不成功

Dim Cmd As new SQLCommand
Cmd.C
Cmd.CommandText = "select distinct 分区,年,月份,目标 from 目标 where " & CustomFilter
Dim dt1 As DataTable = Cmd.ExecuteReader
Dim dtb As New DataTableBuilder("统计")
dtb.AddDef("分区", Gettype(String), 50)
Dim prds As List(of String()) = dt1.GetUniqueValues("","年","月份")
Dim exp As String
Dim prd As String()
dtb.AddDef("目标总额", Gettype(Double))
dtb.AddDef("销售总额", Gettype(Double))
dtb.AddDef("达成率", Gettype(Double),"[销售总额]/[目标总额]")
For Each prd In prds
    dtb.AddDef(prd(0) & "_" & prd(1) & "_目标", Gettype(Double))
    dtb.AddDef(prd(0) & "_" & prd(1) & "_销售", Gettype(Double))
    exp = String.format("[{0}]/[{1}]",prd(0) & "_" & prd(1) & "_销售" ,prd(0) & "_" & prd(1) & "_目标" )
    dtb.AddDef(prd(0) & "_" & prd(1) & "_达成率", Gettype(Double),exp)
Next
dtb.Build()
Cmd.CommandText = "select 分区,year(日期) as 年,month(日期) as 月份,sum(金额) as 销售 from 订单 where " & CustomFilter & " group by 分区,year(日期),month(日期)"
Dim dt2 As DataTable = Cmd.ExecuteReader
Dim dr As DataRow
For Each cus As String In dt1.GetUniqueValues("","分区")
    dr = DataTables("统计").AddNew()
    dr("分区") = cus
    For Each prd In prds
        dr(prd(0) & "_" & prd(1) & "_目标") = dt1.Compute("Sum(目标)","分区 = \'" & cus & "\' And [年] = \'" & prd(0) & "\' and 月份 = \'"& prd(1) &"\'")
        dr(prd(0) & "_" & prd(1) & "_销售") = dt2.Compute("Sum(销售)","分区 = \'" & cus & "\' And [年] = \'" & prd(0) & "\' and 月份 = \'"& prd(1) &"\'")
    Next
    dr("目标总额") = dt1.Compute("Sum(目标)","分区 = \'" & cus & "\'")
    dr("销售总额") = dt2.Compute("Sum(销售)","分区 = \'" & cus & "\'")
Next
\'********************************
Dim nr As Row = Tables("统计").AddNew
nr(0) = "合计"
For Each c As Col In Tables("统计").Cols
    If c.IsNumeric AndAlso c.DataCol.Expression = "" Then
        nr(c.name) = Tables("统计").Compute("sum([" & c.Name & "])", Tables("统计").Cols(0).Name & " <> \'合计\'")
    MainTable = Tables("统计")
    For Each prd In prds
    DataTables("统计").DataCols(prd(0) & "_" & prd(1) & "_达成率").SetFormat("0.00%")
Next
DataTables("统计").DataCols("达成率").SetFormat("0.00%")

    End If
Next
Dim Chart As WinForm.Chart \'定义一个图表变量
Dim Series As WinForm.ChartSeries \'定义一个图系变量
Dim t As Table = Tables("统计") \'定义一个变量t引用数据表
Chart= e.Form.Controls("Chart1") \' 引用窗口中的图表
Chart.ChartType = ChartTypeEnum.Bar \'图表类型改为Bar(条形)
Chart.SeriesList.Clear() \'清除图表原来的图系
Series = Chart.SeriesList.Add() \'增加一个图系
Series.Length = (t.Cols.Count-3) / 3 \'图系的数据点数等于表的行数
Dim Series1 As WinForm.ChartSeries = Chart.SeriesList.Add()
Series1.Length = (t.Cols.Count-3) / 3 \'图系的数据点数等于表的行数
Dim Series2 As WinForm.ChartSeries = Chart.SeriesList2.Add() \'给图表2增加一个图系
Series2.Length = (t.Cols.Count-3) / 3 \'图系的数据点数等于表的行数
Chart.ChartType2 = ChartTypeEnum.XYPlot
Series.Text = "目标"
Series1.Text = "销售"
Series2.Text = "达成率"
Dim i As Integer = 0
For Each c As Col In Tables("统计").Cols
    If c.Name.EndsWith("目标") Then
        Series.X(i) = i \'指定水平坐标
        Series1.X(i) = i \'指定水平坐标
        Series2.X(i) = i \'指定水平坐标
        Series.Y(i) = nr(c.Name) \'指定垂直坐标
        Series1.Y(i) = nr(Tables("统计").Cols(c.Index+1).Name) \'指定垂直坐标
        Series2.Y(i) = nr(Tables("统计").Cols(c.Index+2).Name) \'指定垂直坐标
        Series2.DataLabelText =nr(Tables("统计").Cols(c.Index+2).Name)  & "%"
        Chart.AxisX.SetValueLabel(i, c.Name.Split("_")(1)) \'指定字符表示
                i+=1
    End If
Next
Chart.AxisX.AnnoWithLabels = True \'启用字符标示
Chart.LegendVisible = True \'显示图列
Chart.LegendCompass= CompassEnum.South \'图列显示在南方(底端)
Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮
Chart.AxisY.Text = "金额"
Chart.AxisY2.Text = "比例"
Series.DataLabelText = "{#YVAL}"
Series1.DataLabelText = "{#YVAL}"
Series1.DataLabelBackColor = Color.Blue \'蓝底
Series1.DataLabelForeColor = Color.White \'白字
Series.DataLabelBackColor = Color.red \'红底
Series.DataLabelForeColor = Color.White \'白字
Series2.DataLabelBackColor = Color.green \'绿底
Series2.DataLabelForeColor = Color.White \'白字

--  作者:有点甜
--  发布时间:2014/4/24 21:55:00
--  

这一段改一下。楼主!

 

For Each c As Col In Tables("统计").Cols
    If c.Name.EndsWith("目标") Then
        Series.X(i) = i \'指定水平坐标
        Series1.X(i) = i \'指定水平坐标
        Series2.X(i) = i \'指定水平坐标
        Series.Y(i) = nr(c.Name) \'指定垂直坐标
        Series1.Y(i) = nr(Tables("统计").Cols(c.Index+1).Name) \'指定垂直坐标
        Series2.Y(i) = nr(Tables("统计").Cols(c.Index+2).Name) * 100 \'指定垂直坐标
 
        Chart.AxisX.SetValueLabel(i, c.Name.Split("_")(1)) \'指定字符表示
                i+=1
    End If
Next
Chart.AxisX.AnnoWithLabels = True \'启用字符标示
Chart.LegendVisible = True \'显示图列
Chart.LegendCompass= CompassEnum.South \'图列显示在南方(底端)
Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮
Chart.AxisY.Text = "金额"
Chart.AxisY2.Text = "比例"
Series.DataLabelText = "{#YVAL}"
Series1.DataLabelText = "{#YVAL}"
Series2.DataLabelText = "{#YVAL}"
Series1.DataLabelBackColor = Color.Blue \'蓝底
Series1.DataLabelForeColor = Color.White \'白字
Series.DataLabelBackColor = Color.red \'红底
Series.DataLabelForeColor = Color.White \'白字
Series2.DataLabelBackColor = Color.green \'绿底
Series2.DataLabelForeColor = Color.White \'白字

--  作者:wealthwind
--  发布时间:2014/4/24 22:04:00
--  
可以了,谢谢老师
图片点击可在新窗口打开查看此主题相关图片如下:360截图20140424220355909.jpg
图片点击可在新窗口打开查看