@@ -68,9 +68,9 @@ the `TempSample` class by setting a Mapper or implementing `IChartEntity` in our
6868
6969## Mappers
7070
71- Mappers are the easiest way but has a performance cost, a mapper is a method that takes both the ` instance `
72- (each ` TempSample ` in our data collection) and the ` point ` (that LiveCharts assigned) as parameters, inside this function we must
73- specify the X and Y coordinates in our chart.
71+ Mappers are the easiest way but has a performance cost, a mapper is a function that takes both: the ` instance `
72+ (each ` TempSample ` in our data collection) and the ` index ` of the instance in the collection as parameters,
73+ and returns a ` Coordinate ` in the chart.
7474
7575``` c#
7676using var streamReader = new StreamReader (" data.json" );
@@ -86,15 +86,9 @@ var chart = new SKCartesianChart
8686 new LineSeries <TempSample >
8787 {
8888 Values = samples ,
89- Mapping = (sample , chartPoint ) => // mark
90- { // mark
91- // use the Temperature property in the Y axis // mark
92- // and the Time property in the X axis // mark
93- chartPoint .Coordinate = new (sample .Time , sample .Temperature );
94-
95- // sometimes it is useful to use the index of the instance in the array as the X coordinate: // mark
96- // chartPoint.SecondaryValue = chartPoint.Index; // mark
97- } // mark
89+ // use the Temperature property in the Y axis // mark
90+ // and the Time property in the X axis // mark
91+ Mapping = (sample , index ) => new (sample .Time , sample .Temperature ) // mark
9892 }
9993 },
10094 XAxes = new [] { new Axis { Labeler = value => $" {value } seconds" } },
@@ -108,19 +102,14 @@ Now it works! You can also register the mapper globally, this means that every t
108102chart all over our application, the library will use the mapper we indicated.
109103
110104``` c#
111- // ideally this code must be placed where your application or view starts
105+ // ideally this code must be placed where your application starts
112106LiveCharts .Configure (config =>
113- config
114- .HasMap <TempSample >(
115- (sample , chartPoint ) =>
116- {
117- chartPoint .PrimaryValue = sample .Temperature ;
118- chartPoint .SecondaryValue = sample .Time ;
119- }));
107+ config .HasMap <TempSample >(
108+ (sample , index ) => new (sample .Time , sample .Temperature ));
120109```
121110
122111Global mappers are unique for a type , this means that every time a `TempSample ` instance is in a chart , LiveCharts will use this mapper ,
123- if You register again a global mapper for the ` TempSample ` class, then the previous will be replaced by the new one.
112+ if you register again a global mapper for the `TempSample ` class , then the previous will be replaced by the new one .
124113If the series specifies the `Mapping ` property , then the global mapper will be ignored and instead it will use the series instance mapper .
125114
126115< a href = " https://github.com/beto-rodriguez/LiveCharts2/blob/master/samples/MappersSamples/Program.cs" class = " btn btn-light btn-lg text-primary shadow-sm mb-3" >
@@ -129,8 +118,9 @@ If the series specifies the `Mapping` property, then the global mapper will be i
129118
130119## IChartEntity
131120
132- The ` IChartEntity ` interface force our points to have a [ Coordinate] ( https://lvcharts.com/api/2.0.0-beta.710/LiveChartsCore.Kernel.Coordinate ) , LiveCharts will use this property to build the plot, when the interface is implemented correctly, you will notice a considerable
133- performance improvement, specially in large data sets.
121+ The `IChartEntity ` interface forces our points to have a [Coordinate ](https :// lvcharts.com/api/2.0.0-beta.710/LiveChartsCore.Kernel.Coordinate),
122+ LiveCharts will use this property to build the plot , when the interface is implemented correctly , you will notice a considerable
123+ performance improvement , specially on large data sets .
134124
135125Imagine the same case we used in the previous sample where we have a json file that contains the temperature of a CPU at a given time ,
136126we want to build a chart with that data .
0 commit comments