Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:



C#
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

C#
//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.
Posted
Updated 28-Jan-15 22:31pm
v4
Comments
sashje- 29-Jan-15 3:54am    
Improve your question, it doesn't make sense at all.
U@007 29-Jan-15 4:00am    
Now see my question?
sashje- 29-Jan-15 5:20am    
if you are displaying the data in the same bar chart, you should maybe have the identical set of X vs Y values.. That is, you should have entries of "0" for Fedex in the Pending_List_Count, and entry 0 for YRC in the shipped_list_count and so on.. If you don't have the same set of values and labels, you will need to create to different bar charts..
_Asif_ 29-Jan-15 3:56am    
Can you please elaborate a bit more? :)
U@007 29-Jan-15 4:00am    
Now see my question?

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)
C#
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.
C#
var Shipping = new List<shippingitem>();
Shipping.Add(new ShippingItem("Fedex", 234, 0));
//etc</shippingitem>


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 ...
C#
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 ...
C#
var Shipping_List = new Dictionary<string, int>();
Shipping_List.Add("Fedex", 234);
//etc


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)
 
Share this answer
 
Comments
_Asif_ 29-Jan-15 6:57am    
+5 :)
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
XML
<data>
 <ShippingCompany>
   <Name ="Fedex">
   ...
 </ShippingCompany>
 <ShippingData>
   <Name = "Fedex" Shipped="234" Pending="0"/>
   <Name = "CSX" Shipped="0" Pending="20" />
   ....
 </ShippingData>
</Data></data>


* Have a class which will hold this XML data
C#
Class ShippingData
{
   public string Name;
   string Shipped;
   string Pending;
}


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

* A reading pseudo-code would be like

C#
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);
     }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900