kirsan31 / winforms-datavisualization

System.Windows.Forms.DataVisualization provides charting for WinForms applications.
MIT License
47 stars 19 forks source link

Since v 1.9.0, some chart series are started from (0,0) #46

Closed mschmitz2 closed 1 year ago

mschmitz2 commented 1 year ago

Thank you for your great work on this project!

I have noticed an issue when updating from v1.8.0 to v1.9.0 in some of my charts, but not in others. I am not entirely sure sure what causes this issue. The only thing that sets these plots apart from others that are fine, is that they mix series of different types (3x Line series and 2x Point series) though I'm not sure how that would affect things internally.

With v1.9.0 I get this:

plot_v1 9

while for the same chart with v1.8.0 I get this, as expected:

plot_v1 8

Showing the entire x- and y-axes, one can see that for all line plot series the actual first data point is replaced by the point (0,0):

plot_v1 9_all values

kirsan31 commented 1 year ago

Thank you for your great work on this project!

Thank you 🙏

I have noticed an issue when updating from v1.8.0 to v1.9.0

Can it be somehow related to IsXValueIndexed breaking change? If no, then we need a repro project here...

mschmitz2 commented 1 year ago

Can it be somehow related to IsXValueIndexed breaking change?

I don't think it is as I'm not using indexed series here.

Does this work for you: ConsoleAppChartTest2.zip ?

I have tried to reduce the code to a minimum from the original solution. I am now plotting the same simple data twice: once as Point and once as Line. You can see that the data is plotted correctly when plotting as Point, but that the first data point is replaced with (0,0) when plotting as Line:

image

I could debug it up to the location where I set the data to Chart1.Series:

prop_vals[seriesIdx].xAxVals.Zip(prop_vals[seriesIdx].ySeries, (xVal, o) => (xVal, o.yVal, o.ptLabel))
    .ToList()
    .ForEach(o =>
    {
        var pt = new DataPoint(o.xVal, o.yVal);
        if (o.ptLabel != null)
            pt.Label = o.ptLabel;
        if (double.IsNaN(o.yVal))
            pt.IsEmpty = true;
        Chart1.Series[seriesIdx].Points.Add(pt);
    });

after which Chart1.Series[0].Points still has the correct values. So something must happen in the background after this.

kirsan31 commented 1 year ago

Thanks @mschmitz2, I will look into it...

kirsan31 commented 1 year ago

With points all are ok: image So, this is some kind of drawing glitch🤔 It's all very strange, need more investigation, when I will have a time... P.s. you have a cross thread problems (accessing controls not from GUI thread) in you app. P.p.s try to avoid unnecessary ToList() (it's can be a real problem with large data).

mschmitz2 commented 1 year ago

Thanks for looking into it!

P.s. you have a cross thread problems (accessing controls not from GUI thread) in you app.

Yes, I removed the code dealing with that for this example since it works fine for the purpose of this.

P.p.s try to avoid unnecessary ToList() (it's can be a real problem with large data).

Thanks! It's indeed time I go through the code this is extracted from to look for performance improvements. A lot of this has just been adding new features quickly, one of which might have required a List..

kirsan31 commented 1 year ago

Regression was introduced in 83bdc36379b44eb6bfaa66fbed39b6994327b6c8. I implemented the fix. But in my point of view problems was only with 1 points of series: image Red question is strange (or may be here we have 3 series)?

Also I found that 83bdc36379b44eb6bfaa66fbed39b6994327b6c8 commit introduced a problems with empty points when they are visible: image I totally missed that empty point can be not so empty 🤦‍♂️🙄

mschmitz2 commented 1 year ago

Confirming that 1.9.1 fixes all the original issues, including the red case. All back to how it looked with 1.8:

image

Thanks for the quick fix!