回复 2楼iceman的帖子
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 System.Collections;
using C1.WPF.C1Chart;
namespace ComponentOneTest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
c1Chart1.BeginUpdate();
int count = 3000;
DateTime[] x = new DateTime[count];
double[] y = new double[count];
for (int i = 0; i < count; i++)
{
x = DateTime.Now.AddMinutes(i);
y = i;
}
//X轴设为时间
c1Chart1.View.AxisX.IsTime = true;
c1Chart1.View.AxisX.MinorGridStroke = Brushes.Red;
c1Chart1.View.AxisX.MinorGridStrokeDashes = new DoubleCollection(3);
c1Chart1.View.AxisX.Scale = 1000;
// c1Chart1.View.AxisX.MajorUnit = .1;
c1Chart1.View.AxisX.MinorUnit = .01;
c1Chart1.View.AxisX.AnnoFormat = "MM-dd HH:MM:ss";
//添加数据
XYDataSeries ds = new XYDataSeries()
{
XValuesSource = x,
ValuesSource = y,
ConnectionStrokeThickness = 3,
Label = "hhh",
PointTooltipTemplate = (DataTemplate)Resources["lbl"],
};
c1Chart1.Data.Children.Add(ds);
c1Chart1.View.AxisX.ScrollBar = new AxisScrollBar();
c1Chart1.View.AxisY.ScrollBar = new AxisScrollBar();
c1Chart1.View.AxisY.MinScale = 0.01;
c1Chart1.View.AxisX.MinScale = 0.01;
//Marker
var pnl = new ChartPanel();
var obj = new ChartPanelObject()
{
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Bottom,
};
var bdr = new Border()
{
Background = new SolidColorBrush(Colors.Green) { Opacity = 0.4 },
BorderBrush = new SolidColorBrush(Colors.Green),
BorderThickness = new Thickness(1, 1, 3, 3),
CornerRadius = new CornerRadius(6, 6, 0, 6),
Padding = new Thickness(3)
};
var sp = new StackPanel();
var tb1 = new TextBlock();
var bind1 = new Binding();
bind1.Source = ds;
bind1.Path = new PropertyPath("XValuesSource");
tb1.SetBinding(TextBlock.TextProperty, bind1);
var tb2 = new TextBlock();
var bind2 = new Binding();
bind2.Source = obj;
bind2.StringFormat = "数据值={0:#.##}";
bind2.Path = new PropertyPath("DataPoint.Y");
tb2.SetBinding(TextBlock.TextProperty, bind2);
sp.Children.Add(tb1);
sp.Children.Add(tb2);
bdr.Child = sp;
obj.Content = bdr;
obj.DataPoint = new Point();
obj.Action = ChartPanelAction.MouseMove;
pnl.Children.Add(obj);
c1Chart1.View.Layers.Add(pnl);
//曲线类型
c1Chart1.ChartType = ChartType.Line;
c1Chart1.EndUpdate();
// c1Chart1.Actions.Add(new ZoomAction());
}
private void button1_Click(object sender, RoutedEventArgs e)
{
c1Chart1.View.AxisX.Scale = 1;
c1Chart1.View.AxisX.Value = 0.5;
c1Chart1.View.AxisY.Scale = 1;
c1Chart1.View.AxisY.Value = 0.5;
foreach (DataSeries ds in c1Chart1.Data.Children)
{
ds.PointLabelTemplate = null;
}
}
private void c1Chart1_MouseWheel(object sender, MouseWheelEventArgs e)
{
}
}
} |