Hi
I am totally new to LightninhChart.
I want to view 30 signals, but only (the one who is activated by click) will show its units
How do I make it?
Can I drag a line with the mouse only? how?
//Quantity of points
const int pointCount = 160000;
int yAxisCount = 30;
for (int axisY = 0; axisY < yAxisCount; axisY++)
{
AxisY yAxis = new AxisY(chartYM.ViewXY);
yAxis.AxisColor = DefaultColors.SeriesForBlackBackground[axisY % DefaultColors.SeriesForBlackBackground.Length];
yAxis.Title.Text = "Axis " + (axisY + 1).ToString();
yAxis.Title.Color = yAxis.AxisColor;
yAxis.SetRange(-10, 10);
yAxis.Visible = false;
chartYM.ViewXY.YAxes.Add(yAxis);
//Create a PointLineSeries for each axis, and fill it with data
PointLineSeries pls = new PointLineSeries(chartYM.ViewXY, axisX, yAxis);
//Make points invisible
pls.PointsVisible = false;
pls.LineStyle.Color = yAxis.AxisColor;
SeriesPoint[] points = new SeriesPoint[pointCount];
for (int point = 0; point < pointCount; point++)
{
points[point].X = (double)point;
points[point].Y = 50 * Math.Sin(2 * Math.PI * (axisY*2+1) / 8000.0 * point); // 100.0 * rand.NextDouble();
}
//Assign the data for the point line series
pls.Points = points;
chartYM.ViewXY.PointLineSeries.Add(pls);
}
multiple signals with focus on one
Moderator: Queue Moderators
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: multiple signals with focus on one
Hi,
to be able to help you more, I have to ask questions as I did't understand what you are trying to achieve.
When clicking one series, you want to
- show its value point by point
- edit one data point value by dragging one point up / down
Or something else?
Please include an illustrative picture, so we could help you with correct code example.
to be able to help you more, I have to ask questions as I did't understand what you are trying to achieve.
When clicking one series, you want to
- show its value point by point
- edit one data point value by dragging one point up / down
Or something else?
Please include an illustrative picture, so we could help you with correct code example.
LightningChart Support Team, PT
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: multiple signals with focus on one
I made this kind of example application, based the description you wanted. Hopefully I got it right
VS project:
How does this example meet your needs?
VS project:
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Arction.WinForms.Charting;
using Arction.WinForms.Charting.Axes;
using Arction.WinForms.Charting.Views;
using Arction.WinForms.Charting.Views.ViewXY;
using Arction.WinForms.Charting.EventMarkers;
using Arction.WinForms.Charting.SeriesXY;
using Arction.WinForms.Charting.Annotations;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
const int SeriesCount = 6;
const int PointCountPerSeries = 100;
LightningChartUltimate _chart;
PointLineSeries _seriesBeingTracked = null;
AnnotationXY _valueDisplay = null;
Random _rand = new Random();
public Form1()
{
InitializeComponent();
CreateChart();
}
void CreateChart()
{
_chart = new LightningChartUltimate();
_chart.BeginUpdate();
_chart.Parent = this;
_chart.Dock = DockStyle.Fill;
ViewXY v = _chart.ViewXY;
AxisX xAxis = v.XAxes[0];
xAxis.ValueType = AxisValueType.Number;
//Clear old Y axes
foreach (AxisY yAxis in v.YAxes)
{
yAxis.Dispose();
}
v.YAxes.Clear();
//Add new Y axes and series
for (int seriesIndex = 0; seriesIndex < SeriesCount; seriesIndex++)
{
Color color = DefaultColors.SeriesForBlackBackground[seriesIndex % DefaultColors.SeriesForBlackBackground.Length];
AxisY yAxis = new AxisY(v);
yAxis.AxisColor = color;
yAxis.Title.Color = color;
yAxis.AutoDivSeparationPercent = 10;
v.YAxes.Add(yAxis);
PointLineSeries pls = new PointLineSeries(v, xAxis, yAxis);
pls.LineStyle.Color = color;
pls.Points = GenerateData(seriesIndex);
pls.MouseClick += pls_MouseClick;
v.PointLineSeries.Add(pls);
}
//Create annotation to show tracked data value
_valueDisplay = new AnnotationXY(v, xAxis, v.YAxes[0]);
_valueDisplay.LocationCoordinateSystem = CoordinateSystem.RelativeCoordinatesToTarget;
_valueDisplay.Style = AnnotationStyle.RoundedCallout;
_valueDisplay.MouseInteraction = false;
_valueDisplay.Visible = false;
v.Annotations.Add(_valueDisplay);
//Set stacked layout
v.AxisLayout.YAxesLayout = YAxesLayout.Stacked;
//Hide legend box
v.LegendBox.Visible = false;
v.ZoomToFit();
_chart.MouseMove += _chart_MouseMove;
_chart.MouseClick += _chart_MouseClick;
_chart.Title.Text = "Click on series to start tracking it. Click elsewhere to stop tracking";
_chart.EndUpdate();
}
SeriesPoint[] GenerateData(int seriesIndex)
{
SeriesPoint[] points = new SeriesPoint[PointCountPerSeries];
for (int i = 0; i < PointCountPerSeries; i++)
{
points[i].X = i;
points[i].Y = (_rand.NextDouble()-0.5) * 2.0 + 10.0 * Math.Sin((double)i * (double) (seriesIndex+1) / 20.0);
}
return points;
}
void _chart_MouseClick(object sender, MouseEventArgs e)
{
//Detect if chart was clicked elsewhere than series.
bool overSeries = false;
foreach (PointLineSeries pls in _chart.ViewXY.PointLineSeries)
{
if (pls.IsMouseOver(e.X, e.Y))
{
overSeries = true;
break;
}
}
if (!overSeries)
{
_valueDisplay.Visible = false;
_seriesBeingTracked = null;
}
}
void _chart_MouseMove(object sender, MouseEventArgs e)
{
UpdateNearestValue(e);
}
void pls_MouseClick(object sender, MouseEventArgs e)
{
//Set series being tracked
_seriesBeingTracked = (PointLineSeries)sender;
_chart.BeginUpdate();
//Set correct Y axis for value display
_valueDisplay.AssignYAxisIndex = _seriesBeingTracked.AssignYAxisIndex;
//Change color for the value display
_valueDisplay.Fill.Color = ChartTools.CalcGradient(_seriesBeingTracked.LineStyle.Color, Color.White, 90);
_valueDisplay.Fill.GradientColor = ChartTools.CalcGradient(_seriesBeingTracked.LineStyle.Color, Color.White, 50);
//Update nearest value
UpdateNearestValue(e);
_chart.EndUpdate();
}
void UpdateNearestValue(MouseEventArgs e)
{
//Find nearest data point from the series being tracked (clicked previously)
_chart.BeginUpdate();
if (_seriesBeingTracked != null)
{
double x;
_chart.ViewXY.XAxes[0].CoordToValue(e.X,out x,false);
LineSeriesValueSolveResult res = _seriesBeingTracked.SolveYValueAtXValue(x);
if(res.SolveStatus == LineSeriesSolveStatus.OK)
{
double nearestX = _seriesBeingTracked.Points[res.NearestDataPointIndex].X;
double nearestY = _seriesBeingTracked.Points[res.NearestDataPointIndex].Y;
_valueDisplay.Visible = true;
_valueDisplay.Text = "X: "+nearestX.ToString("0.0")+"\nY: "+nearestY.ToString("0.0");
_valueDisplay.TargetAxisValues.SetValues(nearestX, nearestY);
}
else
{
_valueDisplay.Visible = false;
}
}
_chart.EndUpdate();
}
}
}
How does this example meet your needs?
LightningChart Support Team, PT