Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms 表单:在条形图布局中放置标签_Xamarin.forms_Oxyplot - Fatal编程技术网

Xamarin.forms 表单:在条形图布局中放置标签

Xamarin.forms 表单:在条形图布局中放置标签,xamarin.forms,oxyplot,Xamarin.forms,Oxyplot,我正在使用oxyplot绘制条形图。我想在图表中添加一个额外的标签。我尝试使用Textannotation,但它没有显示在图表上。我犯了什么错误导致文本不出现,是数据点吗?请帮忙 plotModel = new PlotModel { Title = "Daily", LegendPlacement = LegendPlacement.Outside, LegendPositi

我正在使用oxyplot绘制条形图。我想在图表中添加一个额外的标签。我尝试使用Textannotation,但它没有显示在图表上。我犯了什么错误导致文本不出现,是数据点吗?请帮忙

plotModel = new PlotModel
            {
                Title = "Daily",
                LegendPlacement = LegendPlacement.Outside,
                LegendPosition = LegendPosition.BottomCenter,
                LegendOrientation = LegendOrientation.Horizontal,
                LegendBorderThickness = 0
            };

            TextAnnotation txtlabel = new TextAnnotation();
            txtlabel.Text = "Test";
            txtlabel.TextColor = OxyColors.Red;
            txtlabel.Stroke = OxyColors.Red;
            txtlabel.StrokeThickness = 5;
            txtlabel.FontSize = 36;
            txtlabel.TextPosition = new DataPoint(21, 3.5);

            plotModel.Annotations.Add(txtlabel);

            string sPrevType = "";
            string sCurrentType = "";
            DateTime dtdate;

            var sr = new ColumnSeries();
            var col = new ColumnItem();
            int iCount = 0;
            List<decimal> lstI = new List<decimal>();
            List<decimal> lstD = new List<decimal>();
            List<decimal> lstS = new List<decimal>();

            foreach (var itm in _dateodr)
            {
                dtdate = itm.date;
                sCurrentType = itm.Type;
                lstI.Add(itm.I_Unit);
                lstD.Add(itm.D_Unit);
                lstS.Add(itm.S_Unit);
                if (sCurrentType != sPrevType && sPrevType != "")
                {
                    sr = new ColumnSeries();
                    sr.Title = sPrevType;
                    sr.LabelPlacement = LabelPlacement.Outside;
                    sr.StrokeColor = OxyColors.Black;
                    sr.StrokeThickness = 1;
                    //sr.LabelFormatString = "{0:#,##0.00}";
                    plotModel.Series.Add(sr);

                }
                sPrevType = sCurrentType;
                iCount += 1;
            }

            if (iCount == _dateodr.Count)
            {
                sr = new ColumnSeries();
                sr.Title = sPrevType;
                sr.LabelPlacement = LabelPlacement.Outside;
                sr.StrokeColor = OxyColors.Black;
                sr.StrokeThickness = 1;
                //sr.LabelFormatString = "{0:#,##0.00}";
                sr.FontSize = 10;
                plotModel.Series.Add(sr);
            }

            for (int i = 0; i < iCount; i++)
            {
                ColumnSeries ssr = (ColumnSeries)plotModel.Series[i];
                var colIm = new ColumnItem();
                colIitm.Value = double.Parse(lstI[i].ToString()) / 1000;
                ssr.Items.Add(colIitm);

                var colDOitm = new ColumnItem();
                colDitm.Value = double.Parse(lstD[i].ToString()) / 1000;
                ssr.Items.Add(colDitm);

                var colSitm = new ColumnItem();
                colSitm.Value = double.Parse(lstS[i].ToString()) / 1000;
                ssr.Items.Add(colSitm);

            }


            categoryaxis.Labels.Add("I");
            categoryaxis.Labels.Add("Dr");
            categoryaxis.Labels.Add("Sr");


            switch (sUnitType)
            {
                case "2":
                    valueAxis = new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0, Title = "m", Angle = 90, FontWeight = FontWeights.Bold, FontSize = 15 };
                    break;

                case "qy":
                    valueAxis = new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0, Title = "Qy", Angle = 90, FontWeight = FontWeights.Bold, FontSize = 15 };
                    break;

                case "Am":
                    valueAxis = new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0, Title = "Am", Angle = 90, FontWeight = FontWeights.Bold, FontSize = 15 };
                    break;
            }

            plotModel.Axes.Add(categoryaxis);
            plotModel.Axes.Add(valueAxis);

        }


        PlotView plot = new PlotView
        {
            VerticalOptions = LayoutOptions.Fill,
            HorizontalOptions = LayoutOptions.Fill,
            BackgroundColor = Color.White,
            Model = plotModel
        };


        Content = plot;
plotModel=新的plotModel
{
Title=“每日”,
LegendPlacement=LegendPlacement.Outside,
LegendPosition=LegendPosition.BottomCenter,
LegenOrientation=LegenOrientation.水平,
LegendBorderThickness=0
};
TextAnnotation txtlabel=新建TextAnnotation();
txtlab.Text=“测试”;
txtlab.TextColor=OxyColors.Red;
txtlab.Stroke=OxyColors.Red;
txtlab.StrokeThickness=5;
txtlab.FontSize=36;
txtlab.TextPosition=新数据点(21,3.5);
plotModel.Annotations.Add(txtlab);
字符串sPrevType=“”;
字符串sCurrentType=“”;
日期时间;
var sr=新的ColumnSeries();
var col=新的ColumnItem();
int-iCount=0;
List lstI=新列表();
List lstD=新列表();
List lstS=新列表();
foreach(日期中的var itm)
{
dtdate=itm.date;
sCurrentType=itm.Type;
lstI.Add(itm.I_单位);
lstD.Add(itm.D_单位);
lstS.Add(itm.S_单位);
如果(sCurrentType!=sPrevType&&sPrevType!=“”)
{
sr=新列系列();
高级职称=sPrevType;
sr.LabelPlacement=LabelPlacement.Outside;
sr.StrokeColor=氧色。黑色;
sr.StrokeThickness=1;
//sr.LabelFormatString=“{0:#,###0.00}”;
plotModel.Series.Add(sr);
}
sPrevType=sCurrentType;
i计数+=1;
}
if(iCount==\u dateodr.Count)
{
sr=新列系列();
高级职称=sPrevType;
sr.LabelPlacement=LabelPlacement.Outside;
sr.StrokeColor=氧色。黑色;
sr.StrokeThickness=1;
//sr.LabelFormatString=“{0:#,###0.00}”;
sr.FontSize=10;
plotModel.Series.Add(sr);
}
for(int i=0;i
我回答了一个类似的问题,看看它是否对您有帮助。嗨,jstreet,我试过了,但没有显示出来。我没有尝试数据点,但运气不好。尝试将注释放置在X轴和Y轴现有点内的数据点中。嗨,jstreet,我如何将数据点放置在X轴和Y轴内?不,相反。比如说,在你的图表中,你的X从0到10,Y从0到100。将注释放置在X=5和Y=50处。我回答了一个类似的问题,看看它是否对您有帮助。嗨,jstreet,我试过了,但没有显示出来。我没有尝试数据点,但运气不好。尝试将注释放置在X轴和Y轴现有点内的数据点中。嗨,jstreet,我如何将数据点放置在X轴和Y轴内?不,相反。比如说,在你的图表中,你的X从0到10,Y从0到100。将注释放置在X=5和Y=50处。