Unplanned
Last Updated: 26 May 2020 01:01 by ADMIN
Gilles
Created on: 06 Nov 2019 15:57
Category: Charts
Type: Bug Report
2
Chart not displayed if I set Min and Max properties of a Date ChartCategoryAxis

 

Hi, I can't figure how to use the Min/Max properties of the ChartCategoryAxis because if I set these properties, the chart disappears.

Please help me.

 

@page "/"

<TelerikChart>

    <ChartSeriesItems>
        <ChartSeries Type="ChartSeriesType.Line" Name="Test" Data="@mesures"
                     Field="@nameof(Mesure.Value)" CategoryField="@nameof(Mesure.Date)" Aggregate="ChartSeriesAggregate.Sum">
        </ChartSeries>
    </ChartSeriesItems>

    <ChartCategoryAxes>
        <!-- This is OK -->
        @*<ChartCategoryAxis BaseUnit="ChartCategoryAxisBaseUnit.Hours" Type="ChartCategoryAxisType.Date" BaseUnitStep="1"></ChartCategoryAxis>*@

        <!-- This isn't : nothing is displayed -->
        <ChartCategoryAxis Min="@MinDate" Max="@MaxDate" BaseUnit="ChartCategoryAxisBaseUnit.Hours" Type="ChartCategoryAxisType.Date" BaseUnitStep="1"></ChartCategoryAxis>
    </ChartCategoryAxes>

</TelerikChart>

@code {

    private DateTime MinDate { get; set; } = new DateTime(2019, 01, 01, 13, 0, 0);
    private DateTime MaxDate { get; set; }   = new DateTime(2019, 01, 01, 17, 0, 0);

    public class Mesure
    {
        public DateTime Date { get; set; }
        public int Value { get; set; }
    }

    public List<Mesure> mesures = new List<Mesure>()
    {
        new Mesure() { Date = new DateTime(2019, 01, 01, 13, 0, 0), Value = 1 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 14, 0, 0), Value = 2 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 14, 30, 0), Value = 3 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 14, 35, 0), Value = 4 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 15, 0, 0), Value = 5 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 16, 0, 0), Value = 6 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 17, 0, 0), Value = 7 },
    };
}


1 comment
ADMIN
Marin Bratanov
Posted on: 07 Nov 2019 08:47

Hello Gilles,

I moved this thread to the Feedback portal so you can Follow its status. Here's a link for you: https://feedback.telerik.com/blazor/1440973-chart-not-displayed-if-i-set-min-and-max-properties-of-a-date-chartcategoryaxis.

And here's a workaround (I highlighted the changes):

 

<TelerikChart>

    <ChartSeriesItems>
        <ChartSeries Type="ChartSeriesType.Column" Name="Test" Data="@mesures"
                     Field="@nameof(Mesure.Value)" CategoryField="@nameof(Mesure.Date)" Aggregate="ChartSeriesAggregate.Sum">
        </ChartSeries>
    </ChartSeriesItems>

    <ChartCategoryAxes>
        <ChartCategoryAxis Min="@(SerializeDate(MinDate))"
                           Max="@(SerializeDate(MaxDate))"
                           BaseUnit="ChartCategoryAxisBaseUnit.Hours"
                           Type="ChartCategoryAxisType.Date" BaseUnitStep="1"></ChartCategoryAxis>
    </ChartCategoryAxes>

</TelerikChart>

@code {

    private DateTime MinDate { get; set; } = new DateTime(2019, 01, 01, 10, 11, 12);
    private DateTime MaxDate { get; set; } = new DateTime(2019, 01, 01, 20, 21, 22);

    public string SerializeDate(DateTime date)
    {
        return System.Text.Json.JsonSerializer.Serialize(date).Replace("\"", "");
    }

    public class Mesure
    {
        public DateTime Date { get; set; }
        public int Value { get; set; }
    }

    public List<Mesure> mesures = new List<Mesure>()
{
        new Mesure() { Date = new DateTime(2019, 01, 01, 1, 2, 3), Value = 1 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 14, 0, 0), Value = 2 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 14, 30, 0), Value = 3 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 14, 35, 0), Value = 4 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 15, 0, 0), Value = 5 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 16, 0, 0), Value = 6 },
        new Mesure() { Date = new DateTime(2019, 01, 01, 17, 0, 0), Value = 7 },
    };
}

 

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor