Asp.net图表多系列数据显示错误。 [英] Asp.net chart multi-series showing wrong data

查看:155
本文介绍了Asp.net图表多系列数据显示错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在解决<一href="http://stackoverflow.com/questions/12808642/how-to-show-asp-net-chart-grouped-by-2-parameters">this用asp.net多系列图表问题的编程方式,我发现了另一种多系列图表另一个问题:

After solving this problem with asp.net multi-series chart programmatically, I found another problem in another multi-series chart:

我想显示月度销售报告,显示过去 M 月批准和否决提案的演变。有些个月,没有任何拒绝的建议,因此下面的查询(C#/ Oracle)的返回一些空的结果。

I want to show a monthly sales report, showing the evolution of the last m months in approved and rejected proposals. Some months, there aren't any rejected proposals, so the following query (C#/Oracle) returns some empty results.

select to_char(c.date,'YYYYMM') ctb_month, 
       c.approved,
       count(distinct c.f1) amt_c, 
       count(b.f1) amt_b, 
       sum(nvl(b.value,0)) sum_values
from bens b 
     join contracts c
     on b.contract_id = c.f1
where b.seller = :USR_ID 
AND c.date 
     BETWEEN add_months(:DATAI,:MONTHS) AND :DATAI
group by to_char(c.date,'YYYYMM'), c.approved
order by ctb_month

OBS:在绑定的:个月参数,我要确保它的值是负的。

OBS: Before binding the :MONTHS parameter, I make sure its value is negative.

的查询结果例:

CTB_MONTH APPROVED AMT_C AMT_B SUM_VALUES

201209    APPROVED    10    20    1234.56
201209    PENDING      3     3     120.21
201210    APPROVED    12    18     850.52
201210    PENDING      4     4     158.71
201210    REJECTED     1     1      80.40

注意:在这种情况下,没有发现在201209任何拒绝建议当前卖方

NOTE: in this case, there weren't any rejected proposal in 201209 for the current seller.

$ C $三来一补图表:

Code to fill the chart:

我存储在由较低层传递的数据在一个变种报告和它的状态批准过滤数据

I stored the data passed by the lower layers in a var report and filtered the data by it's APPROVED status:

var approved = queryResult
              .Where(r => r.APPROVED == "APPROVED")
              .ToList()
              ;
var rejected = queryResult
              .Where(r => r.APPROVED == "REJECTED")
              .ToList()
              ;
var pending =  queryResult
              .Where(r => r.APPROVED == "PENDING")
              .ToList()
              ;

然后,我创建了一系列的循环

Then, I'm creating the series in a loop

for (int i = 0; i < 6; i++) {
    Series temp = new Series {
        XAxisType = AxisType.Primary,
        XValueType = ChartValueType.DateTime,
        YAxisType = AxisType.Primary,
        //mostra só a quantidade de contratos
        IsValueShownAsLabel = i % 2 == 0 ? true : false,
        ChartType = SeriesChartType.Column,
        CustomProperties = "EmptyPointValue=Zero",
        Legend = "Legenda"
    };
    grafico.Series.Add(temp);
}

和数据绑定的每一个系列的手

And DataBinding each series by hand

// approved contracts
grafico.Series[0].Points.DataBindXY(approved, "MONTH", approved, "AMT_C");
grafico.Series[0].LegendText = "Cont. approved";
// approved bens
grafico.Series[1].Points.DataBindXY(approved, "MONTH", approved, "AMT_B");
grafico.Series[1].LegendText = "Ben. approved";
grafico.Series[1].ChartType = SeriesChartType.Line;
// pending contracts
grafico.Series[2].Points.DataBindXY(pending, "MONTH", pending, "AMT_C");
grafico.Series[2].LegendText = "Cont. pending";
// pending bens
grafico.Series[3].Points.DataBindXY(pending, "MONTH", pending, "AMT_B");
grafico.Series[3].LegendText = "Ben. pending";
grafico.Series[3].ChartType = SeriesChartType.Line;
// rejected contracts
grafico.Series[4].Points.DataBindXY(rejected, "MONTH", rejected, "AMT_C");
grafico.Series[4].LegendText = "Cont. rejected";
// rejected bens
grafico.Series[5].Points.DataBindXY(rejected, "MONTH", rejected, "AMT_B");
grafico.Series[5].LegendText = "Ben. rejected";
grafico.Series[5].ChartType = SeriesChartType.Line;

注:画报是我的图表对象;对一些可视化的设置中定义的&LT; ASP:图表&GT; 标记

NOTES: grafico is my Chart object; Some of the visual settings are defined in the <asp:Chart> tag.

当我运行的应用程序,完整的系列绘制正确,但不完整的系列(201209 /拒绝,在上面的例子中)被画在错误的 X 坐标(为201210的值被绘制在列201209,在这种情况下),因为如果控制被忽略了 DataBindXY通过 X 方法和顺序绘制值。

When I run the app, the complete series are correctly drawn, but the incomplete series (201209 / REJECTED, in the above example) is drawn in the wrong X coordinates (the values for 201210 are draw in the column for 201209, in this case), as if the control were ignoring the X values passed in the DataBindXY method and drawing the values in sequence.

是否有人知道如何解决这个问题? 先谢谢了。

Does somebody know how to fix this issue? Thanks in advance.

[求助]由于@jbl,图表绘制现在在正确的位置的值。

在code:

var allMonths = queryResult
    .Select(x => x.MONTH)
    .Distinct()
    .OrderBy(mes => mes)
    ;

foreach (var mes in allMonths) {

    bool hasData = rejected.Any(r => r.MONTH == mes);
    if (hasData == false) {
        rejected.Add(new MonthlyData() { MONTH = mes, APPROVED = "REJECTED" });
    }
    hasData = pending.Any(r => r.MONTH == mes);
    if (hasData == false) {
        pending.Add(new MonthlyData() { MONTH = mes, APPROVED = "PENDING" });
    }
    hasData = approved.Any(r => r.MONTH == mes);
    if (hasData == false) {
        approved.Add(new MonthlyData() { MONTH = mes, APPROVED = "APPROVED" });
    }
}
approved = approved.OrderBy(v => v.MONTH).ToList();
pending = pending.OrderBy(v => v.MONTH).ToList();
rejected = rejected.OrderBy(v => v.MONTH).ToList();

grafico.ChartAreas[0].AxisX.Interval = 1;
grafico.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Months;
grafico.ChartAreas[0].AxisX.IntervalOffset = 1;
grafico.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Months;

注意:的MonthlyData是输送值在查询结果中每行一个简单的类

Note: MonthlyData is a simple class that transports the values for every line in the query result.

推荐答案

我想你将不得不使用空数据点的 http://msdn.microsoft.com/en-us/library/dd456677.aspx 调整所有的系列

I guess you will have to use Empty Data Points http://msdn.microsoft.com/en-us/library/dd456677.aspx to align all your series

这意味着:

  • 在建的所有的x值的集合中的一系列
  • 在做这一切的x值左连接与您的系列检测所有失分
  • 填补缺失的点空数据点

希望这将有助于

编辑:你可以尝试(未测试)像这样的批准/ AMT_C意甲

edit : you can try (not tested) something like this for the approved/AMT_C serie

var allXvalues = queryResult.select(r=>r.CTB_MONTH).Distinct().OrderBy(month=>month).ToList();


allXvalues
  .ForEach
   (
    xvalue=>
      {
        var p = approved.Where(o=>o.MONTH==xValue).FirstOrDefault();
        if(p==null)
            grafico.Series[0].Points.Add(new DataPoint(p.MONTH,p.AMT_C));
        else
            grafico.Series[0].Points.Add(new DataPoint(xvalue,0){IsEmpty=true});
      }
   );

这篇关于Asp.net图表多系列数据显示错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