How to show multiple charts in one window WPF -livecharts

524 Views Asked by At

I am trying to show two charts in a wpf window after a button is clicked. I use two functions to render the charts. Only the chart that I call first displays. The second one doesn't for some reason. Heres my code

 public void LineChart(List<int> vec)
    {
        ChartValues <int> val = new ChartValues<int>();
        List <string> labels =new List<string>();
        string str;
        for (int i=0; i<vec.Count; i++)
        {
            val.Add(vec[i]);
            str = (i + 1).ToString();
            labels.Add(str);
        }
        LineCollection = new SeriesCollection
        {
            new LineSeries
            {
                Title="Tiles v Iteration",
                Values= val,
                Fill=Brushes.Khaki,
                Stroke=Brushes.DarkRed                   
            }
        };

        LineLabels = labels;
        LYFormatter = value => value.ToString("G");
        DataContext = this;
    }

    public void BarChart(List<int>tile, List<int> number) 
    {
        ChartValues<int> vl = new ChartValues<int>();
        List<string> labels = new List<string>();
        string str;
        for (int i = 0; i < tile.Count; i++)
        {
            vl.Add(number[i]);
            str = tile[i].ToString();
            labels.Add(str);
        }

        BarCollection = new SeriesCollection
        {
            new ColumnSeries
            {
                Title="Number v Tile",
                Values= vl,
                Fill=Brushes.Khaki,
                Stroke=Brushes.DarkRed
            }
        };
        BarLabels = labels;
        BYFormatter = value => value.ToString("G");
        DataContext = this;
    }



 private async void start_Click(object sender, RoutedEventArgs e)
        { 
        BarChart(UniqueTiles, UniqueTileNumber);
        LineChart(TileNumber);
         }

As it shows here BarChart gets rendered but LineChart doesn't. When I bring LineChart first then it works and BarChart stops working. Does anyone have any ideas as to what's going on?

0

There are 0 best solutions below