Open zzl4883a opened 5 years ago
pieces2:
public void CreateChart(double[] dataX, double[] dataY) { if (dataX.Length == dataY.Length) { List<Microcharts.Entry> entryList = new List<Microcharts.Entry>(); for (int i = 0; i < dataX.Length; i++) { var entry = new Microcharts.Entry(float.Parse(dataY[i].ToString())) { Label = $"{ dataX[i].ToString()}", ValueLabel = $"{dataY[i].ToString()}", Color = SKColor.Parse("#45d758") }; entryList.Add(entry); } var entries = entryList.ToArray(); LineChart lineChart = new LineChart() { Entries = entries, LineMode = LineMode.Straight, LineSize = 4 }; Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { this.chartView.Chart = lineChart; }); } }
I have a problem for help~ I want to change the LineChart view dynamic. I put a button,the button's clicked_method called "CreateChart",and this method passes two parameters(double [] dataX and double [] dataY).
I want to change the LineChart view when I click the button pass different parameters(dataX and dataY). There are two pieces of code at the bottom,the pieces 1 code can show lineChart normal pieces 1: ` public MainPage() {
pieces2:
public void CreateChart(double [] dataX,double [] dataY) { if (dataX.Length == dataY.Length) { List<Microcharts.Entry> entryList = new List<Microcharts.Entry>(); for (int i = 0; i < dataX.Length; i++) { var entry = new Microcharts.Entry(float.Parse(dataY[i].ToString())) { Label = $"{ dataX[i].ToString()}", ValueLabel = $"{dataY[i].ToString()}", Color = SKColor.Parse("#45d758") }; entryList.Add(entry); } var entries = entryList.ToArray(); LineChart lineChart = new LineChart() { Entries = entries, LineMode = LineMode.Straight, LineSize = 4 }; Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { this.chartView.Chart = lineChart; }); }