如何获得以下格式? [英] How to get Below Format?

查看:86
本文介绍了如何获得以下格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



实际上我正在比较条形图中待处理的V / s发货订单,但是条形图中的值不匹配指数值的原因是不匹配。



所以如果我通过最终结果值(下面的例子)它将完美地工作。



如何获得最终结果值。我试过但是订单不正确。没有硬编码..



任何想法/建议?




见下例:







Hi all,

Actually I am Comparing Pending V/s Shipped Orders in Bar Charts fine, But The Values are Mismatching in Bar Chart reason of Index Values are Mismatching.

So If I pass Final Result Value (example of below) it will work Perfectly.

How Can I get Final Result Value. I have tried but it's not correct order. Without hard code..

Any Idea/Suggestions?


See Below Example:



var Shipped_List = new List<string>();
var Pending_List = new List<string>();
var Shipped_List_Count = new List<int>()
var Pending_List_Count = new List<int>()

// Actual Data

Shipped_List.Add("Fedex");
Shipped_List.Add("UPS");
Shipped_List.Add("ABF");
Shipped_List.Add("ACE");
Shipped_List.Add("BAX");
Shipped_List.Add("DHL");
Shipped_List.Add("FEDEXFRT");
Shipped_List.Add("JEVIC");
Shipped_List.Add("R&L");
Shipped_List.Add("ROADWAY");
Shipped_List.Add("SUTTON");
Shipped_List.Add("YELLOW");

Shipped_List_Count.Add(234);
Shipped_List_Count.Add(32);
Shipped_List_Count.Add(3);
Shipped_List_Count.Add(2);
Shipped_List_Count.Add(1);
Shipped_List_Count.Add(34);
Shipped_List_Count.Add(5);
Shipped_List_Count.Add(1);
Shipped_List_Count.Add(1);
Shipped_List_Count.Add(8);
Shipped_List_Count.Add(1);
Shipped_List_Count.Add(2);

Pending_List.Add("R&L");
Pending_List.Add("UPS");
Pending_List.Add("YRC");
Pending_List.Add("CSX");






Pending_List_Count.Add(55);
Pending_List_Count.Add(3);
Pending_List_Count.Add(2);
Pending_List_Count.Add(20);







//最终结果像这样






//Final Result Like this

//Final Result Like this

Shipped_List.Add("Fedex");
Shipped_List.Add("UPS");
Shipped_List.Add("ABF");
Shipped_List.Add("ACE");
Shipped_List.Add("BAX");
Shipped_List.Add("DHL");
Shipped_List.Add("FEDEXFRT");
Shipped_List.Add("JEVIC");
Shipped_List.Add("R&L");
Shipped_List.Add("ROADWAY");
Shipped_List.Add("SUTTON");
Shipped_List.Add("YELLOW");
Shipped_List.Add("SUTTON");
Shipped_List.Add("YELLOW");
Shipped_List.Add("YRC");
Shipped_List.Add("CSX");

Shipped_List_Count.Add(234);
Shipped_List_Count.Add(32);
Shipped_List_Count.Add(3);
Shipped_List_Count.Add(2);
Shipped_List_Count.Add(1);
Shipped_List_Count.Add(34);
Shipped_List_Count.Add(5);
Shipped_List_Count.Add(1);
Shipped_List_Count.Add(1);
Shipped_List_Count.Add(8);
Shipped_List_Count.Add(1);
Shipped_List_Count.Add(2);
Shipped_List_Count.Add(0);
Shipped_List_Count.Add(0);

Pending_List.Add("Fedex");
Pending_List.Add("UPS");
Pending_List.Add("ABF");
Pending_List.Add("ACE");
Pending_List.Add("BAX");
Pending_List.Add("DHL");
Pending_List.Add("FEDEXFRT");
Pending_List.Add("JEVIC");
Pending_List.Add("R&L");
Pending_List.Add("ROADWAY");
Pending_List.Add("SUTTON");
Pending_List.Add("YELLOW");
Pending_List.Add("SUTTON");
Pending_List.Add("YELLOW");
Pending_List.Add("YRC");
Pending_List.Add("CSX");

