Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
L
livecharts
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
livecharts
Commits
3fb68fa0
Commit
3fb68fa0
authored
Aug 12, 2019
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复 当没有DataLabel 时会出现的bug
parent
234e9b5e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
222 additions
and
2 deletions
+222
-2
App.xaml
WpfApp1/App.xaml
+1
-1
Column2Example.xaml
WpfApp1/Column2Example.xaml
+39
-0
Column2Example.xaml.cs
WpfApp1/Column2Example.xaml.cs
+173
-0
WpfApp1.csproj
WpfApp1/WpfApp1.csproj
+7
-0
ColumnPointView.cs
WpfView/Points/ColumnPointView.cs
+2
-1
No files found.
WpfApp1/App.xaml
View file @
3fb68fa0
...
...
@@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="Column
Range
Example.xaml">
StartupUri="Column
2
Example.xaml">
<Application.Resources>
</Application.Resources>
...
...
WpfApp1/Column2Example.xaml
0 → 100644
View file @
3fb68fa0
<Window x:Class="WpfApp1.Column2Example"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid >
<lvc:CartesianChart x:Name="chart" Series="{Binding SeriesCollection}" LegendLocation="Left"
DisableAnimations="True" Hoverable="False" DataTooltip="{x:Null}">
<lvc:CartesianChart.AxisX>
<lvc:Axis MinValue="{Binding XMin}" MaxValue="{Binding XMax}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sold Apps" LabelFormatter="{Binding Formatter}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" Background="#08000000" VerticalAlignment="Top">
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="XMin"/>
<TextBox Text="{Binding XMin}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="XMax"/>
<TextBox Text="{Binding XMax}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="运行中"/>
<TextBlock Text="{Binding IsRunning,Mode=OneWay}"/>
</StackPanel>
<Button Content="定时更新" Width="80" Padding="5" Click="Button_Click"/>
<Button Content="清空" Width="80" Padding="5" Click="ButtonClear_Click"/>
<Button Content="GC" Width="80" Padding="5" Click="ButtonGC_Click"/>
</StackPanel>
</Grid>
</Window>
\ No newline at end of file
WpfApp1/Column2Example.xaml.cs
0 → 100644
View file @
3fb68fa0
using
LiveCharts
;
using
LiveCharts.Configurations
;
using
LiveCharts.Defaults
;
using
LiveCharts.Wpf
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
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.Shapes
;
using
System.Windows.Threading
;
namespace
WpfApp1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public
partial
class
Column2Example
:
Window
{
Column2ExampleViewModel
viewModel
;
public
Column2Example
()
{
InitializeComponent
();
viewModel
=
new
Column2ExampleViewModel
();
viewModel
.
Init
();
this
.
DataContext
=
viewModel
;
}
private
void
Button_Click
(
object
sender
,
RoutedEventArgs
e
)
{
if
(
viewModel
.
IsRunning
)
viewModel
.
Stop
();
else
viewModel
.
Start
();
}
private
void
ButtonGC_Click
(
object
sender
,
RoutedEventArgs
e
)
{
GC
.
Collect
();
}
private
void
ButtonClear_Click
(
object
sender
,
RoutedEventArgs
e
)
{
viewModel
.
Values
.
Clear
();
}
}
public
class
Column2ExampleViewModel
:
INotifyPropertyChanged
{
DispatcherTimer
timer
;
public
SeriesCollection
SeriesCollection
{
get
;
set
;
}
public
Func
<
double
,
string
>
Formatter
{
get
;
set
;
}
public
double
XMin
{
get
;
set
;
}
=
double
.
NaN
;
public
double
XMax
{
get
;
set
;
}
=
double
.
NaN
;
public
bool
IsRunning
{
get
;
private
set
;
}
List
<
double
>
datas
=
new
List
<
double
>();
public
ChartValues
<
double
>
Values
=
new
ChartValues
<
double
>();
public
void
Update
()
{
Random
random
=
new
Random
();
double
[]
datas2
=
new
double
[
datas
.
Count
()];
for
(
int
i
=
0
;
i
<
datas
.
Count
();
i
++)
{
datas2
[
i
]
=
datas
[
i
]
+
(
random
.
NextDouble
()
-
0.5
)
*
1
;
}
//把其中一部分数据变为无效
int
null_value_pos
=
random
.
Next
(
datas
.
Count
());
for
(
int
i
=
0
;
i
<
datas
.
Count
()/
10
;
i
++)
{
int
index
=
null_value_pos
-
datas
.
Count
()
/
20
+
i
;
if
(
index
<
0
)
index
+=
datas2
.
Count
();
else
if
(
index
>=
datas2
.
Count
())
index
-=
datas2
.
Count
();
datas2
[
index
]
=
double
.
NaN
;
}
// if (SeriesCollection.Count() > 0)
// SeriesCollection.Clear();
Values
.
Clear
();
Values
.
AddRange
(
datas2
);
}
public
void
Init
()
{
//-----------------------------------------------------------
//模拟数据
double
target
=
150
;
double
tolerance
=
2
;
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
double
d
=
Math
.
Sin
(
Math
.
PI
*
2
*
i
/
35
)
*
tolerance
+
(
random
.
NextDouble
()
-
0.5
)
*
0.3
+
target
;
datas
.
Add
(
d
);
}
SeriesCollection
=
new
SeriesCollection
();
SeriesCollection
.
Add
(
new
Column2Series
{
Title
=
"Column2"
,
Values
=
Values
,
StrokeThickness
=
1
,
Stroke
=
new
SolidColorBrush
(
System
.
Windows
.
Media
.
Colors
.
DarkRed
),
Fill
=
new
SolidColorBrush
(
System
.
Windows
.
Media
.
Color
.
FromArgb
(
0x80
,
0xff
,
0
,
0
)),
YAxisCrossing
=
150
,
Configuration
=
Mappers
.
Xy
<
double
>()
.
X
((
v
,
index
)=>
index
)
.
Y
(
v
=>
v
)
});
Formatter
=
value
=>
value
.
ToString
(
"N"
);
XMin
=
100
;
XMax
=
900
;
//-----------------------------------------------------------
//转显示数据
Update
();
timer
=
new
DispatcherTimer
();
timer
.
Interval
=
TimeSpan
.
FromSeconds
(
0.1
);
timer
.
Tick
+=
Timer_Tick
;
}
public
void
Start
()
{
IsRunning
=
true
;
timer
.
Start
();
}
public
void
Stop
()
{
IsRunning
=
false
;
timer
.
Stop
();
}
private
void
Timer_Tick
(
object
sender
,
EventArgs
e
)
{
Update
();
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
}
}
WpfApp1/WpfApp1.csproj
View file @
3fb68fa0
...
...
@@ -62,9 +62,16 @@
<Generator>
MSBuild:Compile
</Generator>
<SubType>
Designer
</SubType>
</ApplicationDefinition>
<Compile
Include=
"Column2Example.xaml.cs"
>
<DependentUpon>
Column2Example.xaml
</DependentUpon>
</Compile>
<Compile
Include=
"ColumnRangeExample.xaml.cs"
>
<DependentUpon>
ColumnRangeExample.xaml
</DependentUpon>
</Compile>
<Page
Include=
"Column2Example.xaml"
>
<Generator>
MSBuild:Compile
</Generator>
<SubType>
Designer
</SubType>
</Page>
<Page
Include=
"MainWindow.xaml"
>
<Generator>
MSBuild:Compile
</Generator>
<SubType>
Designer
</SubType>
...
...
WpfView/Points/ColumnPointView.cs
View file @
3fb68fa0
...
...
@@ -184,7 +184,8 @@ namespace LiveCharts.Wpf.Points
chart
.
View
.
RemoveFromDrawMargin
(
Rectangle
);
chart
.
View
.
RemoveFromDrawMargin
(
DataLabel
);
//feng
DataLabel
.
Content
=
null
;
if
(
DataLabel
!=
null
)
DataLabel
.
Content
=
null
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment