How to display graph in LiveChart c# wpf? - c#

I am trying to use live chart for wpf c#. Generally I got it to work to display a graph. However when i try to call the function below more than once it does not execute the second time. Why? If I restart the program it works but only the first time again. Anybody familiar with live charts (lvcharts) library and can give me some direction. Thank you!
public void FillTheGraph(string[] axisX, double[] axisY)
{
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Title = "Graph",
Values = new ChartValues<double>(axisY)
},
};
Labels = axisX;
DataContext = this;
}

Related

C# WinForm chart data wont display

So I'm having a really weird problem in C# WindForm. I've tried to create a chart. In the area where the chart itself should exist, the problem is that it displays no data. It just looks like that:
That's my code:
int questionsAmount = setData.questionsAmount;
var dates = new List<DateTime>();
foreach(var item in setData.dates)
{
dates.Add(Convert.ToDateTime(item));
}
int[] records = setData["records"].ToObject<int[]>();
Series series = new Series("records");
series.Points.DataBindXY(dates, records);
series.ChartType = SeriesChartType.Spline;
chart = new Chart();
chart.Name = set.title;
chart.Series.Add(series);
chart.Series["records"].SetDefault(true);
chart.Series["records"].Enabled = true;
chart.BackColor = SystemColors.Highlight;
Controls.Add(chart);
Refresh();
Any help would be much appreciated. Thanks!
Hmm.. First, because we cannot read the entire code, I cannot sure the data generating process is working well. As your picture, the chart control is added. Maybe you can add breakpoint on "series.Points.DataBindXY(dates, records);" and check whether the data is ready or not.
FYI, another probable issue is you need to do UI operation in main thread (UI thread) if you didn't.
Hope these can help you.

How to animate live tiles using notification extensions?

I want to animate lives tiles in UAP applications. But I am getting this exception:
Cannot implicitly convert type 'NotificationsExtensions.Tiles.TileImageSource' to 'string'.
I am using this code:
TileBindingContentAdaptive largebindingContent = new TileBindingContentAdaptive()
{
PeekImage = new TilePeekImage()
{
Source = new TileImageSource("Assets/Apps/Hipstame/hipster.jpg")
},
Children =
{
new TileText() {Text =Description, Wrap = true, Style = TileTextStyle.BodySubtle}
}
};
How can I animate my live tiles?
Cannot implicitly convert type 'NotificationsExtensions.Tiles.TileImageSource' to 'string'.
The reason you are getting this exception is because as of May 2016 NotificationsExtensions received some updates where there have been changes made to TileBackgroundImage and TilePeekImage. You can see the details of these changes here in the msdn update post.
Specifically, the property type for Source changed from TileImageSource to string. This change means that you need to change the way you are setting Source. Note in the code below (yours, which I modified) where the Source is simply a string. This should resolve the exception you are getting.
TileBindingContentAdaptive largebindingContent = new TileBindingContentAdaptive()
{
PeekImage = new TilePeekImage()
{
Source = "Assets/Apps/Hipstame/hipster.jpg"
},
Children =
{
new TileText()
{
Text = Description,
Wrap = true,
Style = TileTextStyle.BodySubtle
}
}
};
As far as animating your live tiles there are a variety of things you can do and I cannot give any specific advice unless you specify what you want to do with your tiles. For example, if you want to cycle through images in your live tile you can take a look at this example here for cycling multiple images with an animation through a live tile. You can also refer to the msdn Adaptive Tile Templates documentation if you want to read through in more detail about what else you can do with your tiles.

Dynamic Data Display: hide the axis lable

I am a new gay on WPF and D3.
The value of X axis in my chart is not meaningful(just 1,2,3,....), so I want to hide the value, just keep the ticks.
How can I do this?
Tnx for anyone whose can help.
Know this has been up for a year but I stumbled across the question as I had the same problem. I was looking to remove the x axis as am just plotting Voltage vs time in real time and the time unit isn't important.
Anyway the solution turned out to be simple.
plotter.HorizontalAxis.Remove();
So my setup C# code behind the WPF now looks like this.
public graph()
{
InitializeComponent();
this.DataContext = this;
_voltagePointCollection = new VoltagePointCollection();
var ds = new EnumerableDataSource<VoltagePoint>(_voltagePointCollection);
//ds.SetXMapping(x => dateAxis.ConvertToDouble(x.Date));
ds.SetXMapping(x => x.tick);
ds.SetYMapping(y => y.Voltage);
plotter.AddLineGraph(ds, Colors.Green, 2, "Volts");
MaxVoltage = 1;
MinVoltage = 0;
BackgroundColor = Brushes.White;
YRangeMin = 0;
YRangeMax = 30;
plotter.HorizontalAxis.Remove();
plotter.LegendVisible = false;
}
Hope this helps someone.

VS2010 Microsoft.Windows.Controls.DataVisualization.Charting C# code for StackedChart

Im creating a silverlight application for now, and I'm having a difficulty how to set an itemssource variable for a stacked chart.
Im using Microsoft.Windows.Controls.DataVisualization.Charting library
I'm used to make a non-stacked chart like so
void getChartCompleted(object sender, GetChartCompletedEventArgs e)
{
Chart chart = new Chart();
BarSeries barSeries = new BarSeries()
{
ItemsSource = e.Result.Value,
DependentValueBinding = new Binding("Value"),
IndependentValueBinding = new Binding("Label")
};
chart.Series.Add(pieSeries);
stackPanelChart.Children.Add(chart);
}
Now, if I want it to be a stacked bar chart, how to set the 'e' variable? Also, what other setting should I appplied to the chart object?
Thanks

How to update Line series Chart with data consistently?

I have a simple line series chart using WPFToolKit. I would like to have new data coming in to be updated on the chart every 5 minutes. But I have no idea how to go about it. The way I am showing data now is this.
public Window1()
{
InitializeComponent();
showColumnChart();
}
private void showColumnChart()
{
List<KeyValuePair<double,double>> Power = new List<KeyValuePair<double, double>>();
Power.Add(new KeyValuePair<double, double>(30, 40));
Power.Add(new KeyValuePair<double,double>(50, 60));
//Setting data for line chart
lineChart.DataContext = Power;
}
Also, do I have to use a database? Any help would be appreciated.
Thanks,
Check http://www.c-sharpcorner.com/UploadFile/mahesh/WPfTimer09292009090518AM/WPfTimer.aspx (using Dispatcher Timer, you can achieve that).

Categories