手动缩放wpf条形图

时间:2009-11-05 12:10:12

标签: c# wpf scale manual bar-chart

我正在扫描计算机,它们的规模不能像1.5,2,2.5那样它们应该是1,2,3,4这样的整数。

我目前的代码是

ICollection<KeyValuePair<String, int>> data = new Dictionary<String, int>();
            data.Add(new KeyValuePair<string, int>(Protocol, protocolCount));

            mycolseries = new ColumnSeries
                {
                    ItemsSource = data,
                    Title = Protocol,
                    IndependentValuePath = "Key",
                    DependentValuePath = "Value",                        
                };                
            mainChart.Series.Add(mycolseries);  

如果我将依赖值更改为“key”,则会出现奇怪的错误,例如“new应该与调用或元素一起使用,或者尚未初始化”

1 个答案:

答案 0 :(得分:0)

public void Window1(){
       setChartSCale()
}


private void setChartScale()
{
    lamainChart.Interval = 1;
    lamainChart.Orientation = AxisOrientation.Y;
    lamainChart.ShowGridLines = true;
    //lamainChart.Maximum = 50;
        lamainChart.Minimum = 0;
}

递归调用此方法

private void addRecursiveLedgendAfterInit(string Protocol, int protocolCount)
{
      ICollection<KeyValuePair<String, int>> data = new Dictionary<String, int>();
      data.Add(new KeyValuePair<string, int>(Protocol, protocolCount));

      mycolseries = new ColumnSeries
      {
           ItemsSource = data,
           Title = Protocol,
           IndependentValuePath = "Key",                        
           DependentRangeAxis =lamainChart,
           DependentValuePath = "Value"
      };                
      mainChart.Series.Add(mycolseries); 
}