求大神帮忙看一下chart为什么显示不出来?

狼二羊 2016-08-25 11:22:11
难道是因为datagridview里面有空值么?别的表没有空值所以能显示那我该怎么把?是在datagridview附上0还是怎么办?
...全文
571 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
巴士上的邂逅 2016-08-25
  • 打赏
  • 举报
回复
上代码上代码
gtclulong 2016-08-25
  • 打赏
  • 举报
回复
要保留几位小数看着改就行 其实你都已经用了case when了,再用一次就行了 我C#、数据库也是初学,标准的T1大神
gtclulong 2016-08-25
  • 打赏
  • 举报
回复

select idinventoryclass = case AA_Inventory.idinventoryclass
          when '46788662-AFB2-4C84-84F7-A50E00F9B74E' then
           '镜片'
          when '378C3E42-DEDA-4A5B-A324-A50E00FF1D3E' then
           '镜架'
          when 'C48B0657-3372-4ED0-A4F1-A50E00FA36ED' then
           '花镜'
          else
           '其它'
        end, 
        abc= case when sum(RE_Retail_b.quantity) is null then 0           
                  else round(sum(RE_Retail_b.quantity),2)           
                  end,
        dsf= case when sum(RE_Retail_b.retailamount) is null then 0
                  else round(sum(RE_Retail_b.retailamount),2)
                  end
  from RE_Retail_b
  left join AA_Inventory on RE_Retail_b.idinventory = AA_Inventory.id
 where (idinventoryclass = '46788662-AFB2-4C84-84F7-A50E00F9B74E' or
       idinventoryclass = '378C3E42-DEDA-4A5B-A324-A50E00FF1D3E' or
       idinventoryclass = 'C48B0657-3372-4ED0-A4F1-A50E00FA36ED' or
       idinventoryclass = '85EB34A4-6949-4AB7-B8B0-A50E00FA3F97')
 group by AA_Inventory.idinventoryclass
试试吧
引用 5 楼 qq_30519247 的回复:
[quote=引用 2 楼 gtclulong 的回复:] 数量是0的数据如果没有需求的话,直接在数据源中的Sql中使用where条件过滤掉 如果确实有需要,那就在Sql中使用decode/case之类的语句把它改写成0 还有你的数字小数点后搞那么多零看着不晕吗?在Sql中完全可以用round保留需要的小数位数 总之,还是改改Sql吧
数据0的必须要有,然后小数点后面没用的0怎么去掉..[/quote]
巴士上的邂逅 2016-08-25
  • 打赏
  • 举报
回复
double可以为""?
qq_34361392 2016-08-25
  • 打赏
  • 举报
回复
引用 8 楼 yuankaiwsl 的回复:
不会吧,为什么不报错呢?
如果是空的会转成""亲测
巴士上的邂逅 2016-08-25
  • 打赏
  • 举报
回复
把Convert.ToDouble(ds.Tables[0].Rows[i]["dsf"].ToString())给一个变量,然后xData.Add变量,加断点看看变量的值
狼二羊 2016-08-25
  • 打赏
  • 举报
回复
引用 8 楼 yuankaiwsl 的回复:
不会吧,为什么不报错呢?
我也不知道啊,,,所以说怎么办
巴士上的邂逅 2016-08-25
  • 打赏
  • 举报
回复
不会吧,为什么不报错呢?
狼二羊 2016-08-25
  • 打赏
  • 举报
回复
引用 6 楼 yuankaiwsl 的回复:
yData.Add(Convert.ToDouble(ds.Tables[0].Rows[i]["dsf"].ToString()));处不会报错吗? 值有空的转换不报错吗?
还真没报错...
巴士上的邂逅 2016-08-25
  • 打赏
  • 举报
回复
yData.Add(Convert.ToDouble(ds.Tables[0].Rows[i]["dsf"].ToString()));处不会报错吗? 值有空的转换不报错吗?
狼二羊 2016-08-25
  • 打赏
  • 举报
回复
引用 2 楼 gtclulong 的回复:
数量是0的数据如果没有需求的话,直接在数据源中的Sql中使用where条件过滤掉 如果确实有需要,那就在Sql中使用decode/case之类的语句把它改写成0 还有你的数字小数点后搞那么多零看着不晕吗?在Sql中完全可以用round保留需要的小数位数 总之,还是改改Sql吧
数据0的必须要有,然后小数点后面没用的0怎么去掉..
狼二羊 2016-08-25
  • 打赏
  • 举报
