WPF Tookit Chart

 

如何使用Chart

实例:

Binding数据源中是一个KeyValuePair对象。可以是Dictionary.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<charting:Chart x:Name="chtSummary" Width="770" Height="400" Title="My Chart Title">
    <charting:Chart.TitleStyle>
        <Style TargetType="datavis:Title">
            <Setter Property="FontSize" Value="28" />
            <Setter Property="FontFamily" Value="Arial" />
            <Setter Property="Margin" Value="5, 10, 5, 15" />
        </Style>
    </charting:Chart.TitleStyle>
    <charting:Chart.LegendStyle>
        <Style TargetType="datavis:Legend">
            <Setter Property="Width" Value="0" />
        </Style>
    </charting:Chart.LegendStyle>
    <charting:Chart.Series>
        <charting:BarSeries ItemsSource="{Binding}" DependentValuePath="Value" IndependentValuePath="Key" IsSelectionEnabled="True" >
            <charting:BarSeries.IndependentAxis>
                <charting:CategoryAxis Orientation="Y" AxisLabelStyle="{StaticResource SummaryChartAxisStyle}" />
            </charting:BarSeries.IndependentAxis>
        </charting:BarSeries>  
    </charting:Chart.Series>   
</charting:Chart>

 

 

如何添加第二个Y坐标

secondary y axis on WPF toolkit chart

 

实例:

On the first serie (ColumnSerie on my example), add this

1
2
3
<DVC:ColumnSeries.DependentRangeAxis >
    <DVC:LinearAxis Location="Left" Orientation="Y" />
</DVC:ColumnSeries.DependentRangeAxis>

On the second serie (LineSeries), add this

1
2
3
<DVC:LineSeries.DependentRangeAxis >
    <DVC:LinearAxis Location="Right" Orientation="Y" />
</DVC:LineSeries.DependentRangeAxis>

 

如何修改图列的名称

实例:

LineSeries Title=" Monthly Count" is responsible for display the legend text

1
2
3
4
5
6
7
8
9
10
<wpft:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart"
       Width="400" Height="250"
       Background="LightSteelBlue">
    <wpft:Chart.Series>
     <wpft:LineSeries Title=" Monthly Count"
        IndependentValueBinding="{Binding Path=Key}"
        DependentValueBinding="{Binding Path=Value}">
</wpft:LineSeries>
</wpft:Chart.Series>          
</wpft:Chart>

 

改变DataPointStyle

实例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<chartingToolkit:Chart Margin="0,12,12,12" Name="chart1">
   <chartingToolkit:Chart.Series>
    <chartingToolkit:ColumnSeries DependentValuePath="value">
     <chartingToolkit:ColumnSeries.DataPointStyle>
      <Style TargetType="chartingToolkit:ColumnDataPoint">
       <Setter Property="DependentValueStringFormat" Value="{}{0:C0}"/>
      </Style>
     </chartingToolkit:ColumnSeries.DataPointStyle>
    </chartingToolkit:ColumnSeries>
     
   </chartingToolkit:Chart.Series>
   <chartingToolkit:Chart.Axes>
    <chartingToolkit:LinearAxis Orientation="Y" ShowGridLines="False" HorizontalAlignment="Left">
     <chartingToolkit:LinearAxis.AxisLabelStyle>
      <Style TargetType="chartingToolkit:AxisLabel">
       <Setter Property="StringFormat" Value="{}{0:C0}"/>
      </Style>
     </chartingToolkit:LinearAxis.AxisLabelStyle>
    </chartingToolkit:LinearAxis>
   </chartingToolkit:Chart.Axes>
  </chartingToolkit:Chart>
posted @   霍旭东  阅读(1398)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示