tookit chart 一个简单的双Y轴实现

最近在项目中需要使用到 toolkit里面的chart组件  下面是一个简单的例子和双Y轴的实现

后台代码

 public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            List<CityEntity> pugetSound = new List<CityEntity>();
            pugetSound.Add(new CityEntity { Key = "Bellevue", Value = 1 });
            pugetSound.Add(new CityEntity { Key = "Issaquah", Value = 2 });
            pugetSound.Add(new CityEntity { Key = "Redmond", Value = 3 });
            pugetSound.Add(new CityEntity { Key = "Seattle", Value = 4 });


            ColumnSeries series = new ColumnSeries();
            series.ItemsSource = pugetSound;
            series.DependentValueBinding = new Binding("Value");
            series.IndependentValueBinding = new Binding("Key");
            series.Title = "柱图";
            series.DependentRangeAxis = new LinearAxis() { Orientation = AxisOrientation.Y, Minimum = 0, Maximum = 10 };
            this.Chart.Series.Add(series);
            
           

            LineSeries series2 = new LineSeries();
            series2.ItemsSource = pugetSound;
            series2.DependentValueBinding = new Binding("Value");
            series2.IndependentValueBinding = new Binding("Key");
            series2.Title = "趋势图";
            series2.DependentRangeAxis = new LinearAxis() { Orientation = AxisOrientation.Y, Minimum =0, Maximum = 10 };
            this.Chart.Series.Add(series2);
        }

    }


    public class CityEntity
    {
        public string Key { get; set; }
        public int Value { get; set; }


    }

  前台代码

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:visualizationToolkit="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
  
    x:Class="SilverlightApplication1.MainPage">
    <StackPanel>
        <chartingToolkit:Chart x:Name="Chart" Title="Typical Use" Height="600" Width="500">
            <!--<chartingToolkit:Chart.Axes>
                <chartingToolkit:CategoryAxis Title="Name" Orientation="X" FontStyle="Italic"/>
                <chartingToolkit:LinearAxis Title="Value" Orientation="Y" Minimum="0" Maximum="1" Interval="100" ShowGridLines="True"  FontStyle="Italic"/>
            </chartingToolkit:Chart.Axes>-->
       
        </chartingToolkit:Chart>
    </StackPanel>
</UserControl>

 

posted @ 2012-10-25 15:51  好佳伙  阅读(925)  评论(0编辑  收藏  举报