Hello,
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.
Valentin.
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".
<
telerik:RadCartesianChart.Grid
>
<
telerik:CartesianChartGrid
MajorLinesVisibility
=
"XY"
>
<
telerik:CartesianChartGrid.MajorXLineStyle
>
<
Style
TargetType
=
"Line"
>
<
Setter
Property
=
"Stroke"
Value
=
"Red"
/>
</
Style
>
</
telerik:CartesianChartGrid.MajorXLineStyle
>
<
telerik:CartesianChartGrid.MajorYLineStyle
>
<
Style
TargetType
=
"Line"
>
<
Setter
Property
=
"Stroke"
Value
=
"Green"
/>
</
Style
>
</
telerik:CartesianChartGrid.MajorYLineStyle
>
</
telerik:CartesianChartGrid
>
</
telerik:RadCartesianChart.Grid
>
Hope this information is helpful.
Regards,
Dinko
Telerik
Hello,
Yes, is that I searched.
So, I want to change it in code, and I can't give "Line" to TargetType :
Style st =
new
Style();
st.TargetType =
"?"
;
//Here
this
.chartVariables.Grid.MajorXLineStyle = st;
Few month, I had tried this :
couleurLignesHorizontales =
new
SolidColorBrush(
this
.cpCouleurLigne.SelectedColor);
((SolidColorBrush)((Setter)
this
.chartVariables.Grid.MajorXLineStyle.Setters[0]).Value).Color = couleurLignesHorizontales.Color;
// OR
((Setter)
this
.chartVariables.Grid.MajorXLineStyle.Setters[0]).Value = couleurLignesHorizontales;
But the compiler said me that the value is sealed and i can't modify it.
Thank you
The TargetType property of the Style is of type Type and this is why you need to set it to a typeof(Line):
st.TargetType =
typeof
(Line);
You got the "sealed" exception because the Style was already in use and you cannot modify it.
Regards,
Petar Marchev
Telerik
I've done this :
Style st =
new
Style();
st.TargetType =
this
.chartVariables.Grid.MajorXLineStyle.TargetType;
//typeof(/*Not found*/);
Setter newSetter =
new
Setter();
newSetter.Value = couleurLignesHorizontales;
st.Setters.Add(newSetter);
this
.chartVariables.Grid.MajorXLineStyle = st;
(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 ?
Hello,
To try to apply the changement, I tried this :
this
.chartVariables.Grid.MajorLinesVisibility = GridLineVisibility.None;
this
.chartVariables.Grid.MajorLinesVisibility = GridLineVisibility.X;
[..] to "reload" the grid. But there is an error :
"Not equal value to null compulsory for ' Setter. Property"
Thanks
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.
Regards,
Petar Marchev
Telerik
Hello Petar,
Effectively, do not need to touch at the new Setter.
Now, it's working very nice, thank you !
Valentin.