Skip to content

Commit 362ec81

Browse files
Merge pull request #829 from beto-rodriguez/dev
beta 700
2 parents bd04814 + a10aa33 commit 362ec81

184 files changed

Lines changed: 5105 additions & 3152 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/cartesianChart/legends.md

Lines changed: 34 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -63,158 +63,61 @@ disable legends in a chart, default value is `Hidden`.
6363
</code></pre>
6464
{{~ end ~}}
6565

66-
## Styling legends
66+
# Customize default legends
6767

68-
{{~ if xaml ~}}
69-
A chart exposes many properties to quickly style a legend:
68+
You can quickly change the position, the font, the text size or the background color:
7069

71-
<pre><code>&lt;lvc:CartesianChart
72-
Series="{Binding Series}"
73-
LegendPosition="Left"
74-
LegendFontFamily="Courier New"
75-
LegendFontSize="25"
76-
LegendTextBrush="#f2f4c3"
77-
LegendBackground="#480032">
78-
&lt;/lvc:CartesianChart>
79-
</code></pre>
70+
{{~ if xaml ~}}
71+
{{~ render_params_file_as_code this "~/../samples/$PlatformSamplesFolder/Axes/Multiple/$PlatformViewFile" ~}}
8072
{{~ end ~}}
8173

8274
{{~ if winforms ~}}
83-
A chart exposes many properties to quickly style a legend:
84-
85-
<pre><code>cartesianChart1.LegendPosition = LiveChartsCore.Measure.LegendPosition.Left;
86-
cartesianChart1.LegendFont = new System.Drawing.Font("Courier New", 25);
87-
cartesianChart1.LegendTextColor = System.Drawing.Color.FromArgb(255, 50, 50, 50);
88-
cartesianChart1.LegendBackColor = System.Drawing.Color.FromArgb(255, 250, 250, 250);</code></pre>
89-
{{~ end ~}}
90-
91-
{{~ if blazor ~}}
92-
You can use css to override the style of the tooltip.
93-
94-
<pre><code>&lt;style>
95-
/*
96-
You can also use css to override the styles.
97-
*/
98-
99-
.lvc-legend {
100-
background-color: #fafafa !important;
101-
}
102-
103-
.lvc-legend-item {
104-
font-family: SFMono-Regular,Menlo,Monaco,Consolas !important;
105-
color: #808080 !important;
106-
}
107-
&lt;/style></code></pre>
75+
{{~ render_params_file_as_code this "~/../samples/WinFormsSample/Axes/Multiple/View.cs" ~}}
10876
{{~ end ~}}
10977

110-
The code above would result in the following legend:
111-
112-
![custom]({{ assets_url }}/docs/_assets/legend-custom-style.png)
113-
114-
## Custom template
115-
116-
{{~ if xaml || blazor ~}}
117-
If you need to customize more, you can also use the create your own template:
118-
{{~ end ~}}
119-
120-
{{~ if avalonia ~}}
121-
{{~ "~/../samples/AvaloniaSample/General/TemplatedLegends/View.axaml" | render_file_as_code ~}}
122-
123-
:::tip
124-
You can find another example at the source code of the `DefaultLegend` class
125-
([xaml](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/DefaultLegend.axaml),
126-
[code](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/DefaultLegend.axaml.cs)).
127-
:::
128-
78+
{{~ if eto ~}}
79+
{{~ render_params_file_as_code this "~/../samples/EtoFormsSample/Axes/Multiple/View.cs" ~}}
12980
{{~ end ~}}
13081

13182
{{~ if blazor ~}}
132-
{{~ "~/../samples/BlazorSample/Pages/General/TemplatedLegends.razor" | render_file_as_code ~}}
133-
134-
:::tip
135-
You can find another example at the source code of the `DefaultLegend` class
136-
([view](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/DefaultLegend.razor),
137-
[code](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/DefaultLegend.razor.cs)).
138-
:::
139-
83+
{{~ render_params_file_as_code this "~/../samples/BlazorSample/Pages/Axes/Multiple.razor" ~}}
14084
{{~ end ~}}
14185

142-
{{~ if maui ~}}
143-
{{~ "~/../samples/MauiSample/General/TemplatedLegends/View.xaml" | render_file_as_code ~}}
86+
## View model
14487

