Livecharts - Observable Value











up vote
0
down vote

favorite












I'm using LiveCharts to display a barchart with stock levels. The unit names and stock levels are stored in an access database, and these values are retrieved and put into Lists.



The only thing that should really change is the value of stock so I wanted to track changes of the stock and update the database automatically, giving somewhat live data.



What I want to happen is for the chart to automatically update when the value (stock) changes in the database. I don't want to update the entire table, only the value that has changed so that the animations show on individual bars when they're changed.



I have the following code for loading my database values into the database:



    string units = new string[30];
List<string> subs = new List<string>();
List<string> line = new List<string>();
List<double> min = new List<double>();
List<double> max = new List<double>();
List<ObservableValue> stock = new List<ObservableValue>();

bool initial = true;
private void LoadData()
{
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:DatabasesubDB.mdb";

using (OleDbConnection conn = new OleDbConnection(strConn))
{
conn.Open();
string strSQL = "SELECT * FROM Units";
OleDbCommand command = new OleDbCommand(strSQL, conn);

using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
if (initial)
{
subs.Add(reader["Sub"].ToString());
line.Add(reader["Line"].ToString());
min.Add(Convert.ToDouble(reader["Minimum"]));
max.Add(Convert.ToDouble(reader["Maximum"]));
}
stock.Add(reader["Stock"]);
}
}
initial = false;
}
}


Chart setup:



    public void chartSetup()
{
cartesianChart1.Series = new SeriesCollection
{
new ColumnSeries
{
Title = "Total",
Fill = System.Windows.Media.Brushes.Crimson,
Values = new ChartValues<ObservableValue>(stock)
}
};
cartesianChart1.AxisX.Add(new Axis
{
Title = "Unit",
FontSize = 15,
Separator = new Separator
{
Step = 1,
IsEnabled = false //disable it to make it invisible.
},
LabelsRotation = 45,
Labels = new ChartValues<string>(subs)
});

cartesianChart1.AxisY.Add(new Axis
{
Title = "Total",
FontSize = 15,
ShowLabels = true,
LabelFormatter = value => value.ToString("N")
});
}


