I was wondering how to select multiple values of same type from a list...
To be more specific:
public class price
{
public string NAME { get; set; }
public string PRICE { get; set; }
public string TIMESTAMP { get; set; }
}
This is my List called price. Now I want for example, if this is my json output to send to list:
{
"Products": [[{
"NAME": "Shirt",
"PRICE": "25.0",
"TIMESTAMP": "2018-03-19 06:58:24"
}
], [{
"NAME": "Pants",
"PRICE": "30.0",
"TIMESTAMP": "2018-03-19 06:58:16"
}
], [{
"NAME": "Shirt",
"PRICE": "20.0",
"TIMESTAMP": "2018-03-19 06:58:17"
}
]]
}
So I want to return the values from a specific Name, like Shirt. When I choose Shirt, I want the values: 25.0 - 20.0. Then I want to create a graph with all the values from NAME=Shirt orderby oldest first (Like a chart). I receive a json from a link, parse it and put it in a List like this:
string link = @"http://*****/getprices.php";
string json = new WebClient().DownloadString(link);
var jObject = JObject.Parse(json);
var pricePropery = jObject["Prices"] as JArray;
List<price> PriceList = new List<price>();
foreach (var property in pricePropery)
{
var propertyList = JsonConvert.DeserializeObject<List<price>>(property.ToString());
PriceList.AddRange(propertyList);
}
The thing is that the json has a couple times the same NAME with only a different PRICE and TIMESTAMP, so I want to select all the Prices of the value "NAME" and sort it by the oldest Price by using the TIMESTAMP above.
Now I want to make a chart by using microcharts. To create a chart, you have to do something like this:
PriceChart.Chart = new PointChart { Entries = Source };
So I replaced "Source" by PriceList, but thats not going to work.
So how am I supposed to do this...
EDIT: When I use this code:
var singleNameWithOldestPrice =
from p in pricePropery
group p by p.NAME into grp
select grp.OrderBy(a => a.TIMESTAMP ).First();
How am I supposed to use it as source of the chart, because this is not going to work:
PriceChart.Chart = new PointChart { Entries = singleNameWithOldestPrice };
I cannot convert a List to a source of a PointChart.
Please let me know!
all you want is
var singleNameWithOldestPrice =
from p in pricePropery
group p by p.NAME into grp
select grp.OrderBy(a => a.TIMESTAMP ).First()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.