Hi Paulo,
It looks like you need to stack TimeSpan values, not DateTime values, but at this point this is not supported. An easy solution is to simply add the time intervals as regular values and change the way they are formatted. For this purpose you have to implement a custom type that formats values as time intervals. The following code demonstrates how this can be done (without being a complete solution).
class CustomTimeValueFormatter : NValueFormatter
{
public override string FormatValue(object value)
{
if (value is double)
return FormatValue((double)value);
return value.ToString();
}
public override string FormatValue(double value)
{
int intValue = ((int)value);
double minutes = intValue % 60;
double hours = intValue / 60;
return hours.ToString("00") + ":" + minutes.ToString("00");
}
}
Using this class you can implement the stacked charts like this:
void ConfigureChart(bool percentStack)
{
NChart chart = nChartControl1.Charts[0];
if (!percentStack)
{
NStandardScaleConfigurator scaleY = (NStandardScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator;
scaleY.LabelValueFormatter = new CustomTimeValueFormatter();
}
NBarSeries barSeries1 = (NBarSeries)chart.Series.Add(SeriesType.Bar);
barSeries1.MultiBarMode = MultiBarMode.Series;
barSeries1.DataLabelStyle.VertAlign = VertAlign.Center;
barSeries1.Values.ValueFormatter = new CustomTimeValueFormatter();
NBarSeries barSeries2 = chart.Series.Add(SeriesType.Bar) as NBarSeries;
barSeries2.MultiBarMode = percentStack ? MultiBarMode.StackedPercent : MultiBarMode.Stacked;
barSeries2.FillStyle = new NColorFillStyle(Color.Red);
barSeries2.DataLabelStyle.VertAlign = VertAlign.Center;
barSeries2.Values.ValueFormatter = new CustomTimeValueFormatter();
NBarSeries barSeries3 = chart.Series.Add(SeriesType.Bar) as NBarSeries;
barSeries3.MultiBarMode = percentStack ? MultiBarMode.StackedPercent : MultiBarMode.Stacked;
barSeries3.FillStyle = new NColorFillStyle(Color.Green);
barSeries3.DataLabelStyle.VertAlign = VertAlign.Center;
barSeries3.Values.ValueFormatter = new CustomTimeValueFormatter();
barSeries1.Values.AddRange(new double[] { 5, 20, 15 });
barSeries2.Values.AddRange(new double[] { 20, 35, 10 });
barSeries3.Values.AddRange(new double[] { 15, 10, 25 });
}
Best Regards,
Nevron Support Team