I'm using MicroCharts barChart
<forms:ChartView x:Name="chart1" HeightRequest="150">
I read a list of data from Api. I need to show the data grouped by parameter year(i read from every object from the list) and have 3 values for every year to show. Similar like this example:
private PlotView _opv = new PlotView();
MessagingCenter.Subscribe<Object, BindingList<Summary>>(this, "Sum", (args, list) =>
{
var plotModel = new PlotModel { Title = "OxyPlot Demo" };
CategoryAxis xaxis = new CategoryAxis();
xaxis.Position = OxyPlot.Axes.AxisPosition.Bottom;
xaxis.MajorGridlineStyle = LineStyle.Solid;
xaxis.MinorGridlineStyle = LineStyle.Dot;
foreach (var el in list)
{
xaxis.Labels.Add(el.Year);
ColumnSeries s = new ColumnSeries();
s.IsStacked = false;
s.Items.Add(new ColumnItem((double)el.Plus));
s.Items.Add(new ColumnItem((double)el.Minus));
s.Items.Add(new ColumnItem((double)el.Sum));
plotModel.Series.Add(s);
s.ClearSelection();
}
plotModel.Axes.Add(xaxis);
plotModel.Axes.Add(new LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, Minimum = 0, Maximum = 10000000 });
_opv.Model = plotModel;
});
Content = _opv;
This is my code but not showing the true data Any suggestions?
if you want to achieve the effect above,you could consider using it OxyPlot.Xamarin.Forms
in your MainActivity
initialize after Xamarin.Forms.Forms.Init
:
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
OxyPlot.Xamarin.Forms.Platform.Android.PlotViewRenderer.Init();
in your page.xam.cs:
public class BarChar : ContentPage
{
private PlotView _opv = new PlotView();
public BarChar()
{
var plotModel = new PlotModel { Title = "OxyPlot Demo" };
CategoryAxis xaxis = new CategoryAxis();
xaxis.Position = AxisPosition.Bottom;
xaxis.MajorGridlineStyle = LineStyle.Solid;
xaxis.MinorGridlineStyle = LineStyle.Dot;
xaxis.Labels.Add("2/2010");
xaxis.Labels.Add("2/2011");
xaxis.Labels.Add("2/2012");
xaxis.Labels.Add("2/2013");
ColumnSeries s1 = new ColumnSeries();
s1.IsStacked = false;
s1.Items.Add(new ColumnItem(1.2));
s1.Items.Add(new ColumnItem(1.6));
s1.Items.Add(new ColumnItem(1.4));
s1.Items.Add(new ColumnItem(1.5));
ColumnSeries s2 = new ColumnSeries();
s2.IsStacked = false;
s2.Items.Add(new ColumnItem(1.5));
s2.Items.Add(new ColumnItem(1.6));
s2.Items.Add(new ColumnItem(1.1));
s2.Items.Add(new ColumnItem(1.2));
ColumnSeries s3 = new ColumnSeries();
s3.IsStacked = false;
s3.Items.Add(new ColumnItem(1.2));
s3.Items.Add(new ColumnItem(1.3));
s3.Items.Add(new ColumnItem(1.4));
s3.Items.Add(new ColumnItem(1.5));
ColumnSeries s4 = new ColumnSeries();
s4.IsStacked = false;
s4.Items.Add(new ColumnItem(1.5));
s4.Items.Add(new ColumnItem(1.4));
s4.Items.Add(new ColumnItem(1.3));
s4.Items.Add(new ColumnItem(1.2));
plotModel.Series.Add(s1);
plotModel.Series.Add(s2);
plotModel.Series.Add(s3);
plotModel.Series.Add(s4);
plotModel.Axes.Add(xaxis);
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 0, Maximum = 1.6 });
_opv.Model = plotModel;
Content = _opv;
}
}
I think this works only for android?
@VaskoJosifovski it also work for ios,you need call
OxyPlot.Xamarin.Forms.Platform.iOS.PlotViewRenderer.Init();
in ios project,you could read the documentCan u open chat to ask something
I edite my question
@VaskoJosifovskic have you get the correct data in messagingcenter