Search Results for

    Show / Hide Table of Contents

    FlexCelReport.CustomizeChart Event

    Fires for each chart in each sheet, after the report has been generated. Allows to do custom modifications to the charts, like for example setting series colors.

    Syntax

    Namespace: FlexCel.Report

    public CustomizeChartEventHandler CustomizeChart

    Examples

    Imagine you want to set the maximum of the x-axis so it ends exactly at the maximum point in your chart.

    You can use the following code to do it:

        using (FlexCelReport flexcelReport = new FlexCelReport(true))
        {
            flexcelReport.CustomizeChart += (sender, args) =>
            {
                var axis = args.Chart.GetChartAxis();
                for (int i = 0; i < axis.Length; i++)
                {
                    if (axis[i].CategoryAxis != null)
                    {
                        //MaxValueForAxis is a method that returns the value we want to set for the Axis.
                        ((TValueAxis)axis[i].CategoryAxis).Max = MaxValueForAxis();
                        ((TValueAxis)axis[i].CategoryAxis).AxisOptions &= ~TValueAxisOptions.AutoMax;
                    }
                    args.Chart.SetChartAxis(axis[i]);
                }
            };
            flexcelReport.Run("Template.xlsx", "Result.xlsx");
        }
    

    Imagine you want to set each series color to a specific value.

    You can use the following code to do it:

        using (FlexCelReport flexcelReport = new FlexCelReport(true))
        {
            flexcelReport.CustomizeChart += (sender, e) =>
            {
                if (e.ChartName == "ChartIWantToModify")
                {
                    //In this event we will set the colors of the series depending on the product.
                    //Let's imagine each product has an associated color that we want to use for its series.
                    //The method ColorForProducts returns the color we want to give to that series.
                    for (int subChart = 1; subChart <= e.Chart.SubchartCount; subChart++)
                    {
                        for (int series = 1; series <= e.Chart.SeriesInSubchart(subChart); series++)
                        {
                            var seriesDef = e.Chart.GetSeriesInSubchart(subChart, series, true, true, true);
                            var seriesOptions = seriesDef.Options[-1];
                            seriesOptions.FillOptions = new ChartSeriesFillOptions(
                                new TShapeFill(true, new TSolidFill(ColorForProduct(series))), null, false, false);
                            seriesOptions.LineOptions = new ChartSeriesLineOptions(
                                new TShapeLine(true, new TLineStyle(new TSolidFill(ColorForProduct(series)))), false);
                            e.Chart.SetSeriesInSubchart(subChart, series, seriesDef);
                        }
                    }
                }
    
            };
            flexcelReport.Run("Template.xlsx", "Result.xlsx");
        }
    

    See also

    • FlexCelReport
    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com