Hi, I am following into this code.
please refer to https://help.syncfusion.com/windowsforms/spreadsheet/shapes#adding-charts-at-runtime
The code below is a sample on how to create chart. But this example is hard coded(predefined). What I want is to do is to generate or add chart during run time. Please refer to attached.
var chart = spreadsheet.AddChart(spreadsheet.ActiveSheet);
object[] Y_values = new object[] { 200, 100, 100 };
object[] X_values = new object[] { "Total Income", "Expenses", "Profit" };
IChartSerie series = chart.Series.Add(ExcelChartType.Pie);
// Enters the X and Y values directly
series.EnteredDirectlyValues = Y_values;
series.EnteredDirectlyCategoryLabels = X_values;
var shape = chart as ShapeImpl;
// Re-Positioning Chart
shape.Top = 200;
shape.Left = 200;
//Re-sizing a Chart
shape.Height = 300;
shape.Width = 300;|
private void ChartBtn_Click(object sender, EventArgs e)
{
var chart = spreadsheet.AddChart(spreadsheet.ActiveSheet);
GridRangeInfo range = spreadsheet.ActiveGrid.SelectedRanges.ActiveRange;
chart.DataRange = spreadsheet.ActiveSheet.Range[range.Left,range.Top,range.Bottom,range.Right];
var shape = chart as ShapeImpl;
shape.Top = 100;
shape.Left = 200;
// chart.ChartType = ExcelChartType.Column_Clustered;
spreadsheet.ActiveGrid.GraphicModel.InvalidateGraphicObjects();
spreadsheet.ActiveGrid.GraphicModel.InvalidateGraphicVisual();
} |
thank you for the response. The chart is for the Column,
How about if I want a pie chart?