My issue is that I'm unable to implement ObservableValue for stock. I get the message: "Cannot convert from 'object' to
LiveCharts.Defaults.ObservableValue










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm using LiveCharts to display a barchart with stock levels. The unit names and stock levels are stored in an access database, and these values are retrieved and put into Lists.



    The only thing that should really change is the value of stock so I wanted to track changes of the stock and update the database automatically, giving somewhat live data.



    What I want to happen is for the chart to automatically update when the value (stock) changes in the database. I don't want to update the entire table, only the value that has changed so that the animations show on individual bars when they're changed.



    I have the following code for loading my database values into the database:



        string units = new string[30];
    List<string> subs = new List<string>();
    List<string> line = new List<string>();
    List<double> min = new List<double>();
    List<double> max = new List<double>();
    List<ObservableValue> stock = new List<ObservableValue>();

    bool initial = true;
    private void LoadData()
    {
    string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:DatabasesubDB.mdb";

    using (OleDbConnection conn = new OleDbConnection(strConn))
    {
    conn.Open();
    string strSQL = "SELECT * FROM Units";
    OleDbCommand command = new OleDbCommand(strSQL, conn);

    using (OleDbDataReader reader = command.ExecuteReader())
    {
    while (reader.Read())
    {
    if (initial)
    {
    subs.Add(reader["Sub"].ToString());
    line.Add(reader["Line"].ToString());
    min.Add(Convert.ToDouble(reader["Minimum"]));
    max.Add(Convert.ToDouble(reader["Maximum"]));
    }
    stock.Add(reader["Stock"]);
    }
    }
    initial = false;
    }
    }


    Chart setup:



        public void chartSetup()
    {
    cartesianChart1.Series = new SeriesCollection
    {
    new ColumnSeries
    {
    Title = "Total",
    Fill = System.Windows.Media.Brushes.Crimson,
    Values = new ChartValues<ObservableValue>(stock)
    }
    };
    cartesianChart1.AxisX.Add(new Axis
    {
    Title = "Unit",
    FontSize = 15,
    Separator = new Separator
    {
    Step = 1,
    IsEnabled = false //disable it to make it invisible.
    },
    LabelsRotation = 45,
    Labels = new ChartValues<string>(subs)
    });

    cartesianChart1.AxisY.Add(new Axis
    {
    Title = "Total",
    FontSize = 15,
    ShowLabels = true,
    LabelFormatter = value => value.ToString("N")
    });
    }


    My issue is that I'm unable to implement ObservableValue for stock. I get the message: "Cannot convert from 'object' to
    LiveCharts.Defaults.ObservableValue










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm using LiveCharts to display a barchart with stock levels. The unit names and stock levels are stored in an access database, and these values are retrieved and put into Lists.



      The only thing that should really change is the value of stock so I wanted to track changes of the stock and update the database automatically, giving somewhat live data.



      What I want to happen is for the chart to automatically update when the value (stock) changes in the database. I don't want to update the entire table, only the value that has changed so that the animations show on individual bars when they're changed.



      I have the following code for loading my database values into the database:



          string units = new string[30];
      List<string> subs = new List<string>();
      List<string> line = new List<string>();
      List<double> min = new List<double>();
      List<double> max = new List<double>();
      List<ObservableValue> stock = new List<ObservableValue>();

      bool initial = true;
      private void LoadData()
      {
      string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:DatabasesubDB.mdb";

      using (OleDbConnection conn = new OleDbConnection(strConn))
      {
      conn.Open();
      string strSQL = "SELECT * FROM Units";
      OleDbCommand command = new OleDbCommand(strSQL, conn);

      using (OleDbDataReader reader = command.ExecuteReader())
      {
      while (reader.Read())
      {
      if (initial)
      {
      subs.Add(reader["Sub"].ToString());
      line.Add(reader["Line"].ToString());
      min.Add(Convert.ToDouble(reader["Minimum"]));
      max.Add(Convert.ToDouble(reader["Maximum"]));
      }
      stock.Add(reader["Stock"]);
      }
      }
      initial = false;
      }
      }


      Chart setup:



          public void chartSetup()
      {
      cartesianChart1.Series = new SeriesCollection
      {
      new ColumnSeries
      {
      Title = "Total",
      Fill = System.Windows.Media.Brushes.Crimson,
      Values = new ChartValues<ObservableValue>(stock)
      }
      };
      cartesianChart1.AxisX.Add(new Axis
      {
      Title = "Unit",
      FontSize = 15,
      Separator = new Separator
      {
      Step = 1,
      IsEnabled = false //disable it to make it invisible.
      },
      LabelsRotation = 45,
      Labels = new ChartValues<string>(subs)
      });

      cartesianChart1.AxisY.Add(new Axis
      {
      Title = "Total",
      FontSize = 15,
      ShowLabels = true,
      LabelFormatter = value => value.ToString("N")
      });
      }


      My issue is that I'm unable to implement ObservableValue for stock. I get the message: "Cannot convert from 'object' to
      LiveCharts.Defaults.ObservableValue










      share|improve this question















      I'm using LiveCharts to display a barchart with stock levels. The unit names and stock levels are stored in an access database, and these values are retrieved and put into Lists.



      The only thing that should really change is the value of stock so I wanted to track changes of the stock and update the database automatically, giving somewhat live data.



      What I want to happen is for the chart to automatically update when the value (stock) changes in the database. I don't want to update the entire table, only the value that has changed so that the animations show on individual bars when they're changed.



      I have the following code for loading my database values into the database:



          string units = new string[30];
      List<string> subs = new List<string>();
      List<string> line = new List<string>();
      List<double> min = new List<double>();
      List<double> max = new List<double>();
      List<ObservableValue> stock = new List<ObservableValue>();

      bool initial = true;
      private void LoadData()
      {
      string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:DatabasesubDB.mdb";

      using (OleDbConnection conn = new OleDbConnection(strConn))
      {
      conn.Open();
      string strSQL = "SELECT * FROM Units";
      OleDbCommand command = new OleDbCommand(strSQL, conn);

      using (OleDbDataReader reader = command.ExecuteReader())
      {
      while (reader.Read())
      {
      if (initial)
      {
      subs.Add(reader["Sub"].ToString());
      line.Add(reader["Line"].ToString());
      min.Add(Convert.ToDouble(reader["Minimum"]));
      max.Add(Convert.ToDouble(reader["Maximum"]));
      }
      stock.Add(reader["Stock"]);
      }
      }
      initial = false;
      }
      }


      Chart setup:



          public void chartSetup()
      {
      cartesianChart1.Series = new SeriesCollection
      {
      new ColumnSeries
      {
      Title = "Total",
      Fill = System.Windows.Media.Brushes.Crimson,
      Values = new ChartValues<ObservableValue>(stock)
      }
      };
      cartesianChart1.AxisX.Add(new Axis
      {
      Title = "Unit",
      FontSize = 15,
      Separator = new Separator
      {
      Step = 1,
      IsEnabled = false //disable it to make it invisible.
      },
      LabelsRotation = 45,
      Labels = new ChartValues<string>(subs)
      });

      cartesianChart1.AxisY.Add(new Axis
      {
      Title = "Total",
      FontSize = 15,
      ShowLabels = true,
      LabelFormatter = value => value.ToString("N")
      });
      }


      My issue is that I'm unable to implement ObservableValue for stock. I get the message: "Cannot convert from 'object' to
      LiveCharts.Defaults.ObservableValue







      c# winforms livecharts






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 10:49

























      asked Nov 22 at 10:35









      J. James

      226




      226
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          A LiveCharts Observable value expects to be initialized with a double so you need to convert the value of stock to that, and add an ObservableValue to the list rather than a raw value::



          stock.Add(new ObservableValue(Convert.ToDouble(reader["Stock"])));





          share|improve this answer























          • "Cannot convert from 'double' to LiveCharts.Defaults.ObservableValue when I try that
            – J. James
            Nov 22 at 11:33










          • Oops, edited answer!
            – stuartd
            Nov 22 at 11:48












          • Thanks, this definitely works! But the chart doesn't seem to update when a value is changed.
            – J. James
            Nov 22 at 13:06











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428993%2flivecharts-observable-value%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          A LiveCharts Observable value expects to be initialized with a double so you need to convert the value of stock to that, and add an ObservableValue to the list rather than a raw value::



          stock.Add(new ObservableValue(Convert.ToDouble(reader["Stock"])));





          share|improve this answer























          • "Cannot convert from 'double' to LiveCharts.Defaults.ObservableValue when I try that
            – J. James
            Nov 22 at 11:33










          • Oops, edited answer!
            – stuartd
            Nov 22 at 11:48












          • Thanks, this definitely works! But the chart doesn't seem to update when a value is changed.
            – J. James
            Nov 22 at 13:06















          up vote
          1
          down vote



          accepted










          A LiveCharts Observable value expects to be initialized with a double so you need to convert the value of stock to that, and add an ObservableValue to the list rather than a raw value::



          stock.Add(new ObservableValue(Convert.ToDouble(reader["Stock"])));





          share|improve this answer























          • "Cannot convert from 'double' to LiveCharts.Defaults.ObservableValue when I try that
            – J. James
            Nov 22 at 11:33










          • Oops, edited answer!
            – stuartd
            Nov 22 at 11:48












          • Thanks, this definitely works! But the chart doesn't seem to update when a value is changed.
            – J. James
            Nov 22 at 13:06













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          A LiveCharts Observable value expects to be initialized with a double so you need to convert the value of stock to that, and add an ObservableValue to the list rather than a raw value::



          stock.Add(new ObservableValue(Convert.ToDouble(reader["Stock"])));





          share|improve this answer














          A LiveCharts Observable value expects to be initialized with a double so you need to convert the value of stock to that, and add an ObservableValue to the list rather than a raw value::



          stock.Add(new ObservableValue(Convert.ToDouble(reader["Stock"])));






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 at 11:48

























          answered Nov 22 at 11:28









          stuartd

          49.7k1096123




          49.7k1096123












          • "Cannot convert from 'double' to LiveCharts.Defaults.ObservableValue when I try that
            – J. James
            Nov 22 at 11:33










          • Oops, edited answer!
            – stuartd
            Nov 22 at 11:48












          • Thanks, this definitely works! But the chart doesn't seem to update when a value is changed.
            – J. James
            Nov 22 at 13:06


















          • "Cannot convert from 'double' to LiveCharts.Defaults.ObservableValue when I try that
            – J. James
            Nov 22 at 11:33










          • Oops, edited answer!
            – stuartd
            Nov 22 at 11:48












          • Thanks, this definitely works! But the chart doesn't seem to update when a value is changed.
            – J. James
            Nov 22 at 13:06
















          "Cannot convert from 'double' to LiveCharts.Defaults.ObservableValue when I try that
          – J. James
          Nov 22 at 11:33




          "Cannot convert from 'double' to LiveCharts.Defaults.ObservableValue when I try that
          – J. James
          Nov 22 at 11:33












          Oops, edited answer!
          – stuartd
          Nov 22 at 11:48






          Oops, edited answer!
          – stuartd
          Nov 22 at 11:48














          Thanks, this definitely works! But the chart doesn't seem to update when a value is changed.
          – J. James
          Nov 22 at 13:06




          Thanks, this definitely works! But the chart doesn't seem to update when a value is changed.
          – J. James
          Nov 22 at 13:06


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428993%2flivecharts-observable-value%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)