I want to change the color of vertical and horizontal gridLines of my chart (target on my screen '12'), but I don't find which property can do this changement..
The MajorXLine and MajorYLine don't have a semblable property.
Can you help me ?
Thank you very much.
7 Answers, 1 is accepted
In order to change the color of the vertical and horizontal grid lines of the chart, you can specify a custom Style to the MajorXLineStyle / MajorYLineStyle. Keep in mind that the TargetType property of the custom style should be set to "Line".
For your convenience, we have prepared a sample project demonstrating this approach. In addition, you can take a look at the CartesianChartGrid and PolarChartGrid help article in our documentation.
Hope this information is helpful.
Yes, is that I searched.
So, I want to change it in code, and I can't give "Line" to TargetType :
Few month, I had tried this :
But the compiler said me that the value is sealed and i can't modify it.
The TargetType property of the Style is of type Type and this is why you need to set it to a typeof(Line):
You got the "sealed" exception because the Style was already in use and you cannot modify it.
I've done this :
(I did : st.TargetType = this.chartVariables.Grid.MajorXLineStyle.TargetType; because I cannot access to "Line" for the 'TargetType').
But the changement is never effective.
=> How I can apply the changements ?
To try to apply the changement, I tried this :
[..] to "reload" the grid. But there is an error :
"Not equal value to null compulsory for ' Setter. Property"
I do not know why you say that the type is Not Found. Perhaps you have not included the correct namespace. Line is a simple class and you should be able to declare a reference to a Line and if you can do this, you should be able to get the Line's type.
I have created a simple project to demonstrate how to get it done. As I mentioned before, you are not allowed to modify a Style once it is in use, so make sure to fully set it up prior to passing it to the grid. Make sure you never modify this style afterwards.
As you have discovered on your own, there seems to be a bug in the grid where dynamic change of line styles is not anticipated and when you change the style, the change is not applied. In order to work around the bug you can use the code you already have that toggles the visibility of the lines.
Effectively, do not need to touch at the new Setter.
Now, it's working very nice, thank you !