I
I
ichernob2015-12-14 22:18:10
infographics
ichernob, 2015-12-14 22:18:10

Why does the application crash in Windows Phone 8.1 when trying to initialize two Charts?

private void plotButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                g1 = new List<Point>();
                g2 = new List<Point>();
                for (int i = 0; i < 100; i++)
                {
                    g1.Add(new Point(Convert.ToDouble(i * 10), Convert.ToDouble(i * 10)));
                    g2.Add(new Point(Convert.ToDouble(i * 10), Convert.ToDouble(i * 100)));
                }

                var line1 = plot1.Series[0] as LineSeries;
                var line2 = plot1.Series[1] as LineSeries;
                line1.ItemsSource = g1;
                line2.ItemsSource = g2;
                var line3 = plot2.Series[0] as LineSeries;
                var line4 = plot2.Series[1] as LineSeries;
                line3.ItemsSource = g1;
                line4.ItemsSource = g2;
            }
            catch(Exception ex)
            {

            }
        }

xmlns:chart="using:WinRTXamlToolkit.Controls.DataVisualization.Charting"
...
<Grid Grid.Row="2" x:Name="graphGrid" Margin="19,9.5,19,0">
            <ScrollViewer VerticalScrollMode="Enabled"
                          VerticalScrollBarVisibility="Auto">
                <StackPanel Orientation="Vertical">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <ScrollViewer Grid.Row="0" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Auto">
                            <chart:Chart x:Name="plot1" Width="1000" Height="Auto">
                                <chart:Chart.Series>
                                    <chart:LineSeries x:Name="graphic1" Title="Winner" ItemsSource="{Binding graph}"
                                                  IndependentValueBinding="{Binding Y}"
                                                  DependentValueBinding="{Binding X}" >
                                        <chart:LineSeries.DataPointStyle>
                                            <Style TargetType="chart:LineDataPoint">
                                                <Setter Property="Width" Value="1" />
                                                <Setter Property="Height" Value="1" />
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="chart:LineDataPoint">
                                                            <Ellipse Fill="Blue" Stroke="Blue" StrokeThickness="3" />
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </chart:LineSeries.DataPointStyle>
                                    </chart:LineSeries>
                                    <chart:LineSeries x:Name="graphic2" Title="LMS" ItemsSource="{Binding graph}"
                                                  IndependentValueBinding="{Binding Y}"
                                                  DependentValueBinding="{Binding X}">
                                        <chart:LineSeries.DataPointStyle>
                                            <Style TargetType="chart:LineDataPoint">
                                                <Setter Property="Width" Value="1" />
                                                <Setter Property="Height" Value="1" />
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="chart:LineDataPoint">
                                                            <Ellipse Fill="Green" Stroke="Green" StrokeThickness="3" />
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </chart:LineSeries.DataPointStyle>
                                    </chart:LineSeries>
                                </chart:Chart.Series>
                                <chart:Chart.Axes>
                                    <chart:LinearAxis x:Name="y1" Title="y" Orientation="Y"
                                                      Minimum="{Binding ymin}"
                                                      Maximum="{Binding ymax}"
                                                      Interval="{Binding yint}"
                                                      ShowGridLines="True" />
                                    <chart:LinearAxis x:Name="x1" Title="x" Orientation="X"
                                                    Minimum="{Binding xmin}"
                                                    Maximum="{Binding xmax}"
                                                    Interval="{Binding xint}"
                                                    ShowGridLines="True" />
                                </chart:Chart.Axes>
                            </chart:Chart>
                        </ScrollViewer>
                        <ScrollViewer Grid.Row="1" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Auto">
                            <chart:Chart x:Name="plot2" Width="1000" Height="Auto">
                                <chart:Chart.Series>
                                    <chart:LineSeries x:Name="graphic3" Title="Winner" ItemsSource="{Binding graph}"
                                                  IndependentValueBinding="{Binding Y}"
                                                  DependentValueBinding="{Binding X}" >
                                        <chart:LineSeries.DataPointStyle>
                                            <Style TargetType="chart:LineDataPoint">
                                                <Setter Property="Width" Value="1" />
                                                <Setter Property="Height" Value="1" />
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="chart:LineDataPoint">
                                                            <Ellipse Fill="Blue" Stroke="Blue" StrokeThickness="3" />
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </chart:LineSeries.DataPointStyle>
                                    </chart:LineSeries>
                                    <chart:LineSeries x:Name="graphic4" Title="LMS" ItemsSource="{Binding graph}"
                                                  IndependentValueBinding="{Binding Y}"
                                                  DependentValueBinding="{Binding X}">
                                        <chart:LineSeries.DataPointStyle>
                                            <Style TargetType="chart:LineDataPoint">
                                                <Setter Property="Width" Value="1" />
                                                <Setter Property="Height" Value="1" />
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="chart:LineDataPoint">
                                                            <Ellipse Fill="Green" Stroke="Green" StrokeThickness="3" />
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </chart:LineSeries.DataPointStyle>
                                    </chart:LineSeries>
                                </chart:Chart.Series>
                                <chart:Chart.Axes>
                                    <chart:LinearAxis x:Name="y2" Title="y" Orientation="Y"
                                                      Minimum="{Binding ymin}"
                                                      Maximum="{Binding ymax}"
                                                      Interval="{Binding yint}"
                                                      ShowGridLines="True" />
                                    <chart:LinearAxis x:Name="x2" Title="x" Orientation="X"
                                                    Minimum="{Binding xmin}"
                                                    Maximum="{Binding xmax}"
                                                    Interval="{Binding xint}"
                                                    ShowGridLines="True" />
                                </chart:Chart.Axes>
                            </chart:Chart>
                        </ScrollViewer>
                    </Grid>
                </StackPanel>
            </ScrollViewer>
        </Grid>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ichernob, 2015-12-14
@ichernob

I'm trying to build several graphs, in plotButton_Click all the code is executed, the method ends and suddenly an exception occurs Message = "System.InvalidOperationException: Sequence contains no elements\r\n at System.Linq.Enumerable.Min(IEnumerable`1 source)\r\n at WinRTXamlToolkit.Controls.DataVisualization.Charting.OrientedPanel.MeasureOverride(Size availableSize)\r\n at Windows.UI.Xa...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question