RadHtmlChart convert millis to datetim in tooltip

1 Answer 19 Views
Ajax Chart (HTML5)
Didier
Top achievements
Rank 2
Iron
Didier asked on 29 Mar 2022, 04:29 PM

Hi all,

 

I 'm looking to convert millis into the tooltip of a RadHtmlChart

 

The convertion work well on the xAxis.

I set the DataFormating in the code behind since a have dynamical number of serie ..

But it's doesnt work.

 

Also, looking for simple Label (unit) insertion bellow the xAxis and left to the yAxis. (like my sample)

 

Thanks in advance,

 

Didier

 

 

 

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 30 Mar 2022, 03:34 PM

Hi Didier,

You can add labels to the X and Y axis of the HtmlChart by defining their TitleApperance.Text properties:

        <telerik:RadHtmlChart runat="server" ID="RadHtmlChart1" Width="640px" Height="480px">
            <PlotArea>
                ...
                <XAxis BaseUnit="days">
                    <TitleAppearance Text="Sell Date">
                    </TitleAppearance>
                </XAxis>
                <YAxis>
                    <TitleAppearance Text="Quantity">
                </YAxis>
            </PlotArea>
        </telerik:RadHtmlChart>

AS for the formatting of the date - the Chart will handle it automatically if the bound data field type is set to DateTime. Otherwise, you can see how to convert the numbers to datetime values here:

https://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/how-to/programmatic-creation-of-seriesitems-with-datetime

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Didier
Top achievements
Rank 2
Iron
commented on 30 Mar 2022, 07:13 PM | edited

Thanks for your reply.

 

The problem is the fact that i create the Series dynamically from code behind, because I can have 1 to n series ..

So i can not set the ClientTemplate from aspx, it doesnt exist and it's created dynamically.

 

Here, my code behind

scatterChart.DataSource = null;
List<BatchChannelValue> listBatchValues = GetValues(long.Parse(ChartID));

var channelGroup = listBatchValues.GroupBy(x => x.ChannelLabel);

if (scatterChart.PlotArea.Series.Count > 0)
    scatterChart.PlotArea.Series.Clear();

foreach (var channelItem in channelGroup)
{

    ScatterLineSeries sls = new ScatterLineSeries();

    sls.Name = channelItem.Key + " Data";
    sls.DataFieldY = channelItem.Key;
    sls.DataFieldX = "DateTimeRecord";
    sls.LabelsAppearance.Visible = false;
    sls.MissingValues = Telerik.Web.UI.HtmlChart.MissingValuesBehavior.Gap;
    sls.TooltipsAppearance.DataFormatString = "{1:0.000} the {0:dd/MM/yyyy HH:mm:ss}";
                           

    foreach (var value in channelItem)
    {
        ScatterSeriesItem serieItem = new ScatterSeriesItem(ToMilliseconds(value.DateTimeRecord), (decimal?)value.Value);
        sls.SeriesItems.Add(serieItem);
                                

    }
    scatterChart.PlotArea.Series.Add(sls);

    scatterChart.PlotArea.XAxis.BaseUnit = Telerik.Web.UI.HtmlChart.DateTimeBaseUnit.Seconds;

    scatterChart.PlotArea.XAxis.LabelsAppearance.RotationAngle = 90;
    scatterChart.PlotArea.XAxis.Type = Telerik.Web.UI.HtmlChart.AxisType.Date;
                            
    scatterChart.PlotArea.XAxis.LabelsAppearance.DataFormatString = "{0:dd/MM/yyyy HH:mm:ss}";
    scatterChart.PlotArea.XAxis.TitleAppearance.Text = "Time";
    scatterChart.PlotArea.YAxis.TitleAppearance.Text = "K";

    scatterChart.DataBind();
                           

}

Also, It's complicated to update the series ... I try here to re-construct the series every 5 secodnes via a timer, but no way.

 

Regards

 

ps: tx for the labels, that's correct

 

 

Tags
Ajax Chart (HTML5)
Asked by
Didier
Top achievements
Rank 2
Iron
Answers by
Vessy
Telerik team
Share this question
or