Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic LineChart GridType.Crossed doesn't work and how to achieve custom positioning of grid lines? (Read 3929 times)
trbld21
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: Apr 18th, 2020
LineChart GridType.Crossed doesn't work and how to achieve custom positioning of grid lines?
Apr 19th, 2020 at 11:10am
Print Post  
Hi.
I am trying to plot some values using LineChart but I have two issues:

a) Although I do use
Code (C++)
Select All
lineChart.GridType = GridType.Crossed; 

I get same result as when using GridType.Vertical. How can I display both Vertical and Horizontal grid lines (i.e. Crossed Lines)? Do I miss something?

b) The code for Y-Axis is shown below (X-Axis is similar). What I'm trying to achieve is a maximum MaxYAxisNumbers = 20 number of horizontal grid lines, thus to display for the vertical range [0-144], ten grid lines, but not at fractional positions. E.g. I want [0, 7, 17, ..., 133]. However the following code, which depends on CustomLabelPosition.AutoScalePoints; leads to fractional grid lines [0, 7.2, 14.4, ..., 136.8]. From what I understand the "AutoScalePoints" places the grid lines at fractional positions that I can't affect.
Thus is there any way to place the grid lines at my custom position i.e. providing a List<double> somewhere as input?

Code (C++)
Select All
// Axis - Y
const int MaxYAxisNumbers = 20
Axis axisY = new Axis();
axisY.MinValue = 0;
axisY.MaxValue = 144;
axisY.Title = "Items";
axisY.Interval = 1;
axisY.Tick = 1;
axisY.Tag = "Y-Axis";
axisY.TitleRotationAngle = 270;
double usedMaxYAxisNumbers = (double)MaxYAxisNumbers;

double diffDistanceY = axisY.MaxValue - axisY.MinValue;
if (diffDistanceY < (double)MaxYAxisNumbers)
		usedMaxYAxisNumbers = diffDistanceY;

double diffStepY = diffDistanceY / usedMaxYAxisNumbers;
List<string> axisListY = new List<string>();
{
		for (double idx = axisY.MinValue; idx < axisY.MaxValue; idx += diffStepY)
				axisListY.Add(idx.ToString());
}

axisY.IntervalCount = (int)usedMaxYAxisNumbers;
axisY.LabelType = LabelType.CustomText;
axisY.CustomLabelPosition = CustomLabelPosition.AutoScalePoints;
axisY.Labels = axisListY.AsReadOnly();
lineChart.YAxes.Add(axisY);
lineChart.GridType = GridType.Crossed;
 



Any help would be appreciated.
Thanks.
  
Back to top
 
IP Logged
 
Iva_P
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: LineChart GridType.Crossed doesn't work and how to achieve custom positioning of grid lines?
Reply #1 - Apr 20th, 2020 at 3:43pm
Print Post  
Hi,
The first problem is most likely caused by opaque brushes. The  grid stripes are drawn in stripes first in the one direction, than the other. So, the horizontal grid stripes overlap the vertical, if drawn after them. I don't remember the sequence of drawing but it can be fixed by using semi-transparent brushes:

lineChart1.GridFills.Clear();
lineChart1.GridFills.Add(new SolidColorBrush(Color.FromArgb(100, 255, 0, 0)));
lineChart1.GridFills.Add(new SolidColorBrush(Color.FromArgb(100, 0, 255, 0)));
lineChart1.GridFills.Add(new SolidColorBrush(Color.FromArgb(100, 0, 0, 255)));

For the second problem - custom positions for the grid stripes, we will add a new GridType.Custom and will try to upload the updated assemblies tomorrow.

Kind Regards,
Iva

  
Back to top
 
IP Logged
 
Iva_P
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: LineChart GridType.Crossed doesn't work and how to achieve custom positioning of grid lines?
Reply #2 - Apr 21st, 2020 at 10:25am
Print Post  
Hi,

Here is the link to download the updated assemblies:

https://mindfusion.eu/_temp/grid_custom.zip

We have added new member to the GridType enumeration called GridType.Custom. The XGridLines and YGridLines properties are arrays that expect the numeric values of the points that should mark the grid stripes and mark. Here is sample code:

lineChart1.GridFills.Clear();
lineChart1.GridFills.Add(new SolidColorBrush(Color.FromArgb(100, 255, 0, 0)));
lineChart1.GridFills.Add(new SolidColorBrush(Color.FromArgb(100, 0, 255, 0)));
lineChart1.GridFills.Add(new SolidColorBrush(Color.FromArgb(100, 0, 0, 255)));
lineChart1.GridFills.Add(new SolidColorBrush(Color.FromArgb(100, 153, 0, 204)));
lineChart1.GridFills.Add(new SolidColorBrush(Color.FromArgb(100, 102, 153, 0)));
                 

lineChart1.GridStrokes.Clear();
lineChart1.GridStrokes.Add(new SolidColorBrush(Colors.Purple));
lineChart1.GridStrokes.Add(new SolidColorBrush(Colors.Orange));
lineChart1.GridStrokes.Add(new SolidColorBrush(Colors.White));

lineChart1.GridStrokeThickness = 5;
lineChart1.GridType = GridType.Custom;

Let us know if it works OK and is what you need.

Kind Regards,
Iva
  
Back to top
 
IP Logged
 
Iva_P
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: LineChart GridType.Crossed doesn't work and how to achieve custom positioning of grid lines?
Reply #3 - Apr 21st, 2020 at 10:26am
Print Post  
And of course here is how you initialize the grid points:

lineChart1.XGridLines = new DoubleCollection() { 10, 90, 100, 105 };
lineChart1.YGridLines = new DoubleCollection() { 10, 120, 90};
  
Back to top
 
IP Logged
 
trbld21
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: Apr 18th, 2020
Re: LineChart GridType.Crossed doesn't work and how to achieve custom positioning of grid lines?
Reply #4 - Apr 22nd, 2020 at 3:02pm
Print Post  
Hi Iva_P,

I downloaded the grid_custom.zip, but when I replace the dlls and I try to use lineChart.YGridLines as
Code (C++)
Select All
DoubleCollection axisGridY = new DoubleCollection();
// ... Fill up data same as labels ...
lineChart.YGridLines = axisGridY;
 



I get an error:

'Error      CS1061      'LineChart' does not contain a definition for 'YGridLines' and no accessible extension method 'YGridLines' accepting a first argument of type 'LineChart' could be found (are you missing a using directive or an assembly reference?)      <filepath>      173      N/A'

Just to say I've downloaded and working on the 'MindFusion.Charting.Wpf.2.2.0' from the NuGet Packages. Thus I just replaced the .dlls in the folder:

packages\MindFusion.Charting.Wpf.2.2.0\lib\net40 with the ones that exist in the grid_custom.zip.

I noticed that there are no .xml files in the zipped file you uploaded but there are 3 xml in the NuGet package which has not been replaced by something new.

Should I use in some other way the grid_custom.zip's data?

Thanks
  
Back to top
 
IP Logged
 
Iva_P
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: LineChart GridType.Crossed doesn't work and how to achieve custom positioning of grid lines?
Reply #5 - Apr 23rd, 2020 at 5:46am
Print Post  
Hi,

I have uploaded a project with the new libraries referenced and included here:

https://mindfusion.eu/samples/wpf/charting/Charting.Sales.zip

We have not updated the package on NuGet yet, so it gets the old version. In your project, you need to remove the NuGet reference and add the libraries I've sent you through the menu in VS References ->(right click) Add Reference and browse to the new MindFusion.Charting.Wpf and the new MindFusion.Licensing.Wpf.

I've done this in the uploaded project.

Kind Regards,
Iva
  
Back to top
 
IP Logged
 
Iva_P
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: LineChart GridType.Crossed doesn't work and how to achieve custom positioning of grid lines?
Reply #6 - Apr 23rd, 2020 at 6:21am
Print Post  
We expect to update the NuGet packages next week. I will post you a message when we've done it.
  
Back to top
 
IP Logged
 
Iva_P
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: LineChart GridType.Crossed doesn't work and how to achieve custom positioning of grid lines?
Reply #7 - May 1st, 2020 at 12:10pm
Print Post  
Hi,
We have uploaded the version with custom grid points on nuget:

https://www.nuget.org/packages/MindFusion.Charting.Wpf

Kind Regards,
Iva
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint