Azeristar Azeristar -4 years ago 150
ASP.NET (C#) Question

How to create a chart which consists of 5 subcharts

I'm trying to create a Chart image which consists of five subcharts.(see Picture)


The X Axis of the Chart should be the same for all 5 subcharts.

How can I realize that with MS Chart Controls?

Currently I'm creating all five Charts, but I have no idea how I can merge the xAxis and how to fit all 5 subcharts into an Image file or Chart.

Thanks for you help in advance!

Answer Source

MsChart allows multiple ChartArea. Each chart area can have multiple Series. As per your screen designs, there will be 5 Chart areas. Each ChartArea will have 1 series added to it.

var chartArea1 = MyChart.ChartAreas.Add("ChartArea 1");
var chartArea5 = MyChart.ChartAreas.Add("ChartArea 5");

Add Series to charts and assign the chart area

MyChart.Series[0].ChartArea = chartArea1.Name;
MyChart.Series[5].ChartArea = chartArea5.Name;

Now, to have a common X axis, assign the

chartArea1.AlignWithChartArea = chartArea5.Name;
chartArea2.AlignWithChartArea = chartArea5.Name;

You can also refer the link for MSChart.

Update for Chart Area placement Below code is to shows how to position the chart areas within a chart control. Note:- X and Y position are in percentage rather then pixels, twips, etc.

chartArea1.Position.Y = 0;
chartArea1.Position.Height = 43;
chartArea1.Position.Width = 100;
chartArea2.Position.Y = chartArea1.Position.Bottom + 1;
chartArea2.Position.Height = chartArea1.Position.Height;
chartArea2.Position.Width = chartArea1.Position.Width;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download