You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'll briefly describe the usage scenario of the requirement: I want to plot a smooth function graph and highlight specific points on the graph. For example, I want to plot a function f(x) = x^2 and then mark the positions (0,0) and (5,25) on the graph. Currently, the method I am using is to use a LineSeries to draw the line and set GeometrySize to 0 to hide evenly distributed points. Then I draw a ScatterSeries to specifically mark the points that need to be displayed.
However, by doing this, the ScatterSeries will use a different color than the LineSeries. I don't want to hardcode and force set the ScatterSeries to a specific color to match the LineSeries color because there may be future requirements to switch to different color schemes. So, I'm wondering if it's possible to set the color of the current series to be the same as the previous one? I noticed that there doesn't seem to be a way to get the color from LineSeries or its Stroke.
Here is my code:
usingLiveChartsCore;usingLiveChartsCore.Defaults;usingLiveChartsCore.Drawing;usingLiveChartsCore.SkiaSharpView;usingLiveChartsCore.SkiaSharpView.Painting;usingSkiaSharp;namespaceWpfApp1{publicclassQuadraticFunctionChart{publicISeries[]Series{get;set;}publicQuadraticFunctionChart(){LineSeries<ObservablePoint>line=newLineSeries<ObservablePoint>{DataPadding=newLvcPoint(0,0),Values=GenerateUniformData(),Fill=null,GeometrySize=0};ScatterSeries<ObservablePoint>points=newScatterSeries<ObservablePoint>{Values=GenerateCustomData(0,5),GeometrySize=10,// I don't want to hardcode the color.// Stroke = new SolidColorPaint(SKColors.DodgerBlue, 5f),Fill=newSolidColorPaint(SKColors.Azure),};Series=newISeries[]{line,points};}// Generate uniformly distributed x-y data from start to endstaticIEnumerable<ObservablePoint>GenerateUniformData(doublestart=-10,doubleend=10,intsegmentCount=100){doublestep=(end-start)/segmentCount;IEnumerable<double>x=Enumerable.Range(0,segmentCount+1).Select(i =>start+i*step);returnGenerateCustomData(x.ToArray());}// Generate x-y data by custom xstaticIEnumerable<ObservablePoint>GenerateCustomData(paramsdouble[]x){returnx.Select(d =>newObservablePoint(d,func.Invoke(d)));}staticFunc<double,double>func= x =>x*x;}}
BTW: For the requirement of plotting a uniform function graph but highlighting specific non-uniform points, is there a more sophisticated way to achieve this? With the current way, when zooming in on the chart, the ScatterSeries does not move closely along the line of the LineSeries like the built-in Geometry in LineSeries; instead, it lags behind for a short period, making it not look particularly seamless.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'll briefly describe the usage scenario of the requirement: I want to plot a smooth function graph and highlight specific points on the graph. For example, I want to plot a function
f(x) = x^2
and then mark the positions(0,0)
and(5,25)
on the graph. Currently, the method I am using is to use a LineSeries to draw the line and setGeometrySize
to 0 to hide evenly distributed points. Then I draw a ScatterSeries to specifically mark the points that need to be displayed.However, by doing this, the ScatterSeries will use a different color than the LineSeries. I don't want to hardcode and force set the ScatterSeries to a specific color to match the LineSeries color because there may be future requirements to switch to different color schemes. So, I'm wondering if it's possible to set the color of the current series to be the same as the previous one? I noticed that there doesn't seem to be a way to get the color from LineSeries or its Stroke.
Here is my code:
BTW: For the requirement of plotting a uniform function graph but highlighting specific non-uniform points, is there a more sophisticated way to achieve this? With the current way, when zooming in on the chart, the ScatterSeries does not move closely along the line of the LineSeries like the built-in Geometry in LineSeries; instead, it lags behind for a short period, making it not look particularly seamless.
Beta Was this translation helpful? Give feedback.
All reactions