Hi, i need help!
I get the top 5 peaks on the chart. Clicking on the item shows the tooltip.
When items are close together, it appears incorrect
Code:
float chartPointX = (float)ChartSF.ValueToPoint(ChartSF.PrimaryAxis, item.ValueX);
float chartPointY = (float)ChartSF.ValueToPoint(ChartSF.SecondaryAxis, item.ValueY);
tooltipBehavior.Show(chartPointX, chartPointY, true);
Hi!
I'm using the latest version and the problem remains.
Hi!
I'm currently only using Xamarin Forms on Android.
In iOs will be developing in the near future.
|
public class CustomLineSeries : Native.LineSeries
{
public CustomLineSeries()
{
}
int i = 0;
protected override Native.ChartSegment CreateSegment()
{
var segemnt = new CustomLineSegment();
i++;
return segemnt;
}
}
public class CustomLineSegment : Native.LineSegment
{
public CustomLineSegment()
{
}
protected override int HitTest(float valueX, float valueY)
{
if (IsRectContains(X1, Y1, valueX, valueY, Series.StrokeWidth))
{
return Series.Segments.IndexOf(this);
}
else if (Series.Segments.IndexOf(this) == Series.Segments.Count - 1 && IsRectContains(X2, Y2, valueX, valueY, Series.StrokeWidth))
{
return Series.Segments.IndexOf(this) + 1;
}
else
{
return -1;
}
}
internal static bool IsRectContains(float xPoint, float yPoint, float valueX, float valueY, float strokeWidth)
{
// here we find the position from 3pixel before and after the exact position
float depth = ((strokeWidth < 3) ? 3 : strokeWidth) * CustomChart.Density;
float x1 = xPoint - depth;
float y1 = yPoint - depth;
float x2 = xPoint + depth;
float y2 = yPoint + depth;
return x1 < valueX && valueX < x2 && y1 < valueY && valueY < y2;
}
}
|
|
<local:ChartExt VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" x:Name="chart">
. . .
<chart:SfChart.Series>
<local:LineSeriesExt x:Name="series"
EnableTooltip="True"
ItemsSource="{Binding Data}"
XBindingPath="XValue"
YBindingPath="YValue"/>
</chart:SfChart.Series>
<local:ChartExt.ChartBehaviors>
<chart:ChartTooltipBehavior x:Name="tooltip"/>
</local:ChartExt.ChartBehaviors>
</local:ChartExt > |