WPF 图表工具包 y 轴标签对于小数字显示为零
我使用 WPF 工具包 (3.5) 图表工具包创建了一个图表,但无法让 y 轴标签显示小数字(例如 0.001)。我已将 y 轴的最小值和最大值分别设置为 0.001 和 0.009,尽管图表在图形上是正确的,但 y 轴范围标签显示“0”或“.01”。我猜测这是 3.5 工具包中图表控件的限制,但我希望我遗漏了一些东西。下面是一些示例代码:
XAML:
<Window x:Class="WpfChartApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit">
<Grid>
<chartingToolkit:Chart Name="chart1">
<chartingToolkit:LineSeries
Title="Rates"
ItemsSource="{Binding Rates}"
IndependentValueBinding="{Binding Time}"
DependentValueBinding="{Binding Value}"
>
<chartingToolkit:LineSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis
Orientation="Y"
Title="Y Value"
ShowGridLines="True"
Maximum=".009"
Minimum=".001"/>
</chartingToolkit:LineSeries.DependentRangeAxis>
</chartingToolkit:LineSeries>
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="X"
Title="X Value"
ShowGridLines="True"
/>
</chartingToolkit:Chart.Axes>
</chartingToolkit:Chart>
</Grid>
以及背后的代码:
using System.Collections.Generic;
using System.Windows;
namespace WpfChartApplication
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var cVm = new ChartViewModel();
chart1.DataContext = cVm;
}
}
public class ChartViewModel
{
public List<Rate> Rates { get; set; }
public ChartViewModel()
{
Rates = new List<Rate>();
Rates.Add(new Rate(1, .001));
Rates.Add(new Rate(2, .003));
Rates.Add(new Rate(3, .001));
Rates.Add(new Rate(4, .002));
Rates.Add(new Rate(5, .001));
Rates.Add(new Rate(6, .001));
Rates.Add(new Rate(7, .003));
Rates.Add(new Rate(8, .007));
Rates.Add(new Rate(9, .009));
Rates.Add(new Rate(10, .008));
}
}
public class Rate
{
public Rate(int time, double value)
{
Time = time;
Value = value;
}
public int Time { get; set; }
public double Value { get; set; }
}
}
I've created a chart using the WPF toolkit (3.5) charting toolkit and I can't get the y-axis labels to display small numbers (e.g. .001). I have set the minimum and maximum values to .001 and .009 respectively for the y-axis and although the chart is graphically correct, the y-axis range labels show either "0" or ".01". I'm guessing that this is a limitation of the chart control in the 3.5 toolkit but I'm hoping that I'm missing something. Here's some example code:
XAML:
<Window x:Class="WpfChartApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit">
<Grid>
<chartingToolkit:Chart Name="chart1">
<chartingToolkit:LineSeries
Title="Rates"
ItemsSource="{Binding Rates}"
IndependentValueBinding="{Binding Time}"
DependentValueBinding="{Binding Value}"
>
<chartingToolkit:LineSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis
Orientation="Y"
Title="Y Value"
ShowGridLines="True"
Maximum=".009"
Minimum=".001"/>
</chartingToolkit:LineSeries.DependentRangeAxis>
</chartingToolkit:LineSeries>
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="X"
Title="X Value"
ShowGridLines="True"
/>
</chartingToolkit:Chart.Axes>
</chartingToolkit:Chart>
</Grid>
And the code behind:
using System.Collections.Generic;
using System.Windows;
namespace WpfChartApplication
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var cVm = new ChartViewModel();
chart1.DataContext = cVm;
}
}
public class ChartViewModel
{
public List<Rate> Rates { get; set; }
public ChartViewModel()
{
Rates = new List<Rate>();
Rates.Add(new Rate(1, .001));
Rates.Add(new Rate(2, .003));
Rates.Add(new Rate(3, .001));
Rates.Add(new Rate(4, .002));
Rates.Add(new Rate(5, .001));
Rates.Add(new Rate(6, .001));
Rates.Add(new Rate(7, .003));
Rates.Add(new Rate(8, .007));
Rates.Add(new Rate(9, .009));
Rates.Add(new Rate(10, .008));
}
}
public class Rate
{
public Rate(int time, double value)
{
Time = time;
Value = value;
}
public int Time { get; set; }
public double Value { get; set; }
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以更改标签样式以获得效果
希望这会有所帮助......
you can change the label style to get the effect
hope this helps...