示例#1
0
 public void SetLegend()   // Called by LegendUpdate
 {
     KSeries[] legend = KChartHandler.Legend();
     guiControls.menuLegend.ClearMenuItems();
     for (int i = legend.Length - 1; i >= 0; i--)
     {
         KSeries series = legend[i]; // captured in the OnClick closure
         series.lineButton = guiControls.menuLegend.NewMenuSection(); series.lineButton.SetLegendImage(series);
         series.lineButton.OnClick((object s, EventArgs e) => { OnLegendClick(legend, series); });
         series.nameButton = guiControls.menuLegend.NewMenuItemButton(); series.nameButton.SetText(series.name);
         series.nameButton.OnClick((object s, EventArgs e) => { OnLegendClick(legend, series); });
         guiControls.menuLegend.AddMenuRow(new KButton[2] {
             series.lineButton, series.nameButton
         });                                                                                         //, pad });
     }
     guiControls.menuLegend.Open();
 }
示例#2
0
        const int LegendItemHeight = 21; // If this value is too small (for the font size?), Label items will flash a gray box for 2 senconds when updated

        public void SetLegend()
        {
            KSeries[] legend = KChartHandler.Legend();
            Xamarin.Forms.Device.BeginInvokeOnMainThread(() => {
                var legendList = new ObservableCollection <LegendItem>();
                for (int i = legend.Length - 1; i >= 0; i--)
                {
                    legendList.Add(new LegendItem {
                        Name   = legend[i].name,
                        Color  = SkiaSharp.Views.Forms.Extensions.ToFormsColor(legend[i].color),
                        Width  = (legend[i].visible) ? 50 : 6,
                        Height =
                            (legend[i].lineStyle == KLineStyle.Thick) ? 4  // show a wide bar for thick plot lines
                          : (legend[i].lineMode == KLineMode.Line) ? 1     // show a smaller bar for think plot lines
                          : LegendItemHeight,                              // show a full rectangle for Range areas
                    });
                }
                legendView.ItemsSource = legendList;
                MainTabbedPage.theChartPage.inspectionView.Children[0].HeightRequest = 40 + LegendItemHeight * (legend.Length + 1) / 2;  // seems redundant?
            });
        }