What is the best approach to ordering the data series in a chart (bar chart specifically)?
Here's a simplified version of the problem:
Chart has two data series, 'REVENUE' and 'EXPENSE'. Raw data simplies down to:
TYPE (string), AMOUNT (dollars), PROGRAM (string)
'EXPENSE', 100, 'ABC'
'EXPENSE', 50, 'XYZ'
'REVENUE', 500, 'XYZ'
X-Axis is each Program, and needs to remain sorted by Program. However, in the chart area, the bar for the REVENUE series must be displayed *before* the bar for the EXPENSE. So, above 'ABC', there would be a blank and then the 100 bar for EXPENSE, and above 'XYZ' there would be a the 500 bar for REVENUE and then the 50 bar for EXPENSE.
I attempted a few approaches, with only partial luck.
First attempt - Reverse():
This did not impact the order at all...when the order was incorrect, Reverse() was called but the order did not change.
Second attempt - RemoveAt() and Add():
This actually worked, and gave me the correct ordering. However, the data series that was removed / re-added is no longer click-able (an exception is thrown), although the data series that was not removed / re-added is still clickable.
FWIW, I cannot simply ensure the data that the Chart is being bound to always puts the REVENUE first, since some Programs (as in the example data above) will not have values for 'REVENUE'.
What is the recommended approach I should be looking at?
Thanks,
William Cook
Here's a simplified version of the problem:
Chart has two data series, 'REVENUE' and 'EXPENSE'. Raw data simplies down to:
TYPE (string), AMOUNT (dollars), PROGRAM (string)
'EXPENSE', 100, 'ABC'
'EXPENSE', 50, 'XYZ'
'REVENUE', 500, 'XYZ'
X-Axis is each Program, and needs to remain sorted by Program. However, in the chart area, the bar for the REVENUE series must be displayed *before* the bar for the EXPENSE. So, above 'ABC', there would be a blank and then the 100 bar for EXPENSE, and above 'XYZ' there would be a the 500 bar for REVENUE and then the 50 bar for EXPENSE.
I attempted a few approaches, with only partial luck.
First attempt - Reverse():
if
(
this
.FundsRadChart.DefaultView.ChartArea.DataSeries[0].LegendLabel.Equals(
"Expense"
, StringComparison.CurrentCultureIgnoreCase))
{
this
.FundsRadChart.DefaultView.ChartArea.DataSeries.Reverse();
}
Second attempt - RemoveAt() and Add():
if
(
this
.FundsRadChart.DefaultView.ChartArea.DataSeries[0].LegendLabel.Equals(
"Expense"
, StringComparison.CurrentCultureIgnoreCase))
{
DataSeries actualsData =
this
.FundsRadChart.DefaultView.ChartArea.DataSeries[0];
this
.FundsRadChart.DefaultView.ChartArea.DataSeries.RemoveAt(0);
this
.FundsRadChart.DefaultView.ChartArea.DataSeries.Add(actualsData);
}
FWIW, I cannot simply ensure the data that the Chart is being bound to always puts the REVENUE first, since some Programs (as in the example data above) will not have values for 'REVENUE'.
What is the recommended approach I should be looking at?
Thanks,
William Cook