145-
:::tip
146-
You can find another example at the source code of the `DefaultLegend` class
147-
([xaml](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/DefaultLegend.xaml),
148-
[code](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/DefaultLegend.xaml.cs)).
149-
:::
150-
151-
{{~ end ~}}
152-
153-
{{~ if uno || unowinui ~}}
154-
{{~ "~/../samples/UnoSample/UnoSample.Shared/LiveChartsSamples/General/TemplatedLegends/View.xaml" | render_file_as_code ~}}
155-
156-
:::tip
157-
You can find another example at the source code of the `DefaultLegend` class
158-
([xaml](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/DefaultLegend.xaml),
159-
[code](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/DefaultLegend.xaml.cs)).
160-
:::
161-
162-
{{~ end ~}}
163-
164-
{{~ if winforms ~}}
165-
You can create your own legend control, the key is that your control must implement `IChartLegend<SkiaSharpDrawingContext>` and then
166-
you have to create a new instance of that control when your chart initializes.
167-
168-
Add a new form to your app named `CustomLegend`, then change the code behind as follows:
169-
170-
{{~ "~/../samples/WinFormsSample/General/TemplatedLegends/CustomLegend.cs" | render_file_as_code ~}}
171-
172-
Your legend is ready to be used, now when you create a chart, we have to pass a new instance of the tooltip we just created.
173-
174-
<pre><code>var cartesianChart = new CartesianChart(legend: new CustomLegend())
88+
```c#
89+
[ObservableObject]
90+
public partial class ViewModel
17591
{
176-
Series = viewModel.Series
177-
};</code></pre>
178-
179-
:::tip
180-
You can find another example at the source code of the `DefaultLegend` class
181-
([xaml](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/DefaultLegend.axaml.cs),
182-
[code](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/DefaultLegend.axaml.cs)).
183-
:::
184-
185-
{{~ end ~}}
92+
public ISeries[] Series { get; set; } = { ... };
93+
public Axis[] YAxes { get; set; } = { ... };
18694

187-
{{~ if winui ~}}
188-
{{~ "~/../samples/WinUISample/WinUISample/General/TemplatedLegends/View.xaml" | render_file_as_code ~}}
95+
public SolidColorPaint LegendTextPaint { get; set; } = // mark
96+
new SolidColorPaint // mark
97+
{ // mark
98+
Color = new SKColor(50, 50, 50), // mark
99+
SKTypeface = SKTypeface.FromFamilyName("Courier New") // mark
100+
}; // mark
189101
190-
:::tip
191-
You can find another example at the source code of the `DefaultLegend` class
192-
([xaml](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpVew.WinUI/DefaultLegend.xaml),
193-
[code](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpVew.WinUI/DefaultLegend.xaml.cs)).
194-
:::
102+
public SolidColorPaint LedgendBackgroundPaint { get; set; } = // mark
103+
new SolidColorPaint(new SKColor(240, 240, 240)); // mark
104+
}
105+
```
195106

196-
{{~ end ~}}
107+
![custom]({{ assets_url }}/docs/_assets/legend-custom-style.png)
197108

198-
{{~ if wpf ~}}
199-
{{~ "~/../samples/WPFSample/General/TemplatedLegends/View.xaml" | render_file_as_code ~}}
109+
## Tooltip control from scratch
200110

201-
:::tip
202-
You can find another example at the source code of the `DefaultLegend` class
203-
([xaml](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/DefaultLegend.xaml),
204-
[code](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/DefaultLegend.xaml.cs)).
205-
:::
111+
You can also create your own legend, the recommended way is to use the LiveCharts API (example bellow) but you can
112+
use anything as tooltip as soon as it implements the `IChartLegend<T>` interface. At the following example we build
113+
a custom control to render legends in our charts using the LiveCharts API.
206114

207-
{{~ end ~}}
115+
## CustomLegend.cs
208116

209-
{{~ if xamarin ~}}
210-
{{~ "~/../samples/XamarinSample/XamarinSample/XamarinSample/General/TemplatedLegends/View.xaml" | render_file_as_code ~}}
117+
{{~ render_params_file_as_code this "~/../samples/ViewModelsSamples/General/TemplatedLegends/CustomLegend.cs" ~}}
211118

212-
:::tip
213-
You can find another example at the source code of the `DefaultLegend` class
214-
([xaml](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/DefaultLegend.xaml),
215-
[code](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/DefaultLegend.xaml.cs)).
216-
:::
119+
## View
217120

218-
{{~ end ~}}
121+
{{~ render_params_file_as_code this "~/../samples/$PlatformSamplesFolder/General/TemplatedLegends/$PlatformViewFile" ~}}
219122

220-
![custom tooltip]({{ assets_url }}/docs/_assets/legend-custom-template.png)
123+
![custom tooltip]({{ assets_url }}/docs/_assets/legend-custom-template.png)

docs/cartesianChart/tooltips.md

Lines changed: 37 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -189,153 +189,64 @@ new ColumnSeries&lt;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>&lt;lvc:CartesianChart
198-
Series="{Binding Series}"
199-
TooltipPosition="Left"
200-
TooltipFontFamily="Courier New"
201-
TooltipFontSize="25"
202-
TooltipTextBrush="#f2f4c3"
203-
TooltipBackground="#480032">
204-
&lt;/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>&lt;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-
&lt;/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

Comments
 (0)