c# - Xamarin.Forms: Putting A Label Inside A PieChart Layout -


good day. i'm creating xamarin.forms portable application able display there chart using oxyplot.

my problem how going put total sales label in there. because if put label in .xaml page, doesn't not appear.

i want put label there (inside red border).

enter image description here

what think should in order have this?

here's code:

salesviewmodel.cs

using oxyplot; using oxyplot.series; using system; using system.collections.generic; using system.componentmodel; using system.linq; using system.runtime.compilerservices; using system.text; using system.threading.tasks;   namespace xamarinformsdemo.viewmodels {     public class salesperproductviewmodel : inotifypropertychanged     {     private plotmodel modelp1;     public salesperproductviewmodel()     {         // pieviewmodel vm = new pieviewmodel();          modelp1 = new plotmodel         {             title = "sales per product",             titlecolor = oxycolors.teal,             titlefontsize = 30,             textcolor = oxycolors.white,             defaultfont = "arial black",             defaultfontsize = 20          };           dynamic seriesp1 = new pieseries { strokethickness = 2.0, insidelabelposition = 0.8, anglespan = 360, startangle = 0 };          seriesp1.slices.add(new pieslice("keyboard", 5900) { isexploded = false, fill = oxycolors.teal });         seriesp1.slices.add(new pieslice("monitor", 4430) { isexploded = true });         seriesp1.slices.add(new pieslice("flash drive", 11620) { isexploded = true });         seriesp1.slices.add(new pieslice("hard drive", 7000) { isexploded = true });         seriesp1.slices.add(new pieslice("ram", 8000) { isexploded = true });          modelp1.series.add(seriesp1);         this.salesperproductmodel = modelp1;      }      public plotmodel salesperproductmodel { get; private set; }        public event propertychangedeventhandler propertychanged;      protected void onpropertychanged([callermembername] string propertyname = null)     {         propertychanged?.invoke(this, new propertychangedeventargs(propertyname));     }      } } 

salesperproductpage.xaml

<?xml version="1.0" encoding="utf-8" ?> <contentpage xmlns="http://xamarin.com/schemas/2014/forms"          xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"          xmlns:oxy="clr-namespace:oxyplot.xamarin.forms;assembly=oxyplot.xamarin.forms"          xmlns:viewmodels="clr-namespace:xamarinformsdemo.viewmodels;assembly=xamarinformsdemo"          x:class="xamarinformsdemo.views.salesperproductpage"          backgroundimage="bg3.jpg"          title="sales per product">     <contentpage.bindingcontext>     <viewmodels:salesperproductviewmodel/>   </contentpage.bindingcontext>      <label text="total sales label here!"    textcolor="#24e97d"/>      <oxy:plotview model="{binding salesperproductmodel}" /> </contentpage> 

you can achieve using textannotation:

        list<tuple<string, int>> data = new list<tuple<string, int>>         {             new tuple<string, int>("product 1", 100),             new tuple<string, int>("product 2", 200),             new tuple<string, int>("product 3", 300),             new tuple<string, int>("product 4", 400),             new tuple<string, int>("product 5", 500),         };          pieseries pieseries = new pieseries();         pieseries.fontsize = 32;         pieseries.textcolor = oxycolors.white;         pieseries.insidelabelcolor = oxycolors.white;         pieseries.strokethickness = 2;          foreach (tuple<string, int> t in data)             pieseries.slices.add(new pieslice(t.item1, t.item2));          mymodel.series.add(pieseries);          mymodel.title = "sales per product";         mymodel.titlecolor = oxycolors.teal;         mymodel.titlefontsize = 36;          mymodel.axes.add(new linearaxis() { position = axisposition.bottom, isaxisvisible = false });         mymodel.axes.add(new linearaxis() { position = axisposition.left, isaxisvisible = false });          int total = data.sum(p => p.item2);          textannotation annotation = new textannotation();         annotation.text = string.format("{0:c2}", total);         annotation.textcolor = oxycolors.red;         annotation.stroke = oxycolors.red;         annotation.strokethickness = 5;         annotation.fontsize = 36;         annotation.textposition = new datapoint(15, 90);          mymodel.annotations.add(annotation); 

enter image description here


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -