Hello,
I'm struggling with adding a secondary axis to a chart. The following code snippet produces the attached charting result "onlyPrimaryAxis.png":
C#for (int i = 0; i < plotSeries.Count(); i++)
{
var ser = plotSeries.ElementAt(i);
var chartSeries = chart.Series[i];
Color color = ColorTranslator.FromHtml(ser.ChartColor);
chartSeries.Outline.SetSolidFill(color);
chartSeries.Fill.SetSolidFill(color);
chartSeries.SeriesName.SetValue(ser.Name);
}
Changing the above to:
C#for (int i = 0; i < plotSeries.Count(); i++)
{
var ser = plotSeries.ElementAt(i);
var chartSeries = chart.Series[i];
Color color = ColorTranslator.FromHtml(ser.ChartColor);
chartSeries.Outline.SetSolidFill(color);
chartSeries.Fill.SetSolidFill(color);
chartSeries.SeriesName.SetValue(ser.Name);
if (ser.Axis == 2)
chartSeries.AxisGroup = AxisGroup.Secondary;
}
gives the attached chart "addSecondaryAxis.png".
If i instead change the code to be:
C#for (int i = 0; i < plotSeries.Count(); i++)
{
var ser = plotSeries.ElementAt(i);
var chartSeries = chart.Series[i];
Color color = ColorTranslator.FromHtml(ser.ChartColor);
if (ser.Axis == 2)
chartSeries.AxisGroup = AxisGroup.Secondary;
chartSeries.Outline.SetSolidFill(color);
chartSeries.Fill.SetSolidFill(color);
chartSeries.SeriesName.SetValue(ser.Name);
}
I now get a crash. The DevExpress portion of the stack trace is:
C#System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=Can't use delete object.
Source=DevExpress.Spreadsheet.v15.1.Core
StackTrace:
at DevExpress.XtraSpreadsheet.API.Native.Implementation.NativeObjectBase.CheckValid()
at DevExpress.XtraSpreadsheet.API.Native.Implementation.NativeSeries.CreateNativeShapeFormat()
at DevExpress.XtraSpreadsheet.API.Native.Implementation.NativeSeries.get_Outline()
Please advise if there's something I'm doing wrong.
thank you.
EDIT: I note I can't attach two files, I'll try a followup comment to attach the 2nd one
2nd attachment showing wrong chart output
Sorry, I should have noted the line at which the crash occurs. it's on:
Hi,
It looks like your code is incomplete because it is unclear how the "plotSeries" object is defined. Would you please provide us with a self-contained code example so that we can compile and debug it locally? I am sure we will be able to find the solution once we replicate the issue.
Thanks for looking at this Alessandro.
The plotSeries object contains just what you see - a color and a name, along with other info that's not passed to or used by DevExpress. I would have hoped that the stack trace and chart images would have been enough to diagnose this.
While I could take the time to build up a stand-alone solution reproducing this, it would be faster for me to take any solution you might have which makes use of a secondary axis in an ASPxSpreadSheet and convert that. Do you have a full working example available?
Thank you,
I re-read my original post and I may not have been clear on the problem.
If you look at the 1st image with only the primary axis, both series are shown. Series 1 is yellow and shows up smashed at the bottom of the chart because of the scale differences . Series 2 is red and in the middle.
In the 2nd image, the second series is orange-ish in the middle, but Series 1 is completely missing. It's the missing series that is my main concern.
Alessandro, would it be of use to you to be able to step through the code here? We can open a hole in our firewall for you to see it live if that could help.
Hello Don,
I have thoroughly researched all the details you provided and tried to reproduce the same behavior in a project using your code snippets, but my attempts were unsuccessful. Please see the attachment.
You can find the "Change Color" button. When you click it, one color of the chart series will be changed.
Would you please check the project and add the missing details, so I can test it on my side and see the problem? This will allow us to collect more information on why the issue occurs on your side and find a solution, or proceed with researching your scenario remotely.
I am waiting for your response.
Stason, Alessandro -
I've attached a visual studio solution which should serve as a complete demonstration of *two distinct* bugs we've found:
Bug #1: when using secondary axes, you must assign the primary axis before the secondary. If you do not, the series name and color will not be respected.
Bug #2 (by far more serious): you can not use a secondary axis if the ranges are built against a set of dates for the x-axis. If you try to, the series placed on the secondary axis will not be rendered.
running the code produces a set of 4 charts, which I'll place in the next comment so you can quickly see what I'm talking about. All 4 charts use the same data, but differ as to how the secondary axis is handled and the use of dates for the x-axis.
if you have any suggestions/work-arounds, etc. they would be most appreciated. This is a show-stopper for our client.
Thank you
The image the code generates - demonstrating the 2 bugs.