Completed
Last Updated: 11 Oct 2019 08:01 by ADMIN
James
Created on: 11 Oct 2019 07:08
Category: Charts
Type: Feature Request
0
Provide styling options for charts UI for Blazor
Hi there, it would be really nice if there were styling options available for the charts. I know that they styling gets inherited from the Telerik theme, but on the theme builder we can't get what we need without disrupting other UI styles. 

What we are looking for is really just a means to change the legend text color, and other text colors, as well as being able to set a background. 

For instance: 



Through the Telerik theme we would not be able to do this, maybe on one chart, but not different styles for each of the 3 charts. 

Possibly also having the chart to resize as the browser resizes, with an included Delay of 20ms. Just a thought. 
1 comment
ADMIN
Marin Bratanov
Posted on: 11 Oct 2019 08:01

Hello James,

The default colors (including the default list of series colors) do come from the themes, but you have full control over various colors and styles through the chart properties. Such properties are the way to style a chart, and you need to look for child elements to find styling options.

Usually, the inner tags will contain their parent tag name and add specifics to its end. You can see an example of this with the ChartSeries > ChartSeriesLabels tags.

Here's an example I made for you based on our first sample in the docs. I highlighted the changes

 

<TelerikChart>
    <ChartSeriesItems>
        <ChartSeries Type="ChartSeriesType.Line" Name="Product 1 (bound to simple data)" Data="@simpleData">
        </ChartSeries>
        <ChartSeries Type="ChartSeriesType.Line" Name="Product 2 (bound to model)" Data="@modelData" Field="@nameof(MyDataModel.SecondSeriesValue)">
            <ChartSeriesLabels Color="cyan" Font="22px 'Courier New'" Background="transparent" Template="#=value# in #=dataItem.ExtraData# quarter" Visible="true">
                <ChartSeriesLabelsBorder Width="3" Color="green" DashType="DashType.LongDashDotDot"></ChartSeriesLabelsBorder>
            </ChartSeriesLabels>
        </ChartSeries>
    </ChartSeriesItems>

    <ChartValueAxes>
        <ChartValueAxis Color="red"></ChartValueAxis>
    </ChartValueAxes>

    <ChartCategoryAxes>
        <ChartCategoryAxis Categories="@xAxisItems"></ChartCategoryAxis>
    </ChartCategoryAxes>

    <ChartTitle Text="Quarterly sales trend"></ChartTitle>

    <ChartLegend Position="Telerik.Blazor.ChartLegendPosition.Bottom" Background="red">
        <ChartLegendLabels Color="blue" Font="10px Verdana">
            <ChartLegendLabelsMargin Top="50"></ChartLegendLabelsMargin>
        </ChartLegendLabels>
    </ChartLegend>
</TelerikChart>

@code {
    public class MyDataModel
    {
        public int SecondSeriesValue { get; set; }
        public string ExtraData { get; set; }

    }

    public List<MyDataModel> modelData = new List<MyDataModel>()
{
        new MyDataModel() { SecondSeriesValue = 1, ExtraData = "first" },
        new MyDataModel() { SecondSeriesValue = 5, ExtraData = "second" },
        new MyDataModel() { SecondSeriesValue = 3, ExtraData = "third" },
        new MyDataModel() { SecondSeriesValue = 2, ExtraData = "fourth" },
    };

    public List<object> simpleData = new List<object>() { 10, 2, 7, 5 };

    public string[] xAxisItems = new string[] { "Q1", "Q2", "Q3", "Q4" };
}

 

Granted, the main background of the chart is now always white, we have not exposed a setting for this yet, but it will become available.

On resizing the chart with the browser - the .Refresh() method the chart exposes does that, you just need to call it from your JS Interop code. I will soon create an example of doing that, in the meantime you can see the general approach here: https://docs.telerik.com/blazor-ui/components/chart/overview#chart-size.

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor