Articles in this section
Category / Section

How to Render a Stacked Bar Chart with a Line Chart in Blazor Charts?

2 mins read

This article explains how to render a stacked bar chart alongside a line chart on the same graph using Blazor Charts.

Solution

Blazor Charts provides support for rendering multiple chart types on the same graph. By setting the IsTransposed property of the SfChart to true, you can effectively align stacked bar(column) charts alongside a line chart. Each series can be configured individually to define its chart type.

Code Snippet

The example below demonstrates how to render a stacked bar chart and a line chart together in a transposed Blazor chart:

@using Syncfusion.Blazor.Charts

<SfChart Title="GDP by Country in 2017" IsTransposed="true">
   <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category">
   </ChartPrimaryXAxis>
   <ChartPrimaryYAxis Title="GDP (In Percentage)" LabelFormat="{value}%" EdgeLabelPlacement="EdgeLabelPlacement.Shift">
   </ChartPrimaryYAxis>
   <ChartLegendSettings Visible="false"></ChartLegendSettings>
   <ChartSeriesCollection>
       <ChartSeries DataSource="@ChartPoints" XName="Country" YName="GDP" Name="Series1" Width="2" ColumnSpacing="0.1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.StackingColumn">
       </ChartSeries>
       <ChartSeries DataSource="@ChartPoints" XName="Country" YName="WorldShare" Name="Series2" Width="2" ColumnSpacing="0.1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.StackingColumn">
       </ChartSeries>
       <ChartSeries DataSource="@ChartPoints" XName="Country" YName="WorldShare1" Name="Series3" Width="2" ColumnSpacing="0.1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Line">
           <ChartMarker Visible="true">
           </ChartMarker>
       </ChartSeries>
   </ChartSeriesCollection>
</SfChart>

@code {
   public List<BarChartData> ChartPoints { get; set; } = new List<BarChartData>
   {
       new BarChartData { Country = "Canada",  GDP = 3.05 , WorldShare = 2.04, WorldShare1 = 5.6 },
       new BarChartData { Country = "Italy", GDP = 1.50 , WorldShare = 2.40, WorldShare1 = 4.2  },
       new BarChartData { Country = "Germany",  GDP = 2.22, WorldShare = 4.56, WorldShare1 = 7.0  },
       new BarChartData { Country = "India", GDP = 6.68 , WorldShare = 3.28, WorldShare1 = 10.3   },
       new BarChartData { Country = "France",  GDP = 1.82, WorldShare = 3.19, WorldShare1 = 5.3  },
       new BarChartData { Country = "Japan",  GDP = 1.71, WorldShare = 6.02, WorldShare1 = 7.9  }
   };
   public class BarChartData
   {
       public string Country { get; set; }
       public double GDP { get; set; }
       public double WorldShare { get; set; }
       public double WorldShare1 { get; set; }
   }
} 

Screenshot

The following image illustrates the output of the above code snippet:

msedge_ubHdEbv0kE.png

Live Sample: Render a stacked bar chart and a line chart on the same graph

Conclusion:

We hope you found this guide helpful in learning How to render a stacked bar chart with a line chart in Blazor Charts. For more features, visit our [Blazor Charts feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our [Blazor Charts example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied