-1

So I just started using LiveCharts and I looked through the docs and tried building my first project. I created a control and bound the Series property to a value but it's not showing anything on the actual control, why is that? What did I miss and how do I resolve this issue? Whats the logic behind that fact that nothing is showing up?

XAML

<Grid>
    <wpf:CartesianChart Series="{Binding observableValues}" />
</Grid>

CS

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            var doubleValues = new ChartValues<double> { 1, 2, 3 };
            var intValues = new ChartValues<int> { 1, 2, 3 };

            //the observable value class is really helpful, it notifies the chart to update
            //every time the ObservableValue.Value property changes
            var observableValues = new ChartValues<LiveCharts.Defaults.ObservableValue>
            {
                new LiveCharts.Defaults.ObservableValue(1), //initializes Value property as 1
                new LiveCharts.Defaults.ObservableValue(2),
                new LiveCharts.Defaults.ObservableValue(3)
            };
        }
    }
Keyur Ramoliya
  • 1,900
  • 2
  • 16
  • 17
Mark Denom
  • 987
  • 1
  • 8
  • 24

1 Answers1

0

You aren't binding anything to the cartesian chart. You should add observableValues as property of MainWindow.

public partial class MainWindow : Window
    {
        public ChartValues<LiveCharts.Defaults.ObservableValue> observableValues
        {
            get;
            set;
        }

        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            var doubleValues = new ChartValues<double> { 1, 2, 3 };
            var intValues = new ChartValues<int> { 1, 2, 3 };

            //note that i'm setting the property and i'm not using 'var' keyword
            observableValues = new ChartValues<LiveCharts.Defaults.ObservableValue>
            {
                new LiveCharts.Defaults.ObservableValue(1), //initializes Value property as 1
                new LiveCharts.Defaults.ObservableValue(2),
                new LiveCharts.Defaults.ObservableValue(3)
            };
        }
    }

If you watch to Output Window you'll see binding errors:

System.Windows.Data Error: 40 : BindingExpression path error ....
Babbillumpa
  • 1,854
  • 1
  • 16
  • 21