Donation
Send us an email if you need help or have some suggestions:
t.office@gmx.netIf you want to support our developement, you can donate here:
Example (WinForms)
This is the small source code behind:
namespace WfChart_Test
{
public partial class Form1 : Form
{
List lineData = new List();
List barData = new List();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
simpleChart1.Refresh();
simpleChart1.chartZoomChangedEvent += SimpleChart1_chartZoomChangedEvent;
}
private void SimpleChart1_chartZoomChangedEvent(double xMin, double xMax, double yMin, double yMax)
{
}
double gauss(double x, double a, double b, double c)
{
var v1 = (x - b);
var v2 = (v1 * v1) / (2 * (c * c));
var v3 = a * Math.Exp(-v2);
return v3;
}
private void buttonFillData_Click(object sender, EventArgs e)
{
ChiChart_Scale xScale = new ChiChart_Scale()
{
mode = ChiChart_ScaleMode.Time,
sUnit = "",
StartTime = DateTime.Now,
sTimeFormat = "dd.MM.yyyy HH:mm:ss.fff"
};
//simpleChart1.setXScaleMode(xScale);
simpleChart1.clearPlots();
int num = 100;
float delta = 100.0f / ((float)num);
PointF[] plot1 = new PointF[num];
PointF[] plot2 = new PointF[num];
PointF[] plot3 = new PointF[num];
PointF[] plot4 = new PointF[num];
for (int i = 0; i < num; i++)
{
plot1[i] = new PointF(i * delta, (float)gauss(i * delta, 33, 57, 4));
plot2[i] = new PointF(i * delta, (float)gauss(i * delta, 100, 45, 4));
plot3[i] = new PointF(i * delta, (float)gauss(i * delta, 44, 70, 4));
plot4[i] = new PointF(i * delta, (float)gauss(i * delta, 55, 65, 4));
}
simpleChart1.addPlot(new ChiChart_Plot("Myplot1", Color.Red, plot1));
simpleChart1.addPlot(new ChiChart_Plot("Myplot2", Color.Blue, plot2, ChiChart_LineStyle.LineDown, ChiChart_PointStyle.None));
simpleChart1.addPlot(new ChiChart_Plot("Myplot3", Color.Green, plot3, ChiChart_LineStyle.LineDown, ChiChart_PointStyle.None, 3));
simpleChart1.addPlot(new ChiChart_Plot("Myplot4", Color.Purple, plot4, ChiChart_LineStyle.Line, ChiChart_PointStyle.Circle));
//cursors
simpleChart1.clearCursors();
simpleChart1.addCursor(new ChiChart_Cursor(30, false, Color.Red, 2, true, 0));
numCursor1.Value = new decimal(30);
simpleChart1.addCursor(new ChiChart_Cursor(84, false, Color.Blue, 2, true, 1));
//Ranges:
simpleChart1.clearRanges();
ChiChart_Range range1 = new ChiChart_Range(new ChiChart_Cursor(55, false, Color.Red, 2, true, 2),
new ChiChart_Cursor(66, false, Color.Blue, 2, true, 3),
Color.Aqua
);
simpleChart1.addRange(range1);
simpleChart1.setXRange(-11, num * 0.1);
simpleChart1.setYRange(-11, 120);
simpleChart1.Refresh();
simpleChart1.draw();
}
private void buttonAppendData_Click(object sender, EventArgs e)
{
int num = 100;
float delta = 100.0f / ((float)num);
List appendData = new List();
var data = simpleChart1.getData();
if (data.Count < 1)
return;
var lastPoint = data[0][data[0].Length-1];
appendData.Add(new PointF(lastPoint.X + 1, 11));
appendData.Add(new PointF(lastPoint.X + 1, 22));
appendData.Add(new PointF(lastPoint.X + 1, 33));
appendData.Add(new PointF(lastPoint.X + 1, 44));
simpleChart1.appendData(appendData);
simpleChart1.Refresh();
simpleChart1.draw();
}
private void checkBox_ShowLegend_CheckedChanged(object sender, EventArgs e)
{
simpleChart1.setShowLegend(checkBox_ShowLegend.Checked);
simpleChart1.Refresh();
simpleChart1.draw();
}
private void cb_selectViewMode_SelectedIndexChanged(object sender, EventArgs e)
{
if (cb_selectViewMode.Text == "Line")
{
simpleChart1.setViewMode(ViewMode.Line);
}
if (cb_selectViewMode.Text == "Bar")
{
simpleChart1.setViewMode(ViewMode.Bar);
}
simpleChart1.Refresh();
}
private void cb_changeColor_SelectedIndexChanged(object sender, EventArgs e)
{
if (cb_changeColor.Text=="White") {
simpleChart1.setBackgroundColor(Color.GhostWhite);
simpleChart1.setAxisColor(Color.Black);
simpleChart1.setGridColor(Color.Gray);
}
if (cb_changeColor.Text == "Black")
{
simpleChart1.setBackgroundColor(Color.Black);
simpleChart1.setAxisColor(Color.White);
simpleChart1.setGridColor(Color.Gray);
}
simpleChart1.Refresh();
}
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
simpleChart1.setShowGridHor(checkBox_ShowGrid.Checked);
simpleChart1.Refresh();
}
private void checkBoxTools_CheckedChanged(object sender, EventArgs e)
{
simpleChart1.setShowTools(checkBoxTools.Checked);
simpleChart1.Refresh();
}
private void checkBoxLog_CheckedChanged(object sender, EventArgs e)
{
simpleChart1.setYScaleLog(checkBoxLog.Checked);
simpleChart1.Refresh();
}
private void simpleChart1_cursorMovedEvent(object sender, int index, ChiChart_Cursor cur)
{
switch (cur.index)
{
case 0:
//cursor 1
numCursor1.Value = new decimal(cur.dPos);
break;
case 1:
//cursor 2
break;
default:
break;
}
}
private void numCursor1_ValueChanged(object sender, EventArgs e)
{
var curs = simpleChart1.GetCursors();
if (curs.Count < 1)
return;
curs[0].dPos = Convert.ToDouble(numCursor1.Value);
simpleChart1.SetCursors(curs);
simpleChart1.Refresh();
simpleChart1.draw();
}
}
}
Example (WINUI)
Source Code (with MVVM binding)
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using CommunityToolkit.Mvvm.DependencyInjection;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace ChironTestWinui
{
///
/// An empty window that can be used on its own or navigated to within a Frame.
///
public sealed partial class MainWindow : Window
{
public MainViewModel ViewModel { get; }
public MainWindow()
{
ViewModel = new MainViewModel();
this.InitializeComponent();
myChart.cursorMovedEvent += MyChart_cursorMovedEvent;
}
private void MyChart_cursorMovedEvent(object sender, int index, ChironChartWinUI_CS.Helper.ChiChart_Cursor cur)
{
ViewModel.cursorMoved(cur);
}
private void myButton_Click(object sender, RoutedEventArgs e)
{
myButton.Content = "Clicked";
}
}
}
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ChironChartWinUI_CS.Controls;
using ChironChartWinUI_CS.Helper;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.UI;
namespace ChironTestWinui
{
public class MainViewModel : ObservableRecipient
{
private double xScaleMin;
public double XScaleMin
{
get { return xScaleMin; }
set
{
xScaleMin = value;
OnPropertyChanged(nameof(XScaleMin));
}
}
private double xScaleMax;
public double XScaleMax
{
get { return xScaleMax; }
set
{
xScaleMax = value;
OnPropertyChanged(nameof(XScaleMax));
}
}
private ObservableCollection plots;
public ObservableCollection Plots
{
get { return plots; }
set
{
plots = value;
OnPropertyChanged(nameof(Plots));
}
}
private ObservableCollection _cursors;
public ObservableCollection Cursors
{
get { return _cursors; }
set
{
_cursors = value;
OnPropertyChanged(nameof(Cursors));
}
}
private string curPos;
public string CurPos
{
get { return curPos; }
set
{
curPos = value;
OnPropertyChanged(nameof(CurPos));
}
}
//private ChiChart_Cursor selectedCursor;
//public ChiChart_Cursor SelectedCursor
//{
// get { return selectedCursor; }
// set
// {
// selectedCursor = value;
// OnPropertyChanged(nameof(SelectedCursor));
// }
//}
public MainViewModel()
{
XScaleMin = 10;
XScaleMax = 90;
//SelectedCursor = new ChiChart_Cursor();
}
public void cursorMoved(ChiChart_Cursor cur)
{
}
double gauss(double x, double a, double b, double c)
{
var v1 = (x - b);
var v2 = (v1 * v1) / (2 * (c * c));
var v3 = a * Math.Exp(-v2);
return v3;
}
private ICommand dataCommand;
public ICommand DataCommand => dataCommand ?? (dataCommand = new AsyncRelayCommand(DataCommandAction));
private async Task DataCommandAction()
{
float num = 100;
ObservableCollection plots = new ObservableCollection();
//SolidColorBrush lineBrush = new SolidColorBrush(Colors.Red);
myLineSerie ser1 = new myLineSerie("L1", Colors.Red, ChiChart_LineStyle.Line, ChiChart_PointStyle.None);
myLineSerie ser2 = new myLineSerie("L2", Colors.Blue, ChiChart_LineStyle.LineDown, ChiChart_PointStyle.Square);
myLineSerie ser3 = new myLineSerie("L3", Colors.Green, ChiChart_LineStyle.LineDown, ChiChart_PointStyle.Circle, 2);
myLineSerie ser4 = new myLineSerie("L4", Colors.Purple, ChiChart_LineStyle.Line, ChiChart_PointStyle.None, 2);
float delta = 100.0f / num;
for (int i = 0; i < num; i++)
{
ser1.points.Add(new myPoint(i * delta, (float)gauss(i * delta, 33, 57, 4)));
ser2.points.Add(new myPoint(i * delta, (float)gauss(i * delta, 100, 45, 4)));
ser3.points.Add(new myPoint(i * delta, (float)gauss(i * delta, 44, 70, 4)));
ser4.points.Add(new myPoint(i * delta, (float)gauss(i * delta, 55, 65, 4)));
}
plots.Add(ser1);
plots.Add(ser2);
plots.Add(ser3);
plots.Add(ser4);
//cursors:
ObservableCollection myCursors = new ObservableCollection();
myCursors.Add(new ChiChart_Cursor(30, false, Colors.Red,2,true,0));
myCursors.Add(new ChiChart_Cursor(84, false, Colors.Blue,2,true,1));
//myChart.Cursors = myCursors;
Plots = plots;
Cursors = myCursors;
}
}
}
Example (MAUI)
Source Code (with MVVM binding)
using ChironChartMaui;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace ChironChartMaui_Test
{
public class MainViewModel : INotifyPropertyChanged
{
public MainViewModel()
{
XMinInfo = "1";
XMaxInfo = "3";
YMinInfo = "1";
YMaxInfo = "2";
ButtClickCommand = new Command(
execute: () =>
{
((Command)ButtClickCommand).ChangeCanExecute();
plotData();
},
canExecute: () => true);
}
public event PropertyChangedEventHandler PropertyChanged;
public ICommand ButtClickCommand { get; private set; }
string xMinInfo;
public string XMinInfo
{
get
{
return xMinInfo;
}
private set
{
if (xMinInfo != value)
{
xMinInfo = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("XMinInfo"));
XMin = Convert.ToDouble(value);
}
}
}
string xMaxInfo;
public string XMaxInfo
{
get
{
return xMaxInfo;
}
private set
{
if (xMaxInfo != value)
{
xMaxInfo = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("XMaxInfo"));
XMax = Convert.ToDouble(value);
}
}
}
string yMinInfo;
public string YMinInfo
{
get
{
return yMinInfo;
}
private set
{
if (yMinInfo != value)
{
yMinInfo = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("YMinInfo"));
YMin = Convert.ToDouble(value);
}
}
}
string yMaxInfo;
public string YMaxInfo
{
get
{
return yMaxInfo;
}
private set
{
if (yMaxInfo != value)
{
yMaxInfo = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("YMaxInfo"));
YMax = Convert.ToDouble(value);
}
}
}
double xMin;
public double XMin
{
get
{
return xMin;
}
private set
{
if (xMin != value)
{
xMin = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("XMin"));
}
}
}
double xMax;
public double XMax
{
get
{
return xMax;
}
private set
{
if (xMax != value)
{
xMax = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("XMax"));
}
}
}
double yMin;
public double YMin
{
get
{
return yMin;
}
private set
{
if (yMin != value)
{
yMin = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("YMin"));
}
}
}
double yMax;
public double YMax
{
get
{
return yMax;
}
private set
{
if (yMax != value)
{
yMax = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("YMax"));
}
}
}
ObservableCollection plots;
public ObservableCollection Plots
{
get
{
return plots;
}
private set
{
if (plots != value)
{
plots = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Plots"));
}
}
}
ObservableCollection cursors;
public ObservableCollection Cursors
{
get
{
return cursors;
}
private set
{
if (cursors != value)
{
cursors = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Cursors"));
}
}
}
double gauss(double x, double a, double b, double c)
{
var v1 = (x - b);
var v2 = (v1 * v1) / (2 * (c * c));
var v3 = a * Math.Exp(-v2);
return v3;
}
void plotData()
{
int num = 100;
ObservableCollection plots = new ObservableCollection();
//SolidColorBrush lineBrush = new SolidColorBrush(Colors.Red);
ChiChart_LineSerie ser1 = new ChiChart_LineSerie("L1", Colors.Red, ChiChart_LineStyle.Line, ChiChart_PointStyle.None);
ChiChart_LineSerie ser2 = new ChiChart_LineSerie("L2", Colors.Blue, ChiChart_LineStyle.LineDown, ChiChart_PointStyle.Square);
ChiChart_LineSerie ser3 = new ChiChart_LineSerie("L3", Colors.Green, ChiChart_LineStyle.LineDown, ChiChart_PointStyle.Circle, 2);
ChiChart_LineSerie ser4 = new ChiChart_LineSerie("L4", Colors.Purple, ChiChart_LineStyle.Line, ChiChart_PointStyle.None, 2);
float delta = 100.0f / num;
for (int i = 0; i < num; i++)
{
ser1.points.Add(new ChiChart_Point(i * delta, (float)gauss(i * delta, 33, 57, 4)));
ser2.points.Add(new ChiChart_Point(i * delta, (float)gauss(i * delta, 100, 45, 4)));
ser3.points.Add(new ChiChart_Point(i * delta, (float)gauss(i * delta, 44, 70, 4)));
ser4.points.Add(new ChiChart_Point(i * delta, (float)gauss(i * delta, 55, 65, 4)));
}
plots.Add(ser1);
plots.Add(ser2);
plots.Add(ser3);
plots.Add(ser4);
//cursors:
ObservableCollection myCursors = new ObservableCollection();
myCursors.Add(new ChiChart_Cursor(30, false, Colors.Red));
myCursors.Add(new ChiChart_Cursor(84, false, Colors.Red));
//myChart.Cursors = myCursors;
Plots = plots;
Cursors = myCursors;
}
}
}