mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-20 00:16:36 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.SectionsMouseMove.SectionMouseMoveSample"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
||||
xmlns:local="clr-namespace:Wpf.CartesianChart.SectionsMouseMove"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<UserControl.DataContext>
|
||||
<local:ViewModel></local:ViewModel>
|
||||
</UserControl.DataContext>
|
||||
<Grid>
|
||||
<lvc:CartesianChart MouseMove="UIElement_OnMouseMove" DataTooltip="{x:Null}">
|
||||
<lvc:CartesianChart.Series>
|
||||
<lvc:ColumnSeries Values="5,6,7,9,2,4,6,5,9,7,5,10"/>
|
||||
</lvc:CartesianChart.Series>
|
||||
<lvc:CartesianChart.AxisY>
|
||||
<lvc:Axis LabelFormatter="{Binding Formatter}">
|
||||
<lvc:Axis.Sections>
|
||||
<lvc:AxisSection Value="{Binding YPointer}"
|
||||
DataLabel="True"
|
||||
StrokeThickness="1"
|
||||
Stroke="#ff5722"
|
||||
DisableAnimations="True"
|
||||
DataLabelForeground="White"
|
||||
Panel.ZIndex="1"/>
|
||||
</lvc:Axis.Sections>
|
||||
</lvc:Axis>
|
||||
</lvc:CartesianChart.AxisY>
|
||||
<lvc:CartesianChart.AxisX>
|
||||
<lvc:Axis LabelsRotation="-25" Labels="January, February, March, April, May, Jun, July, Agust, September, October, November, December">
|
||||
<lvc:Axis.Sections>
|
||||
<lvc:AxisSection Value="{Binding XPointer}"
|
||||
SectionWidth="1"
|
||||
SectionOffset="-0.5"
|
||||
Fill="#59FF5722"
|
||||
Stroke="#ff5722"
|
||||
StrokeThickness=".5"
|
||||
DataLabelForeground="White"
|
||||
DataLabel="True"/>
|
||||
</lvc:Axis.Sections>
|
||||
<lvc:Axis.Separator>
|
||||
<lvc:Separator Step="1" />
|
||||
</lvc:Axis.Separator>
|
||||
</lvc:Axis>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Helpers;
|
||||
using LiveCharts.Wpf;
|
||||
|
||||
namespace Wpf.CartesianChart.SectionsMouseMove
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SectionMouseMoveSample.xaml
|
||||
/// </summary>
|
||||
public partial class SectionMouseMoveSample : UserControl
|
||||
{
|
||||
public SectionMouseMoveSample()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void UIElement_OnMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
var vm = (ViewModel) DataContext;
|
||||
var chart = (LiveCharts.Wpf.CartesianChart) sender;
|
||||
|
||||
//lets get where the mouse is at our chart
|
||||
var mouseCoordinate = e.GetPosition(chart);
|
||||
|
||||
//now that we know where the mouse is, lets use
|
||||
//ConverToChartValues extension
|
||||
//it takes a point in pixes and scales it to our chart current scale/values
|
||||
var p = chart.ConvertToChartValues(mouseCoordinate);
|
||||
|
||||
//in the Y section, lets use the raw value
|
||||
vm.YPointer = p.Y;
|
||||
|
||||
//for X in this case we will only highlight the closest point.
|
||||
//lets use the already defined ClosestPointTo extension
|
||||
//it will return the closest ChartPoint to a value according to an axis.
|
||||
//here we get the closest point to p.X according to the X axis
|
||||
var series = chart.Series[0];
|
||||
var closetsPoint = series.ClosestPointTo(p.X, AxisOrientation.X);
|
||||
|
||||
vm.XPointer = closetsPoint.X;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Wpf.CartesianChart.SectionsMouseMove
|
||||
{
|
||||
public class ViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private double _xPointer;
|
||||
private double _yPointer;
|
||||
|
||||
public ViewModel()
|
||||
{
|
||||
//lets initialize in an invisible location
|
||||
XPointer = -5;
|
||||
YPointer = -5;
|
||||
|
||||
//the formatter or labels property is shared
|
||||
Formatter = x => x.ToString("N2");
|
||||
}
|
||||
|
||||
public double XPointer
|
||||
{
|
||||
get { return _xPointer; }
|
||||
set
|
||||
{
|
||||
_xPointer = value;
|
||||
OnPropertyChanged("XPointer");
|
||||
}
|
||||
}
|
||||
|
||||
public double YPointer
|
||||
{
|
||||
get { return _yPointer; }
|
||||
set
|
||||
{
|
||||
_yPointer = value;
|
||||
OnPropertyChanged("YPointer");
|
||||
}
|
||||
}
|
||||
|
||||
public Func<double, string> Formatter { get; set; }
|
||||
|
||||
#region INotifyPropertyChanged implementation
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user