mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-05 16:56:34 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.FullyResponsive.FullyResponsiveExample"
|
||||
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:local="clr-namespace:Wpf.CartesianChart"
|
||||
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
||||
xmlns:fullyResponsive="clr-namespace:Wpf.CartesianChart.FullyResponsive"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance fullyResponsive:FullyResponsiveExample}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock TextWrapping="Wrap">
|
||||
Fully Responsive
|
||||
</TextBlock>
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal">
|
||||
<TextBlock VerticalAlignment="Center" Margin="0 0 10 0">Points</TextBlock>
|
||||
<Button Click="AddPointOnClick">+</Button>
|
||||
<Button Click="InsertPointOnClick">/</Button>
|
||||
<Button Click="RemovePointOnClick">-</Button>
|
||||
<Button Click="MoveAllOnClick">MoveAll</Button>
|
||||
<TextBlock Margin="0 0 10 0" VerticalAlignment="Center">Series</TextBlock>
|
||||
<Button Click="AddSeriesOnClick">+</Button>
|
||||
<Button Click="RemoveSeriesOnClick">-</Button>
|
||||
</StackPanel>
|
||||
<lvc:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}" LegendLocation="Right"></lvc:CartesianChart>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Defaults;
|
||||
using LiveCharts.Wpf;
|
||||
|
||||
namespace Wpf.CartesianChart.FullyResponsive
|
||||
{
|
||||
public partial class FullyResponsiveExample : UserControl
|
||||
{
|
||||
public FullyResponsiveExample()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
MyValues = new ChartValues<ObservableValue>
|
||||
{
|
||||
new ObservableValue(5),
|
||||
new ObservableValue(7),
|
||||
new ObservableValue(8),
|
||||
new ObservableValue(3)
|
||||
};
|
||||
|
||||
var lineSeries = new LineSeries
|
||||
{
|
||||
Values = MyValues,
|
||||
StrokeThickness = 4,
|
||||
Fill = Brushes.Transparent,
|
||||
PointGeometrySize = 0,
|
||||
DataLabels = true
|
||||
};
|
||||
|
||||
SeriesCollection = new SeriesCollection {lineSeries};
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public ChartValues<ObservableValue> MyValues { get; set; }
|
||||
public SeriesCollection SeriesCollection { get; set; }
|
||||
|
||||
private void AddPointOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new Random();
|
||||
MyValues.Add(new ObservableValue(r.Next(-20, 20)));
|
||||
}
|
||||
|
||||
private void InsertPointOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new Random();
|
||||
if (MyValues.Count > 3)
|
||||
MyValues.Insert(2, new ObservableValue(r.Next(-20, 20)));
|
||||
}
|
||||
|
||||
private void RemovePointOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MyValues.RemoveAt(0);
|
||||
}
|
||||
|
||||
private void AddSeriesOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//Yes it also listens for series changes
|
||||
var r = new Random();
|
||||
|
||||
var c = SeriesCollection[0].Values.Count;
|
||||
|
||||
var val = new ChartValues<ObservableValue>();
|
||||
|
||||
for (int i = 0; i < c; i++)
|
||||
{
|
||||
val.Add(new ObservableValue(r.Next(-20, 20)));
|
||||
}
|
||||
|
||||
SeriesCollection.Add(new LineSeries
|
||||
{
|
||||
Values = val,
|
||||
StrokeThickness = 4,
|
||||
Fill = Brushes.Transparent,
|
||||
PointGeometrySize = 0
|
||||
});
|
||||
}
|
||||
|
||||
private void RemoveSeriesOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var s = SeriesCollection.Where(x => x.Values != MyValues).ToList();
|
||||
if (s.Count > 0) SeriesCollection.RemoveAt(1);
|
||||
}
|
||||
|
||||
private void MoveAllOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new Random();
|
||||
|
||||
foreach (var observable in MyValues)
|
||||
{
|
||||
observable.Value = r.Next(-20, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user