Pending_List_Count.Add(0);
Pending_List_Count.Add(3);
Pending_List_Count.Add(0);
Pending_List_Count.Add(0);
Pending_List_Count.Add(0);
Pending_List_Count.Add(0);
Pending_List_Count.Add(55);
Pending_List_Count.Add(0);
Pending_List_Count.Add(0);
Pending_List_Count.Add(0);
Pending_List_Count.Add(0);
Pending_List_Count.Add(0);
Pending_List_Count.Add(2);
Pending_List_Count.Add(20);





谢谢提前。



Thanks in Advance.

推荐答案

继续解决方案1和评论。



1.你被殴打关于这个硬编码数据的一点点 - 我将慷慨地假设它只是一种快速的方法来敲除一些测试数据来证明你的问题。所以有一些建议 - 把它放在存储库层的方法中,称之为FetchShippingItems和FetchPendingItems,并在那里有一个// TODO注释,里面写着现在的硬编码测试数据



2.解决方案1中的_Asif_暗示了你的真正问题 - 你没有把两位数据捆绑在一起。不幸的是,大部分解决方案都是处理你有硬编码数据的事实 - 但是你可以在你的存储库层中使用它。



3.关键点_Asif_提到的是 Class Dictionary KeyValuePair



首先上课 - 这可以包含您需要了解的有关装运物品的所有信息以及构建一个的方法,例如(故意轻量级的例子)
Further to solution 1 and the comments.

1. You've been beaten up a bit about this hard coded data - I'm going to generously assume that it's just a quick way of knocking up some test data to demonstrate your problem. So some advice - tuck that away in methods in a repository layer, call them something like FetchShippingItems and FetchPendingItems and have a //TODO comment in there that says something like "Hard-coded test data for now"

2. _Asif_ in Solution 1 has alluded to your real problem - you are not "tying together" the two bits of data. Unfortunately most of that solution is dealing with the fact you had hard-coded data - but you could use that within your repository layer.

3. The key points that _Asif_ has mentioned are Class, Dictionary and KeyValuePair

Taking the Class first - this could hold everything you need to know about a Shipping item and a way to construct one e.g.(deliberately light-weight example)
class ShippingItem
{
    public string Carrier { get; set; }
    public int Shipped { get; set; }
    public int Pending { get; set; }
    // ... other things to do with shipping items e.g. weight, size etc

    public ShippingItem(string carrier, int shipped, int pending)
    {
        Carrier = carrier;
        Shipped = shipped;
        Pending = pending;
    }
}



您的存储库可以使用该类的实例填充集合,例如


and your repository could populate a collection with instances of that class e.g.

var Shipping = new List<shippingitem>();
Shipping.Add(new ShippingItem("Fedex", 234, 0));
//etc</shippingitem>





但是你要潜入每个项目来计算出货的数量和未决的数量 - 这可能不是最好的你的条形图的想法,你也可能最终携带有关运送物品的所有额外信息,当你真正想知道的是有多少运费和有多少待定。


那么使用KeyValuePair怎么样?这些列表将完全符合您的需要 - 将名称和数字紧密地保在一起。



例如(并且仍使用您的硬编码测试数据)存储库方法 FetchShippingItems 可以返回KeyValuePair的List ...



But you are then going to have dive into each item to work out the number that are being shipped and the number that are pending - which probably isn't the best idea for your bar chart, and you may also end up carrying around all that extra information about shipping items when really all you want to know is how many are shipping and how many are pending.

So how about using KeyValuePair? A list of these will do exactly what you need - keep a name and a number tightly together.

For example (and still using your hard-coded test data) that repository method FetchShippingItems could return a List of KeyValuePair ...

