我有一个用户的血压数据,并希望使用Oxyplot进行绘图。有收缩压值,舒张压值和代表测试日期的日期。
我有点坚持如何在一个数据点中表示血压的2个值,而不是月变量,因为数据点只需要2个变量。
这是我的代码:
plotModel = new PlotModel { Title = "Blood Presure" };
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left,AbsoluteMaximum = 190, Maximum = 190,AbsoluteMinimum = 10, Minimum = 10, Title = "Diastolic" });
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom,AbsoluteMaximum = 12, Maximum = 12,AbsoluteMinimum = 1, Minimum = 1, MajorStep = 1, Title = "Month" });
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Top, AbsoluteMaximum = 190, Maximum = 190, AbsoluteMinimum = 10, Minimum = 10, Title = "Systolic" });
var series2 = new LineSeries
{
MarkerType = MarkerType.Circle,
MarkerSize = 4,
MarkerStroke = OxyColors.White
};
if (userInfo != null)
{
if (userInfo.Count > 0)
{
var counter = 0.00;
foreach (Info healthData in userInfo)
{
var bp = healthData.BloodPressure;
var date = healthData.CreatedDate;
var month = date.Month;
if (dateLabel != null)
{
dateLabel.Text = month.ToString();
}
// TODO Split this blood pressure value
var result = Regex.Split(bp,"/");
string systolicValue = null;
string diastolicValue = null;
if (result.Length > 1)
{
systolicValue = result[0];
diastolicValue = result[1];
}
series2.Points.Add(new DataPoint(month + counter, double.Parse(systolicValue)));
counter += 0.02;
}
如何在图表上最好地表示这些值? 这是我目前的图表屏幕截图:
答案 0 :(得分:1)
您的数据是三维的。您可以在3D图表上表示它们(只要我知道OxyPlot不支持)。另一种选择是绘制散点图并将其中一个尺寸显示为点的大小(和/或颜色):
//Data:
int n = 10;
var dia = new double[10] {1,3,3,4,4,2,4,5,6,4 };
var sys = new double[10] {2,2,2,4,5,3,4,4,5,6 };
var mon = Enumerable.Range(1, n).ToArray();
var model = new PlotModel { Title = "ScatterSeries" };
var scatterSeries = new OxyPlot.Series.ScatterSeries { MarkerType = MarkerType.Circle };
for (int i = 0; i < n; i++)
{
var x = mon[i];
var y = sys[i];
var size = dia[i];
scatterSeries.Points.Add(new OxyPlot.Series.ScatterPoint(x, y, size, size));
}
model.Series.Add(scatterSeries);
model.Axes.Add(new OxyPlot.Axes.LinearColorAxis { Position = OxyPlot.Axes.AxisPosition.Right, Palette = OxyPalettes.BlueWhiteRed(30) });
model.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom });
model.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left });
var plot = new OxyPlot.Wpf.PlotView() { Model = model };
this.Content = plot;
答案 1 :(得分:0)
我找到了一个更简单的解决方案,通过使用PointAnnotations
来捕获所有三组数据:
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left,AbsoluteMaximum = 190, Maximum = 190,AbsoluteMinimum = 70, Minimum = 70, Title = "Systolic" });
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, AbsoluteMaximum = 190, Maximum = 190, AbsoluteMinimum = 40, Minimum = 40, Title = "Diastolic" });
var series2 = new LineSeries
{
MarkerType = MarkerType.Circle,
MarkerSize = 4,
MarkerStroke = OxyColors.White
;
if (userInfo != null)
{
if (userInfo.Count > 0)
{
var counter = 0.00;
foreach (Info healthData in userInfo)
{
var bp = healthData.BloodPressure;
var date = healthData.CreatedDate;
var month = date.Month;
if (dateLabel != null)
{
dateLabel.Text = month.ToString();
}
// TODO Split this blood pressure value
var result = Regex.Split(bp,"/");
string systolicValue = null;
string diastolicValue = null;
if (result.Length > 1)
{
systolicValue = result[0];
diastolicValue = result[1];
}
series2.Points.Add(new DataPoint(double.Parse(diastolicValue), double.Parse(systolicValue)));
var pointAnnotation1 = new PointAnnotation();
pointAnnotation1.X = Convert.ToDouble(diastolicValue);
pointAnnotation1.Y = Convert.ToDouble(systolicValue);
pointAnnotation1.Text = String.Format("{0}",date.ToString("MM/dd/yyyy")); // I'm adding the date label here
plotModel.Annotations.Add(pointAnnotation1);
}
}
}
plotModel.Series.Add(series2);
下面是图表现在的样子