|
| 1 | +--- |
| 2 | +title: Set Specific Bubble Sizes |
| 3 | +description: Learn how to define bubble sizes in different Charts that users can compare more easily. |
| 4 | +type: how-to |
| 5 | +page_title: How to Set Specific Bubble Sizes |
| 6 | +slug: chart-kb-bubble-size |
| 7 | +tags: telerik, blazor, chart, bubble |
| 8 | +ticketid: 1693133 |
| 9 | +res_type: kb |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | + <tbody> |
| 16 | + <tr> |
| 17 | + <td>Product</td> |
| 18 | + <td>Chart for Blazor</td> |
| 19 | + </tr> |
| 20 | + </tbody> |
| 21 | +</table> |
| 22 | + |
| 23 | +## Description |
| 24 | + |
| 25 | +This KB answers the following questions: |
| 26 | + |
| 27 | +* How to display smaller bubbles for smaller values in a specific Telerik Blazor Chart instance? |
| 28 | +* How to help users compare bubble sizes for different data in different Charts? |
| 29 | +* How to display all bubbles with a specific defined `Size` value in certain dimensions? |
| 30 | +* How to use fixed bubble sizes instead of relative? |
| 31 | + |
| 32 | +## Solution |
| 33 | + |
| 34 | +The [Bubble Chart sets the minimum and maximum bubble sizes automatically](slug:components/chart/types/bubble#bubble-sizing), depending on the Chart dimensions, and the smallest and largest `Size` values in all series in the Chart instance. |
| 35 | + |
| 36 | +To display comparable bubble sizes in multiple Charts: |
| 37 | + |
| 38 | +1. Use an additional dummy data item with a `Size` value that matches the largest value in all involved Chart instances. |
| 39 | +1. Hide the dummy bubble: |
| 40 | + * Set the `Min` or `Max` parameter of `<ChartXAxis>` and `<ChartYAxis>`. |
| 41 | + * Position the bubble outside the visible Chart area (viewport). |
| 42 | + |
| 43 | +>caption Use comparable bubble sizes in several Charts |
| 44 | +
|
| 45 | +````RAZOR |
| 46 | +<h3>Hundreds</h3> |
| 47 | +
|
| 48 | +<p>An additional bubble with <code>Size</code> <strong>3000</strong> is positioned outside the visible Chart area.</p> |
| 49 | +
|
| 50 | +<TelerikChart Width="70vw" Height="35vh"> |
| 51 | + <ChartSeriesItems> |
| 52 | + <ChartSeries Type="ChartSeriesType.Bubble" |
| 53 | + Data="@SeriesData1" |
| 54 | + XField="@nameof(BubbleModel.X)" |
| 55 | + YField="@nameof(BubbleModel.Y)" |
| 56 | + SizeField="@nameof(BubbleModel.Size)"> |
| 57 | + </ChartSeries> |
| 58 | + </ChartSeriesItems> |
| 59 | + <ChartXAxes> |
| 60 | + <ChartXAxis Min="0" /> |
| 61 | + </ChartXAxes> |
| 62 | + <ChartYAxes> |
| 63 | + <ChartYAxis Min="0" /> |
| 64 | + </ChartYAxes> |
| 65 | + <ChartTooltip Visible="true" Shared="true"> |
| 66 | + <Template> |
| 67 | + @{ var dataItem = (BubbleModel)context.DataItem; } |
| 68 | + @dataItem.Size |
| 69 | + </Template> |
| 70 | + </ChartTooltip> |
| 71 | +</TelerikChart> |
| 72 | +
|
| 73 | +<h3>Thousands</h3> |
| 74 | +
|
| 75 | +<p>The max <code>Size</code> value is <strong>3000</strong>. This is the max value in all Charts and series, so there is no need for additional hidden bubbles.</p> |
| 76 | +
|
| 77 | +<TelerikChart Width="70vw" Height="35vh"> |
| 78 | + <ChartSeriesItems> |
| 79 | + <ChartSeries Type="ChartSeriesType.Bubble" |
| 80 | + Data="@SeriesData2" |
| 81 | + XField="@nameof(BubbleModel.X)" |
| 82 | + YField="@nameof(BubbleModel.Y)" |
| 83 | + SizeField="@nameof(BubbleModel.Size)"> |
| 84 | + </ChartSeries> |
| 85 | + </ChartSeriesItems> |
| 86 | + <ChartXAxes> |
| 87 | + <ChartXAxis Min="0" /> |
| 88 | + </ChartXAxes> |
| 89 | + <ChartYAxes> |
| 90 | + <ChartYAxis Min="0" /> |
| 91 | + </ChartYAxes> |
| 92 | + <ChartTooltip Visible="true" Shared="true"> |
| 93 | + <Template> |
| 94 | + @{ var dataItem = (BubbleModel)context.DataItem; } |
| 95 | + @dataItem.Size |
| 96 | + </Template> |
| 97 | + </ChartTooltip> |
| 98 | +</TelerikChart> |
| 99 | +
|
| 100 | +<h3>All Series in Same Chart</h3> |
| 101 | +
|
| 102 | +<p>There is no need for additional hidden bubbles.</p> |
| 103 | +
|
| 104 | +<TelerikChart Width="70vw" Height="35vh"> |
| 105 | + <ChartSeriesItems> |
| 106 | + <ChartSeries Type="ChartSeriesType.Bubble" |
| 107 | + Data="@SeriesData1.Take(SeriesData1.Count - 1)" |
| 108 | + XField="@nameof(BubbleModel.X)" |
| 109 | + YField="@nameof(BubbleModel.Y)" |
| 110 | + SizeField="@nameof(BubbleModel.Size)"> |
| 111 | + </ChartSeries> |
| 112 | + <ChartSeries Type="ChartSeriesType.Bubble" |
| 113 | + Data="@SeriesData2" |
| 114 | + XField="@nameof(BubbleModel.X)" |
| 115 | + YField="@nameof(BubbleModel.Y)" |
| 116 | + SizeField="@nameof(BubbleModel.Size)"> |
| 117 | + </ChartSeries> |
| 118 | + </ChartSeriesItems> |
| 119 | + <ChartTooltip Visible="true" Shared="true"> |
| 120 | + <Template> |
| 121 | + @{ var dataItem = (BubbleModel)context.DataItem; } |
| 122 | + @dataItem.Size |
| 123 | + </Template> |
| 124 | + </ChartTooltip> |
| 125 | +</TelerikChart> |
| 126 | +
|
| 127 | +@code { |
| 128 | + private List<BubbleModel> SeriesData1 = new List<BubbleModel>() { |
| 129 | + new BubbleModel() { X = 50, Y = 100, Size = 100 }, |
| 130 | + new BubbleModel() { X = 150, Y = 200, Size = 200 }, |
| 131 | + new BubbleModel() { X = 250, Y = 300, Size = 300 }, |
| 132 | +
|
| 133 | + // Size matches the max Size value in SeriesData2 |
| 134 | + new BubbleModel() { X = -100, Y = -100, Size = 3000 } |
| 135 | + }; |
| 136 | +
|
| 137 | + private List<BubbleModel> SeriesData2 = new List<BubbleModel>() { |
| 138 | + new BubbleModel() { X = 100, Y = 50, Size = 1000 }, |
| 139 | + new BubbleModel() { X = 200, Y = 150, Size = 2000 }, |
| 140 | + new BubbleModel() { X = 300, Y = 250, Size = 3000 } |
| 141 | + }; |
| 142 | +
|
| 143 | + public class BubbleModel |
| 144 | + { |
| 145 | + public int X { get; set; } |
| 146 | + public int Y { get; set; } |
| 147 | + public int Size { get; set; } |
| 148 | + } |
| 149 | +} |
| 150 | +```` |
| 151 | + |
| 152 | +## See Also |
| 153 | + |
| 154 | +* [Bubble Chart](slug:components/chart/types/bubble) |
0 commit comments