# Custom Rendering and Custom Symbols

## Content

## Rendering and Rendered events

FlexChart provides two events for custom rendering: [Rendering](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendering.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendering.html") and [Rendered](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendered.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendered.html"). The [Rendering](/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendering.html) event fires before the chart renders its elements. The [Rendered](/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendered.html) event fires after the chart completes rendering.
Both events expose the chart drawing surface through [RenderEventArgs](/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.RenderEventArgs.Graphics.html) so you can draw custom shapes, text, and images during the rendering cycle.

```auto
public event EventHandler<RenderEventArgs> Rendered
public event EventHandler<RenderEventArgs> Rendering
```

**Draw a custom zone using the Rendering event**
The [Rendering](/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendering.html) event enables drawing on the chart surface before series elements are rendered. The following example draws a threshold band behind the chart data by handling the [Rendering](/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendering.html) event and using the [DataToPoint](/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChart.DataToPoint.html) method to convert data coordinates to pixel coordinates.

1. Create a custom class to record the data.

```auto
public class ScoreItem
{
    public string Label { get; set; }
    public double Score { get; set; }

    public ScoreItem(string label, double score)
    {
        Label = label;
        Score = score;
    }
}
```

2\. Set the data source on the FlexChart control\.

```auto
var data = new List<ScoreItem>
{
  new ScoreItem("Q1", 55),
  new ScoreItem("Q2", 62),
  new ScoreItem("Q3", 80),
  new ScoreItem("Q4", 74),
  new ScoreItem("Q5", 90),
};

flexChart1.DataSource = data;
flexChart1.BindingX = "Label";
flexChart1.ChartType = ChartType.Line;
flexChart1.Header.Content = "Custom Rendering: Threshold Band";
```

3\. Add a series and attach the [Rendering](/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendering.html) event handler.

```auto
var series = new Series { Name = "Score", Binding = "Score" };
flexChart1.Series.Add(series);

// Handle Rendering to draw a custom band behind the series.
flexChart1.Rendering += FlexChart1_Rendering;
```

4\. Handle the [Rendering](/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.FlexChartBase.Rendering.html) event to draw the zone.

```auto
private void FlexChart1_Rendering(object sender, RenderEventArgs e)
{
    var chart = sender as FlexChart;

    var pt1 = chart.DataToPoint(new PointF((float)chart.AxisX.ActualMin, 70f));
    var pt2 = chart.DataToPoint(new PointF((float)chart.AxisX.ActualMax, (float)chart.AxisY.ActualMax));

    using var fillBrush = new SolidBrush(Color.FromArgb(40, Color.Red));
    using var strokeBrush = new SolidBrush(Color.Transparent);
    e.Engine.SetFill(fillBrush);
    e.Engine.SetStroke(strokeBrush);
    e.Engine.DrawRect(pt1.X, pt2.Y, Math.Abs(pt2.X - pt1.X), Math.Abs(pt2.Y - pt1.Y));
}
```

