|
| 1 | +--- |
| 2 | +title: Transparent Filled Series Markers |
| 3 | +description: how to make semi-transparent chart series markers with solid fill |
| 4 | +type: how-to |
| 5 | +page_title: Transparent Filled Series Markers |
| 6 | +slug: chart-kb-transparent-marker |
| 7 | +position: |
| 8 | +tags: |
| 9 | +ticketid: 1452809 |
| 10 | +res_type: kb |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | +<table> |
| 15 | + <tbody> |
| 16 | + <tr> |
| 17 | + <td>Product</td> |
| 18 | + <td>Charts for Blazor</td> |
| 19 | + </tr> |
| 20 | + </tbody> |
| 21 | +</table> |
| 22 | + |
| 23 | + |
| 24 | +## Description |
| 25 | + |
| 26 | +I want semi-transparent solid marks, not fully opaque rings for the chart series markers. |
| 27 | + |
| 28 | + |
| 29 | +## Solution |
| 30 | + |
| 31 | +Use the `ColorField` so that the markers can inherit a custom color from the data source of the chart, and add an `rgba` color there so it can have opacity. |
| 32 | + |
| 33 | +To remove the blank (white) space at the core of the circle, triangle and square marker, increase the border width of the marker, so it becomes a solid color. |
| 34 | + |
| 35 | +>caption Semi transparent markers in the chart that are solid (entirely filled with color) |
| 36 | +
|
| 37 | +````CSHTML |
| 38 | +@* Compare the two green markers on the right hand side - one has opacity, the other does not *@ |
| 39 | +
|
| 40 | +<TelerikChart Transitions="false"> |
| 41 | + <ChartSeriesItems> |
| 42 | + <ChartSeries Type="ChartSeriesType.Scatter" |
| 43 | + Data="@Series1Data" |
| 44 | + Name="APSK modulation" |
| 45 | + XField="@nameof(ModelData.Strength)" |
| 46 | + YField="@nameof(ModelData.Errors)" |
| 47 | + ColorField="@nameof(ModelData.ItemColor)"> |
| 48 | + <ChartSeriesMarkers Type="ChartSeriesMarkersType.Square"> |
| 49 | + <ChartSeriesMarkersBorder Width="8"></ChartSeriesMarkersBorder> @* increase the size of the border so it hildes the hole *@ |
| 50 | + </ChartSeriesMarkers> |
| 51 | + </ChartSeries> |
| 52 | + </ChartSeriesItems> |
| 53 | +</TelerikChart> |
| 54 | +
|
| 55 | +@code { |
| 56 | + public class ModelData |
| 57 | + { |
| 58 | + public double Strength { get; set; } |
| 59 | + public double Errors { get; set; } |
| 60 | + public string ItemColor { get; set; } |
| 61 | + } |
| 62 | +
|
| 63 | + public List<ModelData> Series1Data = new List<ModelData>() |
| 64 | + { |
| 65 | + new ModelData { Strength = -8, Errors = 5, ItemColor = "rgba(255, 0, 0, 0.3)" }, //opacity in the color field |
| 66 | + new ModelData { Strength = 7, Errors = 3, ItemColor = "rgba(0, 255, 0, 0.3)" }, |
| 67 | + new ModelData { Strength = -6, Errors = 1, ItemColor = "rgba(0, 0, 255, 0.3)" }, |
| 68 | + new ModelData { Strength = 6, Errors = 3, ItemColor = "#0f0" } // control item |
| 69 | + }; |
| 70 | +} |
| 71 | +```` |
0 commit comments