2

Я создаю BubbleSeries в функции в пределах CS файл. В качестве источника данных я использую List<Dictionary<string,string>> GridData. К сожалению, моя реализация исключает исключение: No suitable axis is available for plotting the dependent value. Я новичок SL4, и я не могу понять, что может быть резонансом. Вот как я создаю и добавить BubbleSeries в Диаграмма:Как прагматично создавать BubbleSeries в SL4

List<Dictionary<string,string>> GridData = getGridData(); 

    var s1 = new BubbleSeries(); 
    s1.DependentValueBinding = new Binding("[" + <key to numeric value in DataGrid> + "]"); 
    s1.SizeValueBinding = new Binding("[" + <key to numeric value in DataGrid> + "]"); 
    s1.IndependentValueBinding = new Binding("[" + <key to string value in DataGrid> + "]"); 
    s1.ItemsSource = GridData; 
    s1.Title = "Chart"; 
    // add BubbleSeries to Chart 
    ChartVis.Series.Add(s1); 

Вот полное описание ошибки я получил во время выполнения:

Webpage error details 

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E) 
Timestamp: Mon, 20 Sep 2010 07:09:33 UTC 


Message: Unhandled Error in Silverlight Application 
Code: 4004  
Category: ManagedRuntimeError  
Message: System.InvalidOperationException: No suitable axis is available for plotting the dependent value. 
    at System.Windows.Controls.DataVisualization.Charting.BubbleSeries.<>c__DisplayClass6.<GetAxes>b__3() 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.GetAxes(DataPoint firstDataPoint, Func`2 independentAxisPredicate, Func`1 independentAxisFactory, Func`2 dependentAxisPredicate, Func`1 dependentAxisFactory) 
    at System.Windows.Controls.DataVisualization.Charting.BubbleSeries.GetAxes(DataPoint firstDataPoint) 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.GetAxes() 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.OnDataPointsChanged(IList`1 newDataPoints, IList`1 oldDataPoints) 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSingleSeriesWithAxes.OnDataPointsChanged(IList`1 newDataPoints, IList`1 oldDataPoints) 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.LoadDataPoints(IEnumerable newItems, IEnumerable oldItems) 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.Refresh() 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.OnSizeChanged(Object sender, SizeChangedEventArgs e) 
    at System.Windows.FrameworkElement.OnSizeChanged(Object sender, SizeChangedEventArgs e) 
    at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)  

Line: 56 
Char: 13 
Code: 0 
URI: http://localhost:49402/MyTestPage.aspx 

Моя реализация диаграммы:

<toolkit:Chart Title="Visaulization" Grid.Column="0" x:Name="ChartVis"> 
       <toolkit:Chart.Series> 
       </toolkit:Chart.Series> 
</toolkit:Chart> 

ОБНОВЛЕНИЕ: После изменения объявления моего словаря на Dictionary<string,object> и ввода числовых значений в виде двойных чисел. Я получил эту ошибку:

Message: Unhandled Error in Silverlight Application 
Code: 4004  
Category: ManagedRuntimeError  
Message: System.InvalidOperationException: Assigned dependent axis cannot be used. This may be due to an unset Orientation property for the axis or a type mismatch between the values being plotted and those supported by the axis. 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.GetAxes(DataPoint firstDataPoint, Func`2 independentAxisPredicate, Func`1 independentAxisFactory, Func`2 dependentAxisPredicate, Func`1 dependentAxisFactory) 
    at System.Windows.Controls.DataVisualization.Charting.BubbleSeries.GetAxes(DataPoint firstDataPoint) 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.GetAxes() 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.OnDataPointsChanged(IList`1 newDataPoints, IList`1 oldDataPoints) 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSingleSeriesWithAxes.OnDataPointsChanged(IList`1 newDataPoints, IList`1 oldDataPoints) 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.LoadDataPoints(IEnumerable newItems, IEnumerable oldItems) 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.Refresh() 
    at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.OnSizeChanged(Object sender, SizeChangedEventArgs e) 
    at System.Windows.FrameworkElement.OnSizeChanged(Object sender, SizeChangedEventArgs e) 
    at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)  
+0

Отредактировал свой ответ, чтобы включить полный пример. – AnthonyWJones

ответ

1

Изменить getGridData вернуться List<Dictionary<string, object>> и обеспечить числовые значения добавляются в словарь, используя числовой тип, такой как int или double.

Редактировать

Это может быть проще использовать конкретный пример, вот некоторые тестовый код: -

public partial class BubbleTest : UserControl 
{ 
    public BubbleTest() 
    { 
     InitializeComponent(); 
     Loaded += new RoutedEventHandler(BubbleTest_Loaded); 
    } 

    void BubbleTest_Loaded(object sender, RoutedEventArgs e) 
    { 
     var s1 = new BubbleSeries(); 
     s1.DependentValueBinding = new Binding("[dependent]"); 
     s1.SizeValueBinding = new Binding("[size]"); 
     s1.IndependentValueBinding = new Binding("[independent]"); 
     s1.ItemsSource = GetGridData(); 
     s1.Title = "Chart"; 
     ChartVis.Series.Add(s1); 

    } 

    private List<Dictionary<string, object>> GetGridData() 
    { 
     List<Dictionary<string, object>> gridData = new List<Dictionary<string, object>>(); 

     gridData.Add(CreateBubbleEntry("First", 10.0, 5.0)); 
     gridData.Add(CreateBubbleEntry("Second", 20.0, 10.0)); 

     return gridData; 
    } 

    private Dictionary<string, object> CreateBubbleEntry(string independent, double dependent, double size) 
    { 
     var item = new Dictionary<string, object>(); 
     item.Add("independent", independent); 
     item.Add("dependent", dependent); 
     item.Add("size", size); 
     return item; 
    } 
} 

Xaml для этого пользовательского элемента управления как у вас есть: -

<UserControl x:Class="SilverlightApplication1.BubbleTest" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
> 
    <Grid x:Name="LayoutRoot" Background="White"> 
     <toolkit:Chart Title="Visaulization" Grid.Column="0" x:Name="ChartVis"> 
      <toolkit:Chart.Series> 
      </toolkit:Chart.Series> 
     </toolkit:Chart> 
    </Grid> 
</UserControl> 

Вышеупомянутые работы так, что бы вы ни делали, они будут меняться в некотором роде.

+0

Я сделал то, что вы предложили, но я все еще ошибаюсь. На этот раз я получаю System.InvalidOperationException: Сообщение: необработанная ошибка в приложении Silverlight Код: 4004 Категория: ManagedRuntimeError Сообщение: System.InvalidOperationException: Назначенная зависимая ось не может быть использована. Это может происходить из-за неустановленного свойства ориентации для оси или несоответствия типа между отображаемыми значениями и значениями, поддерживаемыми осью. в System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWi – Skarab

 Смежные вопросы

  • Нет связанных вопросов^_^