![A line chart titled "Custom Rendering: Threshold Band" with a semi-transparent red zone drawn behind the data points above a score of 70.](https://cdn.mescius.io/document-site-files/images/13ef049a-dbc7-444f-94c2-9a9cd1c2f895/7fcdb4ba-b3c0-4275-99fe-49ca98515b5c-20261123.1c964d.png?width=800)

***

## Custom symbols

FlexChart provides a pair of events for customizing how the marker for each data point is drawn: [SymbolRendering](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html") and [SymbolRendered](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html").
Both events receive [RenderSymbolEventArgs](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.RenderSymbolEventArgs.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.RenderSymbolEventArgs.html"), which expose the drawing engine, the data point index, and the point coordinates.

```auto
public event EventHandler<RenderSymbolEventArgs> SymbolRendered 
public event EventHandler<RenderSymbolEventArgs> SymbolRendering
```

The [SymbolRendering](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html") event fires before the default symbol is drawn. The [SymbolRendered](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html") event fires after the default symbol is drawn. Both events enable custom drawing on top of or in place of the default rendering.
**Customize line segment colors**
The [SymbolRendered](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html") event can customize the line segment drawn between the current data point and the previous data point.
The handler compares the current Y value with the previous Y value and draws the connecting line in red when the value increases, green when it decreases, and orange with a dashed stroke when it stays the same.

1. Attach the [SymbolRendered](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html") event to the series.

```auto
var series = new Series()            
{        
  Name = "Trend",   
  DataSource = dataList,
  Binding = "Y",
  BindingX = "X",
};
// Call the rendering event from the series instance
flexChart1.Series.Add(series);
series.SymbolRendered += Series_SymbolRendered;
```

2\. Handle the [SymbolRendered](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendered.html") event.

```auto
private void Series_SymbolRendered(object sender, RenderSymbolEventArgs e)
{
    if (e.Index > 0)
    {
        Color lineColor;
        if (e.Point.Y == previousY)
        {
            lineColor = Color.Orange;
            e.Engine.SetStrokePattern(new double[] { 2, 1 });
        }
        else if (e.Point.Y > previousY)
        {
            lineColor = Color.Red;
            e.Engine.SetStrokePattern(null);
        }
        else
        {
            lineColor = Color.Green;
            e.Engine.SetStrokePattern(null);
        }
        using var brush = new SolidBrush(lineColor);
        e.Engine.SetStroke(brush);
        e.Engine.SetStrokeThickness(3);
        e.Engine.DrawLine(previousX, previousY, e.Point.X, e.Point.Y);
    }
}
```

![A line chart with connecting segments colored to indicate trend direction: red for increasing values, green for decreasing, and orange dashed for unchanged.](https://cdn.mescius.io/document-site-files/images/13ef049a-dbc7-444f-94c2-9a9cd1c2f895/f4c7353a-d737-4536-b1d1-7a835e5f6ec1-20261123.367707.png?width=800)
**Customize colors for a bar chart**
The [SymbolRendering](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html") event customizes the fill and stroke colors of individual columns in a bar chart. The handler sets the color based on the data item at the current index.

1. Attach the [SymbolRendering](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html") event to the series.

```auto
customSeries.Name = "Shipments";

// Call the rendering event from the series instance
customSeries.SymbolRendering += VendorSeries_SymbolRendering;
flexChart1.Series.Add(customSeries);
```

2\. Handle the [SymbolRendering](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html") event.

```auto
private void VendorSeries_SymbolRendering(object sender, RenderSymbolEventArgs e)
{
    using var fillBrush = new SolidBrush(vendors.ElementAt(e.Index).Color);
    using var strokeBrush = new SolidBrush(Color.FromArgb(200, vendors.ElementAt(e.Index).Color));
    e.Engine.SetFill(fillBrush);
    e.Engine.SetStroke(strokeBrush);
}
```

3\. Define the data class and sample data\.

```auto
// Sample data used for the column 
List<SmartPhoneVendor> vendors = new List<SmartPhoneVendor>();

vendors.Add(new SmartPhoneVendor()
{
    Name = "Apple",
    Color = Color.FromArgb(136, 189, 230),
    Shipments = 215.2,
});
vendors.Add(new SmartPhoneVendor()
{
    Name = "Huawei",
    Color = Color.FromArgb(251, 178, 88),
    Shipments = 139,
});
```

![A bar chart showing smartphone vendor shipments, with each column filled in a distinct custom color.](https://cdn.mescius.io/document-site-files/images/13ef049a-dbc7-444f-94c2-9a9cd1c2f895/e77fb76a-96e8-4ff2-8507-06ae0ddbe812-20261123.aeb111.png?width=800)
**Customize colors for a scatter plot**
The [SymbolRendering](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html") event customizes the stroke and fill colors of points in a scatter plot.
The handler selects a color from a gradient based on the temperature value at the current index.

1. Attach the [SymbolRendering](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html") event to the series.

```auto
flexChart1.DataSource = records;
flexChart1.ChartType = ChartType.Scatter;
var recordsSeries = new SeriesWithPointLegendItems();

// Call the rendering event from the series instance
recordsSeries.SymbolRendering += RecordsSeries_SymbolRendering;
flexChart1.Series.Add(recordsSeries);
```

2\. Handle the [SymbolRendering](https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html "https://developer.mescius.com/componentone/api/win/online-flexchart/dotnet-api/C1.Win.FlexChart.10/C1.Win.Chart.Series.SymbolRendering.html") event.

```auto
// Symbol Rendering method
private void RecordsSeries_SymbolRendering(object sender, RenderSymbolEventArgs e)
{
  int idx = (((TemperatureRecord)e.Item).High - 95) / 5;
  using var fillBrush = new SolidBrush(GradientRedColors[idx]);
  using var strokeBrush = new SolidBrush(GradientRedColors[idx]);
  e.Engine.SetFill(fillBrush);
  e.Engine.SetStroke(strokeBrush);
}
```

3\. Define the data class\, sample data\, and color gradient\.

```auto
// Defines the red color gradient
private static readonly Color[] GradientRedColors = 
{
  Color.FromArgb(254, 224, 232),
  Color.FromArgb(252, 173, 193),
  Color.FromArgb(251, 121, 154),
  Color.FromArgb(249, 70, 115)
};

// Represents a temperature record.
public class TemperatureRecord
{
    public string Place { get; set; }
    public int High { get; set; }
}
```

![A scatter plot with points colored on a red gradient based on temperature values.](https://cdn.mescius.io/document-site-files/images/13ef049a-dbc7-444f-94c2-9a9cd1c2f895/c1e61340-eba6-401a-83d0-858219df6f35-20261123.cad6f7.png?width=800)

## See also

[Create Alarm Zone](https://developer.mescius.com/componentone/docs/win/online-flexchart/walkthroughs/zones "https://developer.mescius.com/componentone/docs/win/online-flexchart/walkthroughs/zones")