@@ -189,153 +189,64 @@ new ColumnSeries<ObservablePoint>
189189 (chartPoint) => $"Sales at this moment: {chartPoint.PrimaryValue:C2}"
190190}</code ></pre >
191191
192- ## Styling tooltips
192+ # Customize default tooltips
193193
194- {{~ if xaml ~ }}
195- A chart exposes many properties to quickly style a tooltip:
196-
197- <pre ><code >< ; lvc:CartesianChart
198- Series="{Binding Series}"
199- TooltipPosition="Left"
200- TooltipFontFamily="Courier New"
201- TooltipFontSize="25"
202- TooltipTextBrush="#f2f4c3"
203- TooltipBackground="#480032">
204- < ; /lvc:CartesianChart></code ></pre >
205- {{~ end ~ }}
194+ You can quickly change the position, the font, the text size or the background color:
206195
207- {{~ if winforms ~ }}
208- A chart exposes many properties to quickly style a tooltip:
209-
210- <pre ><code >cartesianChart1.TooltipPosition = LiveChartsCore.Measure.TooltipPosition.Left;
211- cartesianChart1.TooltipFont = new System.Drawing.Font("Courier New", 25);
212- cartesianChart1.TooltipTextColor = System.Drawing.Color.FromArgb(255, 242, 244, 195);
213- cartesianChart1.TooltipBackColor = System.Drawing.Color.FromArgb(255, 72, 0, 50);</code ></pre >
214- {{~ end ~ }}
196+ ## View
215197
216- {{~ if blazor ~ }}
217- You can use css to override the style of the tooltip.
218-
219- <pre ><code >< ; style>
220- .lvc-tooltip {
221- background-color: #480032 !important;
222- }
223-
224- .lvc-tooltip-item {
225- font-family: SFMono-Regular, Menlo, Monaco, Consolas !important;
226- color: #F2F4C3 !important;
227- }
228- < ; /style></code ></pre >
198+ {{~ if xaml ~ }}
199+ {{~ render_params_file_as_code this "~ /../samples/$PlatformSamplesFolder/Axes/NamedLabels/$PlatformViewFile" ~ }}
229200{{~ end ~ }}
230201
231- The code above would result in the following tooltip:
232-
233- ![ zooming] ({{ assets_url }}/docs/_ assets/tooltip-custom-style.png)
234-
235- ## Custom template
236-
237- {{~ if xaml || blazor ~ }}
238- If you need to customize more, you can also pass your own template:
202+ {{~ if winforms ~ }}
203+ {{~ render_params_file_as_code this "~ /../samples/WinFormsSample/Axes/NamedLabels/View.cs" ~ }}
239204{{~ end ~ }}
240205
241- {{~ if avalonia ~ }}
242- {{~ "~ /../samples/AvaloniaSample/General/TemplatedTooltips/View.axaml" | render_file_as_code ~ }}
243-
244- ::: tip
245- You can find a another example at the source code of the ` DefaultTooltip ` class
246- ([ xaml] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/DefaultTooltip.axaml ) ,
247- [ code] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/DefaultTooltip.axaml.cs ) ).
248- :::
249-
206+ {{~ if eto ~ }}
207+ {{~ render_params_file_as_code this "~ /../samples/EtoFormsSample/Axes/NamedLabels/View.cs" ~ }}
250208{{~ end ~ }}
251209
252210{{~ if blazor ~ }}
253- {{~ "~ /../samples/BlazorSample/Pages/General/TemplatedTooltips.razor" | render_file_as_code ~ }}
254-
255- ::: tip
256- You can find a another example at the source code of the ` DefaultTooltip ` class
257- ([ view] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/DefaultTooltip.razor ) ,
258- [ code] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/DefaultTooltip.razor.cs ) ).
259- :::
260-
211+ {{~ render_params_file_as_code this "~ /../samples/BlazorSample/Pages/Axes/NamedLabels.razor" ~ }}
261212{{~ end ~ }}
262213
263- {{~ if maui ~ }}
264- {{~ "~ /../samples/MauiSample/General/TemplatedTooltips/View.xaml" | render_file_as_code ~ }}
265-
266- ::: tip
267- You can find a another example at the source code of the ` DefaultTooltip ` class
268- ([ xaml] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/DefaultTooltip.xaml ) ,
269- [ code] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/DefaultTooltip.xaml.cs ) ).
270- :::
214+ ## View model
271215
272- {{~ end ~ }}
273-
274- {{~ if uno || unowinui ~ }}
275- {{~ "~ /../samples/UnoSample/UnoSample.Shared/LiveChartsSamples/General/TemplatedTooltips/View.xaml" | render_file_as_code ~ }}
276-
277- ::: tip
278- You can find a another example at the source code of the ` DefaultTooltip ` class
279- ([ xaml] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/DefaultTooltip.xaml ) ,
280- [ code] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/DefaultTooltip.xaml.cs ) ).
281- :::
282-
283- {{~ end ~ }}
284-
285- {{~ if winforms ~ }}
286- You can create your own tooltip control, the key is that your control must implement ` IChartTooltip<SkiaSharpDrawingContext> ` and then
287- you have to create a new instance of that control when your chart initializes.
288-
289- Add a new form to your app named ` CustomTooltip ` , then change the code behind as follows:
290-
291- {{~ "~ /../samples/WinFormsSample/General/TemplatedTooltips/CustomTooltip.cs" | render_file_as_code ~ }}
292-
293- Your tooltip is ready to be used, now when you create a chart, we have to pass a new instance of the tooltip we just created.
294-
295- <pre ><code >var cartesianChart = new CartesianChart(tooltip: new CustomTooltip())
216+ ``` c#
217+ [ObservableObject ]
218+ public partial class ViewModel
296219{
297- Series = viewModel.Series
298- };</code ></pre >
220+ public ISeries [] Series { get ; set ; } = { .. . };
221+ public Axis [] XAxes { get ; set ; } = { .. . };
222+ public Axis [] YAxes { get ; set ; } = { .. . };
299223
300- ::: tip
301- You can find a another example at the source code of the ` DefaultTooltip ` class
302- ([ xaml] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/DefaultTooltip.axaml.cs ) ,
303- [ code] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/DefaultTooltip.axaml.cs ) ).
304- :::
224+ public SolidColorPaint TooltipTextPaint { get ; set ; } = // mark
225+ new SolidColorPaint // mark
226+ { // mark
227+ Color = new SKColor (242 , 244 , 195 ), // mark
228+ SKTypeface = SKTypeface .FromFamilyName (" Courier New" ) // mark
229+ }; // mark
305230
306- {{~ end ~ }}
231+ public SolidColorPaint TooltipBackgroundPaint { get ; set ; } = // mark
232+ new SolidColorPaint (new SKColor (72 , 0 , 50 )); // mark
233+ }
234+ ```
307235
308- {{~ if winui ~ }}
309- {{~ "~ /../samples/WinUISample/WinUISample/General/TemplatedTooltips/View.xaml" | render_file_as_code ~ }}
236+ ![ image] ({{ assets_url }}/docs/samples/general/customTooltips/styling-tooltips.png)
310237
311- ::: tip
312- You can find a another example at the source code of the ` DefaultTooltip ` class
313- ([ xaml] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpVew.WinUI/DefaultTooltip.xaml ) ,
314- [ code] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpVew.WinUI/DefaultTooltip.xaml.cs ) ).
315- :::
238+ ## Custom tooltip control
316239
317- {{~ end ~ }}
240+ You can also create your own tooltip, the recommended way is to use the LiveCharts API (example bellow) but you can
241+ use anything as tooltip as soon as it implements the ` IChartTooltip<T> ` interface. In the following example we build
242+ a custom control to render tooltips in out charts using the LiveCharts API.
318243
319- {{~ if wpf ~ }}
320- {{~ "~ /../samples/WPFSample/General/TemplatedTooltips/View.xaml" | render_file_as_code ~ }}
244+ ## CustomTooltip.cs
321245
322- ::: tip
323- You can find a another example at the source code of the ` DefaultTooltip ` class
324- ([ xaml] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/DefaultTooltip.xaml ) ,
325- [ code] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/DefaultTooltip.xaml.cs ) ).
326- :::
246+ {{~ render_params_file_as_code this "~ /../samples/ViewModelsSamples/General/TemplatedTooltips/CustomTooltip.cs" ~ }}
327247
328- {{~ end ~ }}
329-
330- {{~ if xamarin ~ }}
331- {{~ "~ /../samples/XamarinSample/XamarinSample/XamarinSample/General/TemplatedTooltips/View.xaml" | render_file_as_code ~ }}
248+ ## View
332249
333- ::: tip
334- You can find a another example at the source code of the ` DefaultTooltip ` class
335- ([ xaml] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/DefaultTooltip.xaml ) ,
336- [ code] ( https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/DefaultTooltip.xaml.cs ) ).
337- :::
338-
339- {{~ end ~ }}
250+ {{~ render_params_file_as_code this "~ /../samples/$PlatformSamplesFolder/General/TemplatedTooltips/$PlatformViewFile" ~ }}
340251
341- ![ custom tooltip] ({{ assets_url }}/docs/_ assets/tooltip-custom-template.png)
252+ ![ custom tooltip] ({{ assets_url }}/docs/_ assets/tooltip-custom-template.png)
0 commit comments