Display y-axis as time axis in hh:mm:ss

Hi SyncFusion,

How can the display of the time axis (Y!) be changed from seconds to hh:mm:ss?
I have an example screenshot attached.

King Regards

Pascal



Attachment: Duration_of_incidents_de34cd15.zip

3 Replies 1 reply marked as answer

SM Srihari Muthukaruppan Syncfusion Team January 15, 2021 07:07 AM UTC

Hi Pascal, 
 
We have analyzed your query. From that, we would like to let you know that we can achieve your requirement using labelFormat property in the axis of the chart. Based on your requirement we have prepared a sample for your reference. Please find the sample and screenshot below. 
 
 
Screenshot: 
 
 
Let us know if you have any concerns. 
 
Regards, 
Srihari 



PB Pascal Botzke January 18, 2021 06:34 AM UTC

Hi Srihari,

Your answer is not what I expected. I am looking for a representation by time for the y-axis (values). In the meantime I have found a solution myself, which I would like to share with you and other SyncFusion users: 

@using System.Globalization 
@using Syncfusion.Blazor.Charts

<SfChart @ref="Chartobj" Width="100%" ID="chart" >
  <ChartEvents LegendClick="OnLegendClick"></ChartEvents>

  <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Double" CrossesAt="new DateTime(2000, 1, 1, 0, 0, 0)" >
  </ChartPrimaryXAxis>

  <ChartPrimaryYAxis Title="DurationOfIncidents" ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime" LabelFormat="H:mm:ss"
                           RangePadding="ChartRangePadding.None" Minimum="new DateTime(2000, 1, 1, 0, 0, 0)" >
  </ChartPrimaryYAxis>
        
  <ChartTooltipSettings Enable="true"></ChartTooltipSettings>

  <ChartSeriesCollection>
    @foreach (var entry in chartData)
    {
      <ChartSeries Name="@entry.First().Name" DataSource="@entry" YName="@nameof(MyDataModel.YTimeSpan)" XName="@nameof(MyDataModel.XValue)"
                             Type="ChartSeriesType.Column" Visible="@entry.First().Visible">
                    <ChartSeriesAnimation Enable="false"> </ChartSeriesAnimation>
      </ChartSeries>
    }
  </ChartSeriesCollection>

  <ChartLegendSettings Visible="true" Padding="20"></ChartLegendSettings>
</SfChart>

@code {

    public bool FullRefreshChart { get; set; } = false;
    public SfChart Chartobj;
    public string[] colors = new string[] { "Red", "Green", "Blue", "Yellow", "Orange", "Purple", "Black", "Aqua", "Lime", "Gray", "Cyan" };
    private Random rnd = new Random();

    public class MyDataModel
    {
        public string Name { get; set; }
        public string LegendTooltip { get; set; }
        public string Color { get; set; }
        public bool Visible { get; set; }
        public int XValue { get; set; }
        public int YValue { get; set; }
        public DateTime YTimeSpan => new DateTime(2000, 1, 1, 0, 0, 0, new System.Globalization.CultureInfo("de").Calendar).AddSeconds(YValue);
    }

    public List<List<MyDataModel>> chartData = new List<List<MyDataModel>>();

    protected override void OnInitialized()
    {
        base.OnInitialized();
        CultureInfo.CurrentCulture = new CultureInfo("de");
        OnSearch();
    }

    protected override void OnAfterRender(bool firstRender)
    {
        base.OnAfterRender(firstRender);

        if (FullRefreshChart)
        {
            FullRefreshChart = false;
            StateHasChanged();
        }
    }

    public void ClearData()
    {
        chartData = null;
    }

    public void OnSearch()
    {
        chartData = new List<List<MyDataModel>>();
        AddChartSeries(15);
    }

    public List<MyDataModel> GetData(string name, string color)
    {
        List<MyDataModel> data = new List<MyDataModel>();
        for (int i = 0; i < 15; i++)
        {
            data.Add(new MyDataModel() { Name = name, Color = color, Visible = true, XValue = i, YValue = rnd.Next(10, 6000) });
        }
        return data;
    }

    public void OnLegendClick(ILegendClickEventArgs args)
    {
        var dataEntry = chartData.Select(modules => modules.Where(module => module.Name.Equals(args.Series.Name, StringComparison.OrdinalIgnoreCase)).ToList()).ToList();
        dataEntry.ForEach(modules => modules.ForEach(module => module.Visible = args.Series.Visible));
        //dataEntry.Visible = args.Series.Visible;
    }

    public void AddChartSeries(int number = 1)
    {
        var seriesCount = chartData.Count;
        for (int index = seriesCount; index < number + seriesCount; index++)
        {
            var serie = GetData($"{nameof(MyDataModel.XValue)}{index}", colors[rnd.Next(colors.Length - 1)]);
            chartData.Add(serie);
        }
        FullRefreshChart = true;
        StateHasChanged();
    }

    public void RemoveChartSeries(int number = 1)
    {
        for (int index = 0; index < number; index++)
        {
            chartData.RemoveAt(chartData.Count - 1);
        }
        FullRefreshChart = true;
        StateHasChanged();
    }

    public void ClearChartSeries()
    {
        chartData.Clear();
        FullRefreshChart = true;
        StateHasChanged();
        Chartobj.ClearSeries();
    }

    public void ChangeVisibleSeriesHalf()
    {
        int index = 0;
        foreach (var serie in chartData)
        {
            serie.First().Visible = (index % 2 == 0);
            index++;
        }
        //FullRefreshChart = true;
        //StateHasChanged();
    }

    public void ChangeVisibleSeriesFull()
    {
        int index = 0;
        foreach (var serie in chartData)
        {
            serie.First().Visible = true;
            index++;
        }
        //FullRefreshChart = true;
        //StateHasChanged();
    }

    public void ChangeVisibleSeriesNone()
    {
        int index = 0;
        foreach (var serie in chartData)
        {
            serie.First().Visible = false;
            index++;
        }
        //FullRefreshChart = true;
        //StateHasChanged();
    }
}


The import thinks I have mark as bold. Parts of the code are not neccessary.

Kind regards

Pascal


Attachment: Duration_of_incidents_result_258bc7ad.zip

Marked as answer

SM Srihari Muthukaruppan Syncfusion Team January 18, 2021 09:01 AM UTC

Hi Pascal, 
 
Thanks for the update. 
 
Kindly let us know if you need any further assistance on this. We are always happy in assisting you.   
 
Regards, 
Srihari M  


Loader.
Up arrow icon