var Shipping_List = new List<KeyValuePair<string, int>>();
Shipping_List.Add(new KeyValuePair<string,int>("Fedex",234));
Shipping_List.Add(new KeyValuePair<string,int>("UPS",32));
//etc
var Pending_List = new List<keyvaluepair><string,>>();
Pending_List.Add(new KeyValuePair<string,>("R&L", 2));
Pending_List.Add(new KeyValuePair<string,int>("UPS",2));
//etc</keyvaluepair>



字典的工作方式相同...


A Dictionary would work the same way ...

var Shipping_List = new Dictionary<string, int>();
Shipping_List.Add("Fedex", 234);
//etc





真正的关键点可以带走所有这些...



A)使用两个(或更多)列表(或数组) ,或任何集合)保存有关同一事物的信息很少(如果有的话)是一个好主意。对于事情来说太容易了,如果你想要另一条信息,你必须引入一个全新的List(或数组或集合)

让你对组合事物的方式感到满意 - 何时是合适的课程或仅仅是KeyValuePair或组合等等。



B)了解可用的馆藏在这里开始 [ ^ ]。选择最适合您需要的那个(换句话说,不要注意单个集合 - 全部了解它们)



The real key points to take away from all of this ...

A) Using two (or more) Lists (or Arrays, or any collection) to hold bits of information about the same thing is rarely (if ever) a good idea. It's just too easy for things to get out of step and if you want another piece of information you have to introduce a whole new List (or Array, or collection)
Get comfortable with ways of grouping things together - when is a class appropriate or just a KeyValuePair or a combination etc etc.

B) Get to know what collections are available starting here[^]. Choose the one that is most appropriate for your need at the time (in other words, don't fixate on a single collection - get to know them all)


一些设计指南为了让你开始,虽然我不知道你如何将它与业务联系起来,因为你几乎没有在你的问题中分享。你需要调整我的伪代码分配:)



*有这样的XML

A couple of design guide line for you to get you start though i don't know how would you relate it with the business as you have shared almost nothing in your question. You need to tweak allot over my pseudo code as well :)

* Have an XML like this
<data>
 <ShippingCompany>
   <Name ="Fedex">
   ...
 </ShippingCompany>
 <ShippingData>
   <Name = "Fedex" Shipped="234" Pending="0"/>
   <Name = "CSX" Shipped="0" Pending="20" />
   ....
 </ShippingData>
</Data></data>





*有一个将保存此XML数据的类



* Have a class which will hold this XML data

Class ShippingData
{
   public string Name;
   string Shipped;
   string Pending;
}





*有一个Dictionry< string,>喜欢你的代码中的结构



*读取伪代码就好像





* Have a Dictionry<string,> like structure in your code

* A reading pseudo-code would be like

void SomeFunction()
  {
     Dictionary<string, ShippingData> dicShippingList = new Dictionary<string, ShippingData>()
     XmlDocument doc = new XmlDocument();
     doc.Load("XmlFile.xml");
     XmlNodeList CompanyList = doc.SelectNodes("\Data\ShippingCompany");
     foreach(XmlNode node in CompanyList)
     {
       ShippingData shippingData = new ShippingData();
       shippingData.Name = node.Attributes["Name"].Value;
       dicShippingList.Add(node.Name, shippingData);
     }

     XmlNodeList CompanyList = doc.SelectNodes("\Data\ShippingData");
     foreach(XmlNode node in CompanyList)
     {
       string name = node.Attributes["Shipped"].Value;
       ShippingData shipObj = dicShippingList[name];
       shippingData.Shipped = node.Attributes["Shipped"].Value;
       shippingData.Pending = node.Attributes["Pending"].Value;
       dicShippingList[node.Name] = shipObj; 
     }

     foreach(KeyValuePair<string,> item in dicShippingList)
     {
        Console.Write(item.Key);
        Console.Write(((ShippingData)item.Value).Shipped);
     }


这篇关于如何获得以下格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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