【发布时间】:2015-06-06 06:06:57
【问题描述】:
AutoScale OxyPlot 图表。 例如我有这样的东西。
using OxyPlot;
using OxyPlot.Axes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OxyPlot.Wpf;
using PlotControllerTest.Properties;
using System.Diagnostics;
namespace PlotControllerTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public class Chart
{
public PlotController myController { get; set; }
private OxyPlot.Series.LineSeries LS;
OxyPlot.Axes.LinearAxis LAY;
OxyPlot.Axes.LinearAxis LAX;
private int i = 0;
public PlotModel PlotModel {get;set;}
public Chart()
{
PlotModel = new PlotModel();
myController = new PlotController();
myController.UnbindAll();
myController.BindMouseDown(OxyMouseButton.Left, OxyPlot.PlotCommands.PanAt);
LS = new OxyPlot.Series.LineSeries();
LAY = new OxyPlot.Axes.LinearAxis()
{
Position = OxyPlot.Axes.AxisPosition.Left,
AbsoluteMaximum = 100,
AbsoluteMinimum = 1,
};
LAX = new OxyPlot.Axes.LinearAxis()
{
Position = OxyPlot.Axes.AxisPosition.Bottom,
AbsoluteMaximum = 200,
AbsoluteMinimum = 1,
MinorStep=5,
};
PlotModel.Series.Add(LS);
PlotModel.Axes.Add(LAY);
PlotModel.Axes.Add(LAX);
}
public void BeginAddPoints()
{
Random rnd = new Random();
do
{
int temp=rnd.Next(1, 100);
LS.Points.Add(new DataPoint( ++i,temp));
System.Threading.Thread.Sleep(100);
Update();
} while (i<30);
Update();
}
public void Update()
{
PlotModel.InvalidatePlot(true);
}
}
public partial class MainWindow : Window
{
Chart TChart;
delegate void BeginUpdate();
private Stopwatch stopwatch = new Stopwatch();
private long lastUpdateMilliSeconds;
public MainWindow()
{
TChart = new Chart();
BeginUpdate BU = new BeginUpdate(TChart.BeginAddPoints);
IAsyncResult result = BU.BeginInvoke(null,null);
DataContext = TChart;
CompositionTarget.Rendering += CompositionTargetRendering;
InitializeComponent();
}
private void CompositionTargetRendering(object sender, EventArgs e)
{
if (stopwatch.ElapsedMilliseconds > lastUpdateMilliSeconds + 300)
{
TChart.Update();
}
}
}
}
Xaml 代码的样子
<Window x:Class="PlotControllerTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:oxy="http://oxyplot.org/wpf"
Title="MainWindow" Height="350" Width="525">
<Grid>
<oxy:PlotView Model="{Binding PlotModel}" DefaultTrackerTemplate="{x:Null}" Controller="{Binding myController}"></oxy:PlotView>
</Grid>
Y轴拖拽后如何实现自动缩放?例如,当我在窗口中拖动图表时,只出现一条线((1,2),(4,4))。 Y 轴将显示 2 到 4。谢谢。
【问题讨论】:
-
我知道如何使用烛台系列但不使用线条系列。我缺少一种基于 x (1
-
我刚刚用你的代码创建了一个项目,我不确定你的拖动是什么意思。您的项目会自动调整 x 轴以显示从 0 到 max(x)(oxyplot 的本机函数),并且由于它在 y 轴上也是如此,因此您始终可以看到所有值。