Essentially, I am going to want something like the following:
I have a list of states with their top resources, and I want the resources to represent each of the BarSeries.
I want these bar series represented for each state, but each state does not have the same resources as income.
For instance, I have Iowa set to receive income from Tech and Banking.
New Jersey has banking and tourism, as well as New York.
So, I have three series: Banking, Tourism and Tech, that's three bar series, color coded.
I sort the states, having Iowa, New Jersey and New York on the axis (using custom ticks, so Iowa is 0.0, New Jersey is 1.0 and New York is 2.0).
Obviously, this is all mocked up data just to play with this, and isn't the end product I'm trying to make, but this output will be very similar to what I want.
When i use the PointLineSeries, I can get what I want:
Code: Select all
private void PlotPointItem(StateResourceType resourceType,
PointLineSeries lineSeries,
AxisX xAxis,
IEnumerable<StateTopResourcesDataEntry> entries)
{
var seriesPoints = new List<SeriesPoint>();
foreach (var data in entries)
{
var plotItem = data.Resources.SingleOrDefault(r => r.ResourceType.Equals(resourceType));
if (plotItem != null)
{
var seriesPoint = new SeriesPoint();
var item = xAxis.CustomTicks.FirstOrDefault((t) => t.LabelText.Equals(data.StateName));
if (item != null)
{
seriesPoint.X = item.AxisValue;
}
else
{
seriesPoint.X = 0;
}
seriesPoint.Y = plotItem.IncomeFrom;
seriesPoints.Add(seriesPoint);
}
}
//Assign the data for the point line series
lineSeries.Points = seriesPoints.ToArray();
}
However, when I switch over to using a bar graph, I would expect similar results, but I don't get them that way....
Code: Select all
private void PlotPointItem(TickStateInfo tick,
Dictionary<StateResourceType, BarSeries> barSeries,
AxisX xAxis)
{
foreach (var resourceItem in tick.ResourceList)
{
BarSeries barItem;
if (barSeries.TryGetValue(resourceItem.ResourceType, out barItem))
{
barItem.AddValue(tick.XAxisValue, resourceItem.IncomeFrom, resourceItem.IncomeFrom.ToString(), true);
}
}
}
What happens is, the 89.23 Tourism value actually belongs to New Jersey, not New York, and the 91 value for new york's tourism is no where to be seen...
I have validated with breakpoints in my VS IDE that I am setting the location to 1.0 for New Jersey's tourism value of 89.23 and 2.0 for New York's tourism value of 91, but it won't work, I have to do this:
Code: Select all
private void PlotPointItem(TickStateInfo tick,
Dictionary<StateResourceType, BarSeries> barSeries,
AxisX xAxis)
{
var listUsed = new List<StateResourceType>();
foreach (var resourceItem in tick.ResourceList)
{
BarSeries barItem;
if (barSeries.TryGetValue(resourceItem.ResourceType, out barItem))
{
barItem.AddValue(tick.XAxisValue, resourceItem.IncomeFrom, resourceItem.IncomeFrom.ToString(), true);
listUsed.Add(resourceItem.ResourceType);
}
}
foreach (var series in barSeries.Where(series => !listUsed.Contains(series.Key)))
{
series.Value.AddValue(tick.XAxisValue, 0.0, "0.0", true);
}
}
However, in the end, I am going to have dozens of different possible 'resources', and setting each item to 0 is just not going to be practical... is there a way I can skip items, or some workaround I can do (like set 0 value item bars to width 0, it doesn't appear you can set individual bar widths to 0..)
Please let me know if you would like more information...
Thank you for your time!