回复
引用 2 楼 gtclulong 的回复:
数量是0的数据如果没有需求的话,直接在数据源中的Sql中使用where条件过滤掉 如果确实有需要,那就在Sql中使用decode/case之类的语句把它改写成0 还有你的数字小数点后搞那么多零看着不晕吗?在Sql中完全可以用round保留需要的小数位数 总之,还是改改Sql吧
大神,我对sql其实不怎么熟练,我给你看看代码你能帮我改改这个0的问题么.....
private void Form4_Load(object sender, EventArgs e)
        {   
            sql = "select idinventoryclass = case AA_Inventory.idinventoryclass when '46788662-AFB2-4C84-84F7-A50E00F9B74E' then '镜片' when '378C3E42-DEDA-4A5B-A324-A50E00FF1D3E' then '镜架' when 'C48B0657-3372-4ED0-A4F1-A50E00FA36ED' then '花镜' else '其它' end,SUM(RE_Retail_b.quantity)as abc,SUM(RE_Retail_b.retailamount) as dsf from RE_Retail_b left join AA_Inventory on RE_Retail_b.idinventory = AA_Inventory.id  where (idinventoryclass = '46788662-AFB2-4C84-84F7-A50E00F9B74E'or idinventoryclass ='378C3E42-DEDA-4A5B-A324-A50E00FF1D3E'or idinventoryclass = 'C48B0657-3372-4ED0-A4F1-A50E00FA36ED' or idinventoryclass = '85EB34A4-6949-4AB7-B8B0-A50E00FA3F97') group by AA_Inventory.idinventoryclass";
            DataSet ds = DBHelper.getset(sql);
            this.dataGridView1.DataSource = ds.Tables[0];
            List<string> xData = new List<string>() { };
            List<double> yData = new List<double>() { };

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                xData.Add(ds.Tables[0].Rows[i]["idinventoryclass"].ToString());
                yData.Add(Convert.ToDouble(ds.Tables[0].Rows[i]["dsf"].ToString()));
            }

            chart1.Series[0]["PieLabelStyle"] = "Outside";
            chart1.Series[0]["PieLineColor"] = "Black";
            chart1.Series[0].Points.DataBindXY(xData, yData);
        }
狼二羊 2016-08-25
  • 打赏
  • 举报
回复
引用 1 楼 yuankaiwsl 的回复:
上代码上代码
private void Form4_Load(object sender, EventArgs e)
        {   
            sql = "select idinventoryclass = case AA_Inventory.idinventoryclass when '46788662-AFB2-4C84-84F7-A50E00F9B74E' then '镜片' when '378C3E42-DEDA-4A5B-A324-A50E00FF1D3E' then '镜架' when 'C48B0657-3372-4ED0-A4F1-A50E00FA36ED' then '花镜' else '其它' end,SUM(RE_Retail_b.quantity)as abc,SUM(RE_Retail_b.retailamount) as dsf from RE_Retail_b left join AA_Inventory on RE_Retail_b.idinventory = AA_Inventory.id  where (idinventoryclass = '46788662-AFB2-4C84-84F7-A50E00F9B74E'or idinventoryclass ='378C3E42-DEDA-4A5B-A324-A50E00FF1D3E'or idinventoryclass = 'C48B0657-3372-4ED0-A4F1-A50E00FA36ED' or idinventoryclass = '85EB34A4-6949-4AB7-B8B0-A50E00FA3F97') group by AA_Inventory.idinventoryclass";
            DataSet ds = DBHelper.getset(sql);
            this.dataGridView1.DataSource = ds.Tables[0];
            List<string> xData = new List<string>() { };
            List<double> yData = new List<double>() { };

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                xData.Add(ds.Tables[0].Rows[i]["idinventoryclass"].ToString());
                yData.Add(Convert.ToDouble(ds.Tables[0].Rows[i]["dsf"].ToString()));
            }

            chart1.Series[0]["PieLabelStyle"] = "Outside";
            chart1.Series[0]["PieLineColor"] = "Black";
            chart1.Series[0].Points.DataBindXY(xData, yData);
        }
gtclulong 2016-08-25
  • 打赏
  • 举报
回复
数量是0的数据如果没有需求的话,直接在数据源中的Sql中使用where条件过滤掉 如果确实有需要,那就在Sql中使用decode/case之类的语句把它改写成0 还有你的数字小数点后搞那么多零看着不晕吗?在Sql中完全可以用round保留需要的小数位数 总之,还是改改Sql吧

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