This is a migrated thread and some comments may be shown as answers.

How to dynamically set plotbands for HTML Chart when xaxis are dates

3 Answers 246 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 11 Sep 2016, 12:01 AM

I have a HTML Chart that works great to plot Line Series data against hourly date/time values in the X axis.  I want to shade weekend dates based on the selected date range.  So this needs to be done dynamically in code.  I suspect that I'm not setting the From/To values correctly.  I found one reference that suggested that these should be in OADate format.  But this doesn't seem to work.  But there may be other issues that I'm not seeing.  Here is my code.  Any help is greatly appreciated.

Here's the relevant Markup

<telerik:RadHtmlChart runat="server" Width="1000px" Height="300px"  BackColor="AntiqueWhite" PlotArea-XAxis-LabelsAppearance-TextStyle-FontSize="9pt"
      ID="rhcLogsLast24hrs" BorderWidth="1"  >
      <PlotArea>
          <Series>
 
              <telerik:LineSeries DataFieldY="LogParserSuccess" Name="Log Parser" >
                  <TooltipsAppearance Color="White" DataFormatString="{0:n0}"/>
                  <LabelsAppearance Visible="False" DataFormatString="{0:n0}" />
                  <Appearance  FillStyle-BackgroundColor="#5ab7de">
                      <FillStyle ></FillStyle>
                  </Appearance>
                  <LineAppearance Width="1" />
                  <MarkersAppearance MarkersType="Circle" BackgroundColor="White" Size="8" BorderColor="#5ab7de"
                      BorderWidth="2"></MarkersAppearance>
 
                      <TooltipsAppearance Color="White">
                          <ClientTemplate>
                              #=dataItem.LogParserSuccess# Million Log Events Parsed on<br />#=dataItem.Hour#
                          </ClientTemplate>
                      </TooltipsAppearance>
                               </telerik:LineSeries>                                                                                                         
          </Series>
          <XAxis DataLabelsField="Hour"   >
 
              <LabelsAppearance RotationAngle="90"   DataFormatString="{0:M/d h tt}">
              </LabelsAppearance>
              <TitleAppearance Text="Hour">
              </TitleAppearance>
          </XAxis>
          <YAxis>
              <LabelsAppearance DataFormatString="{0:n0}" >
              </LabelsAppearance>
              <TitleAppearance Text="Log Events" >
              </TitleAppearance>
          </YAxis>
 
      </PlotArea>
      <Legend >
          <Appearance Visible="True" Position="Right">
          </Appearance>
      </Legend>
      <ChartTitle Text="Log Events">
      </ChartTitle>
  </telerik:RadHtmlChart>

Here is the relevant Code Behind:

rhcLogsLast24hrs.PlotArea.XAxis.LabelsAppearance.DataFormatString = "{0:M/d h tt}"
           rhcLogsLast24hrs.PlotArea.XAxis.TitleAppearance.Text = "Hour"
           rhcLogsLast24hrs.PlotArea.YAxis.TitleAppearance.Text = "Log Events (Millions)"
           If ts.TotalHours > 24 Then
               rhcLogsLast24hrs.PlotArea.XAxis.LabelsAppearance.Step = ts.TotalHours / 20
           End If
 
           Dim I As Integer = 0
           For Each dr As DataRow In dt.Rows
               Dim thisdate As DateTime = dr("Hour")
 
               If thisdate.DayOfWeek = DayOfWeek.Saturday Or thisdate.DayOfWeek = DayOfWeek.Sunday Then
                   Dim band As PlotBand = New PlotBand()
                   band.Color = System.Drawing.Color.Green
                   band.Alpha = 190
                   band.From = thisdate.ToOADate
                   band.To = thisdate.AddHours(1).ToOADate
                   rhcLogsLast24hrs.PlotArea.XAxis.PlotBands.Add(band)
               End If
               I += 1
           Next
      rhcLogsLast24hrs.DataSource = dt
       rhcLogsLast24hrs.DataBind()

 

Thanks!

 

3 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 14 Sep 2016, 02:12 PM
Hi Peter,

Generally, you can hide particular labels with x-axis templates. You cannot, however, avoid plotting slots for  the weekends. Such a feature request has already been logged in the kendo uservoice portal, so that you can monitor, comment and raise its priority here - http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback/suggestions/12805008-remove-blank-dates-weekends-from-candle-stock-ch

Regards,
Danail Vasilev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Peter
Top achievements
Rank 1
answered on 16 Sep 2016, 03:11 PM
I wasn't trying to hide labels for weekends.  I wanted create a plotband on the weekends.  Is there a way to do this when you have dates on the x-axis?
0
Danail Vasilev
Telerik team
answered on 19 Sep 2016, 04:13 PM
Hi Peter,

This is a feature request that has already been logged here, so that you can monitor, comment and raise its priority by voting on it - http://feedback.telerik.com/Project/108/Feedback/Details/125916

For the time being you can use the provided workaround.

Regards,
Danail Vasilev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Chart (HTML5)
Asked by
Peter
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Peter
Top achievements
Rank 1
Share this question
or