我有一個包含動態資料的圖表。
所以我想當串列中的索引超過 20 時水平激活Scrollview并且我的圖表水平拉伸?
我的 .xaml 檔案如下所示:
<ScrollView>
<StackLayout>
<microcharts:ChartView x:Name="chartView"
HeightRequest="100"
BackgroundColor="#f7f77c"/>
</StackLayout>
</ScrollView>
我的帶有填充資料的 .cs 代碼如下所示:
List<Entry> entries = new List<Entry>();
for (int i = 0; i < result.Count - 1; i )
{
entries.Add(
new Entry((float)result[i].Stoej)
{
Color = SKColor.Parse("#FF1943"),
Label = result[i].D.ToString(),
ValueLabel = result[i].Stoej.ToString()
});
}
chartView.Chart = new LineChart()
{
Entries = entries,
LineMode = LineMode.Spline,
LineSize = 8,
PointMode = PointMode.Circle,
PointSize = 18,
LabelTextSize = 40,
BackgroundColor = SKColors.Transparent
};
更新:
我嘗試這樣,但圖表沒有水平拉伸:

uj5u.com熱心網友回復:
出現問題是因為寬度ChartView是固定的(等于螢屏寬度),我們需要在后面的代碼中手動設定寬度。
int itemWidth = 20; //define by you
chartView.WidthRequest = entries.Count * itemWidth;
并且不要忘記先設定scroll.Orientation="Horizontal"。

uj5u.com熱心網友回復:
您可以檢查您的串列是否 > 20 以啟用:
<ScrollView x:Name="scroll" isEnabled="false">
<StackLayout>
<microcharts:ChartView x:Name="chartView"
HeightRequest="100"
BackgroundColor="#f7f77c"/>
</StackLayout>
</ScrollView>
List<Entry> entries = new List<Entry>();
for (int i = 0; i < result.Count - 1; i )
{
entries.Add(
new Entry((float)result[i].Stoej)
{
Color = SKColor.Parse("#FF1943"),
Label = result[i].D.ToString(),
ValueLabel = result[i].Stoej.ToString()
});
}
if(entries.Count > 20)
{
scroll.IsEnabled = true;
scroll.HorizontalBarVisibility = Always;
}
或者自動讓滾動啟用,所以如果串列開始跳轉用戶設備螢屏,滾動將被調整。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/432714.html
