How to shade in a line chart series

1 Answer 140 Views
Chart
Jerry
Top achievements
Rank 1
Iron
Iron
Iron
Jerry asked on 14 Oct 2022, 02:59 PM

I am using the below line chart.

Is there a way to have the green series area filled in with green?

I would like the green series fully colored in as green. But leave the red series as a line.

 

 

 

 

 

 

 <div class="demo-section wide">
    @(Html.Kendo().Chart()
        .Name("chart")
        .Title("Hybrid car mileage report")
        .Legend(legend => legend
            .Position(ChartLegendPosition.Top)
        )
        .SeriesDefaults(seriesDefaults =>
            seriesDefaults.Line().Style(ChartSeriesStyle.Smooth)
        )
        .Series(series =>
        {
            series
                .Line(new double[] { 1040655525 })
                .Name("mpg")
                .Color("red")
                .Axis("mpg");
            series
                .Line(new double[] { 13652 })
                .Name("l/100 km")
                .Color("green")
                .Axis("l100km");
        })
        .CategoryAxis(axis => axis
            .Categories("Mon""Tue""Wed""Thu""Fri")
            // Align the first two value axes to the left
            // and the last two to the right.
            //
            // Right alignment is done by specifying a
            // crossing value greater than or equal to
            // the number of categories.
            .AxisCrossingValue(001010)
        )
        .ValueAxis(axis => axis
            .Numeric()
                .Title("miles")
                .Min(0).Max(100)
        )
        .ValueAxis(axis => axis
            .Numeric("km")
                .Title("km")
                .Min(0).Max(161).MajorUnit(32)
        )
        .ValueAxis(axis => axis
            .Numeric("mpg")
                .Title("miles per gallon")
                .Color("#ec5e0a")
        )
        .ValueAxis(axis => axis
            .Numeric("l100km")
                .Title("liters per 100km")
                .Color("#4e4141")
        )
        .Tooltip(tooltip => tooltip
            .Visible(true)
            .Format("{0}%")
        )
    )

</div>

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Petar
Telerik team
answered on 17 Oct 2022, 09:03 AM

Hi, Jerry.

Please check this REPL example and let me know if it demonstrates what you need to have in your scenario.

To achieve the demonstrated scenario, the following, marked in yellow configuration is added to the definition that you've shared:

.Series(series =>
{
    series
        .Line(new double[] { 10, 40, 65, 55, 25 })
        .Name("mpg")
        .Color("red")
        .Axis("mpg");
    series
        .Line(new double[] { 1, 3, 6, 5, 2 })
        .Name("l/100 km")
        .Color("green")
        .Axis("l100km")
        .Type("area")
        .Line(ln=>ln.Style(ChartAreaStyle.Smooth));
})

I hope the above suggestion will help you achieve the desired functioanlity. 

Regards,
Petar
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.

Jerry
Top achievements
Rank 1
Iron
Iron
Iron
commented on 18 Oct 2022, 04:59 PM

Yes, that's what I needed.

 

Petar
Telerik team
commented on 19 Oct 2022, 05:27 AM

Hi, Jerry. 

I am happy to hear that the suggested approach has helped you!

Tags
Chart
Asked by
Jerry
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Petar
Telerik team
Share this question
or