- 1 year ago
Creating StackedColumn100 in C# Chart
To create a StackedColumn100 chart in C# using the built-in Chart
control, you can follow these steps:
Add a
Chart
control to your form. You can do this either in the Visual Studio designer or programmatically.Configure the chart properties and series settings. Here's an example:
csharpusing System.Windows.Forms.DataVisualization.Charting;
// Set the chart type to StackedColumn100
chart1.Series.Clear();
chart1.ChartAreas.Clear();
chart1.Series.Add("Series1");
chart1.Series.Add("Series2");
chart1.Series.Add("Series3");
chart1.ChartAreas.Add("ChartArea1");
// Set the chart type
chart1.Series["Series1"].ChartType = SeriesChartType.StackedColumn100;
chart1.Series["Series2"].ChartType = SeriesChartType.StackedColumn100;
chart1.Series["Series3"].ChartType = SeriesChartType.StackedColumn100;
// Add data points
chart1.Series["Series1"].Points.AddXY("Category1", 30);
chart1.Series["Series1"].Points.AddXY("Category2", 50);
chart1.Series["Series1"].Points.AddXY("Category3", 20);
chart1.Series["Series2"].Points.AddXY("Category1", 40);
chart1.Series["Series2"].Points.AddXY("Category2", 10);
chart1.Series["Series2"].Points.AddXY("Category3", 30);
chart1.Series["Series3"].Points.AddXY("Category1", 20);
chart1.Series["Series3"].Points.AddXY("Category2", 40);
chart1.Series["Series3"].Points.AddXY("Category3", 50);
// Set axis labels and titles
chart1.ChartAreas["ChartArea1"].AxisX.Title = "Categories";
chart1.ChartAreas["ChartArea1"].AxisY.Title = "Values";
Adjust the series names, data points, and chart area settings as per your requirements.
Optionally, customize other chart properties like titles, legends, axis labels, colors, etc., to suit your needs.
Run your application to display the StackedColumn100 chart.
The above code demonstrates how to create a StackedColumn100 chart with three series ("Series1", "Series2", and "Series3") and three categories ("Category1", "Category2", and "Category3") with corresponding values. You can modify the series names, data points, and other settings as needed to match your specific data and chart requirements.
Remember to include the System.Windows.Forms.DataVisualization.Charting
namespace at the top of your code file.