Profile Picture

DateTime values Stacked

Posted By Paulo Silva 11 Years Ago
Author
Message
Paulo Silva
Posted 11 Years Ago
View Quick Profile
Junior Member

Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 13, Visits: 12
Hi,

I'm trying to make a Stacked Time value chart, but it seems that only Clustered is working.
My code is this:

private void LoadData()
{
NCartesianChart cartesianChart = nChartControl1.Charts[0] as NCartesianChart;

NStandardScaleConfigurator scaleconfigurator = cartesianChart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NStandardScaleConfigurator;
NDateTimeValueFormatter dateTimeFormater = new NDateTimeValueFormatter(DateTimeValueFormat.LongDate);
dateTimeFormater.FormatSpecifier = "t";
scaleconfigurator.LabelValueFormatter = dateTimeFormater;

NBarSeries barSerie1 = cartesianChart.Series.Add(SeriesType.Bar) as NBarSeries;
barSerie1.MultiBarMode = MultiBarMode.StackedPercent;
barSerie1.DataLabelStyle.VertAlign = VertAlign.Center;

NBarSeries barSerie2 = cartesianChart.Series.Add(SeriesType.Bar) as NBarSeries;
barSerie2.MultiBarMode = MultiBarMode.StackedPercent;
barSerie2.FillStyle = new NColorFillStyle(Color.Red);
barSerie2.DataLabelStyle.VertAlign = VertAlign.Center;

NBarSeries barSerie3 = cartesianChart.Series.Add(SeriesType.Bar) as NBarSeries;
barSerie3.MultiBarMode = MultiBarMode.StackedPercent;
barSerie3.FillStyle = new NColorFillStyle(Color.Green);
barSerie3.DataLabelStyle.VertAlign = VertAlign.Center;

DateTime tini = DateTime.Now;
DateTime tfin = DateTime.Now.AddHours(2);

NRange1DD nRange1dd = new NRange1DD(tini.ToOADate(), tfin.ToOADate());

TimeSpan span = new TimeSpan(0, 30, 0);
if (span.Ticks > 0)
{
while (tini < tfin)
{
barSerie3.Values.Add(tini + span);
barSerie2.Values.Add(tini - span);
barSerie1.Values.Add(tini);
tini += span;
}
}
NRangeAxisView nRangeAxisView = new NRangeAxisView();
nRangeAxisView.Range = nRange1dd;
cartesianChart.Axis(StandardAxis.PrimaryY).View = nRangeAxisView;
NScale bu = cartesianChart.Axis(StandardAxis.PrimaryY).Scale;

nChartControl1.Refresh();
}

Can anyone help?

Nevron Support
Posted 11 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Paulo,

What exactly do you want to achieve - can you post a screenshot?

Best Regards,
Nevron Support Team



Paulo Silva
Posted 11 Years Ago
View Quick Profile
Junior Member

Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 13, Visits: 12
Just a simple stacked or stacked percent with date time values.



Attachments
stacked.png (158 views, 18.00 KB)
stackedpercent.png (153 views, 21.00 KB)
Nevron Support
Posted 11 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
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



Paulo Silva
Posted 11 Years Ago
View Quick Profile
Junior Member

Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 13, Visits: 12
Is this so difficult?

Nevron Support
Posted 11 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Paulo,

What do you find difficult about this code? If it is the formatting - you can use the built-in formatting of the TimeSpan type. In this case the override of FormatValue will be as simple as this:

   public override string FormatValue(double value)
   {
      return TimeSpan.FromMinutes(value).ToString(@"hh\:mm");
   }


Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic