【发布时间】:2016-11-29 15:38:19
【问题描述】:
我一直在我的 Xamarin.ios 和 Xamarin.Android 项目中使用 OxyPlot 来绘制柱形图。这就是我使用 oxyplot 绘制柱形图的方式。
现在我需要一个堆积柱形图。我在文档中找不到它。 oxyplot可以吗?如何?任何帮助表示赞赏..
public class MeasurementGraph
{
public PlotModel VitalModel { get; set; }
public VitalGraph graph { get; set; }
public MeasurementGraph (VitalGraph graph)
{
this.graph = graph;
var model = new PlotModel { Title = "" };
model.PlotAreaBorderColor = OxyColors.Transparent;
model.Axes.Add (GetXAxis ());
model.Axes.Add (GetYAxis ());
model.Series.Add (GetValueSeries ());
if (Math.Abs (graph.trendStart) > float.Epsilon && Math.Abs (graph.trendEnd) > float.Epsilon)
model.Series.Add (GetXtraSeries ());
VitalModel = model;
}
CategoryAxis GetXAxis ()
{
int fontSize;
if (Math.Abs (graph.trendStart) > float.Epsilon)
fontSize = 6;
else
fontSize = 8;
CategoryAxis categoryAxis = new CategoryAxis () {
Position = AxisPosition.Bottom,
MinorTickSize = 0,
MajorTickSize = 0,
MajorGridlineStyle = LineStyle.None,
MinorGridlineStyle = LineStyle.None,
FontSize = fontSize,
IsPanEnabled = false,
IsZoomEnabled = false,
};
foreach (string day in graph.dayList)
categoryAxis.ActualLabels.Add (day);
return categoryAxis;
}
LinearAxis GetYAxis ()
{
List<float> valueList = graph.valueList.Select (x => float.Parse (x)).ToList ();
float maxValue = valueList.Max ();
float minValue = valueList.Max ();
return new LinearAxis () {
AxislineStyle = LineStyle.None,
Position = AxisPosition.Left,
MinorTickSize = 0,
MajorTickSize = 0,
MajorGridlineStyle = LineStyle.Solid,
MajorGridlineColor = OxyColor.Parse ("#f5f5f5"),
MinorGridlineStyle = LineStyle.None,
Maximum = maxValue,
Minimum = minValue,
FontSize = 8,
MajorStep = (maxValue - minValue) / 4,
IsPanEnabled = false,
IsZoomEnabled = false
};
}
ColumnSeries GetValueSeries ()
{
var series = new ColumnSeries ();
series.ColumnWidth = 50;
for (int i = 0; i < graph.valueList.Count; i++) {
series.Items.Add (new ColumnItem {
Value = double.Parse (graph.valueList [i]),
Color = OxyColor.Parse (graph.colorList [i])
});
}
return series;
}
LineSeries GetXtraSeries ()
{
var series = new LineSeries {
StrokeThickness = 2,
MarkerType = MarkerType.None,
MarkerSize = 4,
MarkerStroke = OxyColors.White,
MarkerStrokeThickness = 2,
Color = OxyColors.Blue
};
int xStart = graph.vitalId == 20 ? 0 : -1;
int xEnd = graph.vitalId == 20 ? graph.valueList.Count - 1 : graph.valueList.Count;
series.Points.Add (new DataPoint (xStart, graph.trendStart));
series.Points.Add (new DataPoint (xEnd, graph.trendEnd));
return series;
}
}
【问题讨论】:
-
您是否尝试过每个堆叠列使用 1 个系列?我的意思是,您可以重叠不同的列系列,较高的列在较低的后面。
-
我该怎么做?
标签: c# xaml xamarin charts oxyplot