Page 1 of 1
Changing the appearance of a point in a line series
Posted: Wed May 13, 2009 3:21 pm
by 13048070
Hi,
I'd like to change the appearance of a point on my line series based on the outcome of some condition and still retain the default style in the legend
To add the series I have the following - a default style/color is applied to the series.
Code: Select all
' Apply default style to series
Dim mySeries As New Steema.TeeChart.Styles.Line
With mySeries
.Color = GetColour() ' function returns a color - not shown
.ColorEach = True
.ColorEachLine = False
With .Pointer
.Style = Steema.TeeChart.Styles.PointerStyles.Circle
.HorizSize = 2
.VertSize = 2
.Visible = True
End With
.Title = GetTitle() ' function returns title - not shown
.XValues.DateTime = True
End With
When adding the points I use the following:
If my conditon is true then
Code: Select all
mySeries.Add(x, y, mySeries.Color) ' use the default color
otherwise
Code: Select all
mySeries.Add(x, y, Color.Black) ' use a different color
Is it possible to alter other attributes of the point like its size and shape (without having to change the series pointer properties each time)?
Also I've noted that once I set the ColorEach (or ColorEachLine?) property the series line and pointer disappear from the legend. Is it possible to attribute a default style to the relevant item in the legend (i.e. I'd still like the default style I applied to be visible in the legend as its only the odd point that will be different)?
Thanks,
Norman
Posted: Thu May 14, 2009 11:03 am
by 10050769
Hello norman,
Is it possible to alter other attributes of the point like its size and shape (without having to change the series pointer properties each time)?
Yes, is possible you could use a similar code as next using GetPointerStyle Event():
InitializeChart:
Code: Select all
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mySeries As New Steema.TeeChart.Styles.Line
TChart1.Aspect.View3D = False
mySeries.FillSampleValues()
TChart1.Series.Add(mySeries)
With mySeries
.ColorEach = True
.ColorEachLine = False
With .Pointer
.Style = Steema.TeeChart.Styles.PointerStyles.Circle
.HorizSize = 2
.VertSize = 2
.Visible = True
End With
.XValues.DateTime = True
End With
AddHandler mySeries.GetPointerStyle, AddressOf Line1_GetPointerStyle
TChart1.Legend.LegendStyle = Steema.TeeChart.LegendStyles.Series
End Sub
GetPointerStyle Event:
Code: Select all
Private Sub Line1_GetPointerStyle(ByVal series As Steema.TeeChart.Styles.CustomPoint, ByVal e As Steema.TeeChart.Styles.GetPointerStyleEventArgs)
If (series.YValues(e.ValueIndex) Mod 2 = 0) Then
e.Color = Color.Red
e.Style = Steema.TeeChart.Styles.PointerStyles.Circle
series.Pointer.HorizSize = 10
series.Pointer.VertSize = 10
Else
e.Color = Color.Black
e.Style = Steema.TeeChart.Styles.PointerStyles.Triangle
series.Pointer.HorizSize = 5
series.Pointer.VertSize = 5
End If
End Sub
Please check this code works fine.
Also I've noted that once I set the ColorEach (or ColorEachLine?) property the series line and pointer disappear from the legend. Is it possible to attribute a default style to the relevant item in the legend (i.e. I'd still like the default style I applied to be visible in the legend as its only the odd point that will be different)?
When you only draw series in legend, and you have differents forms for the pointer, and differents colors, of the value series, when series want draw the value don't know which to add. I recomend add a only fixed value for the series. You could examples in
All Features\Welcome !\Miscellaneous\Legend\OnDrawSymbol Event.
I hope that will helps.
Posted: Thu May 14, 2009 12:24 pm
by 13048070
Hi Sandra,
Thanks for the reply.
Your example using GetPointerStyle works, however I don’t know if it's appropriate for what I'm trying to do. You're changing the appearance of the pointer based on the value - however I wish to change the appearance based on the outcome of a condition that doesn't involve either the x or y value. Basically I make a call to a database and retrieve a set of rows which I iterate and then add to my chart. For example the pseudo code might look like this:
Code: Select all
Get rows from database
For each row in my resultset
Get x value from field1
Get y value from field2
test condition e.g. is value from field3 = value from field4
if condition is true
series.add(x value, y value, default point color)
else
series.add(x value, y value, custom point color)
end
Next
The GetPointerStyle executes after I've added all my points to the chart and executes once for each point in each series(?). I no longer have access to the underlying data at this stage to test my condition, and I can’t just assume to change the style of any point that is not the default color, as its possible that the default series color might also be the custom color (I allow the user to define the series color). So I'd have to keep track (in an array) perhaps of all points whose style I need to change and search this in the GetPointerStyle event? It just seems a lot of work and a bit of an inefficient way to do things. I would have hoped that there would be some way when adding data using the series Add method to specify rather than just a color but a pointer style, e.g.
Code: Select all
series.add(x value, y value, custom point style that includes color and shape and size properties)
Is there an event that executes immediately after point is added to the series in which I could change the style of the most recent point?
Regarding the legend I've noticed that if I set the ColorEachLine property to False and exclude the line setting the ColorEach property then the line and pointer styles appear in the legend, which is what I want. I can still add a point with a different color as I described previously i.e.
Thanks for the tip on re OnDrawSymbol. So if I had ColorEach set to true and ColorEachLine set to false then I'd have to create a custom image of a line with a symbol through it (or whatever the current style is) and add it in the manner described? Just thinking out loud (and perhaps I'm lazy) but it seems that changing the style of a point is kicking a off a lotta work or at least more than I'd hoped.
Thanks again though I appreciate the help,
Norman
Posted: Fri May 15, 2009 9:18 am
by 10050769
Hello Norman,
The GetPointerStyle executes after I've added all my points to the chart and executes once for each point in each series(?). I no longer have access to the underlying data at this stage to test my condition, and I can’t just assume to change the style of any point that is not the default color, as its possible that the default series color might also be the custom color (I allow the user to define the series color). So I'd have to keep track (in an array) perhaps of all points whose style I need to change and search this in the GetPointerStyle event? It just seems a lot of work and a bit of an inefficient way to do things. I would have hoped that there would be some way when adding data using the series Add method to specify rather than just a color but a pointer style, e.g.
The only way, for change Pointer value is using GetPointerStyle, because this event is created for this. On the other hand, at moment tu runs application, you haven't access to DB, you will need to make array for save all data and able to use in GetPointerStyle.
Thanks for the tip on re OnDrawSymbol. So if I had ColorEach set to true and ColorEachLine set to false then I'd have to create a custom image of a line with a symbol through it (or whatever the current style is) and add it in the manner described? Just thinking out loud (and perhaps I'm lazy) but it seems that changing the style of a point is kicking a off a lotta work or at least more than I'd hoped.
Exactly, If you only have one series, are choose values for defect, but when you can two series or more, automaticly change values for series, and in legend only appears the name of series and tChart can not add for defect one symbol, because don't know which puts and is better that you add manualy one symbol.
Thanks,
Posted: Fri May 15, 2009 10:00 am
by 13048070
Thank you
Posted: Fri May 15, 2009 4:43 pm
by 13048070
Hi,
If I add a point like so:
how can I check the value of the string value that I assigned to the point in the GetPointerStyle event? I note from your example you can get the y value thus:
Thanks,
Norman
Posted: Mon May 18, 2009 8:06 am
by 10050769
Hello norman,
If you can check value of string you could do next property:
Thanks,
Posted: Mon May 18, 2009 9:41 am
by 13048070
Hi Sandra,
Thanks.
I've noted a problem with exporting and restoring the chart to/from a template (as demonstrated elsewhere in TeeChart examples) - not all the settings are resolved correctly. For example on the click event of a button I add points to be graph as follows:
series.add(x,y,label,color)
I planned on temporarily using the label value to flag whether my point needs to be shown differently or not. In the GetPointerStyle event I check the value of the label and set the pointer style accordingly and then export the chart so that I can restore it during postback and not have to add the points and set the style again. For example GetPointerStyle looks like:
Code: Select all
If e.ValueIndex > -1 Then
If series.Labels(e.ValueIndex) = "change" Then
' custom style
e.Color = Color.Orange
e.Style = Steema.TeeChart.Styles.PointerStyles.Triangle
series.Pointer.HorizSize = 5
series.Pointer.VertSize = 5
Else
' default style
e.Color = series.Color
e.Style = Steema.TeeChart.Styles.PointerStyles.Circle
series.Pointer.HorizSize = 2
series.Pointer.VertSize = 2
End If
End If
' Export Chart to a MemoryStream template
Dim tmpChart As MemoryStream = New MemoryStream()
WebChart.Chart.Export.Template.Save(tmpChart)
' Save template to a Session variable
Session.Add("tmpChart", tmpChart)
When the chart is imported again all the points points are back to the default style. The GetPointerStyle event does not seem to get called again when the chart is imported so I cant set the styles again. Is this a bug? I posted another post a while back informing support of similar issues with exporting the chart see TF02014078.
Also rather than using the label is there a tag property of the point I can access and use. I have to reset the label property when I'm finished setting its style - otherwise they affect the x-axis labels (i.e. the datetime labels on the x-axis disappear). If the tag property was exportable(serializable?) I could use this instead.
Can you tell me when in the sequence of things does the GetPointerStyle event get called. I've noted so far that it get calls for each point in each series only if the series pointer style is visible(?), also gets called before the chart redraws (important as I have to force a redraw in places so I can get pixel coords and if I reset the label property too early the points I customise get set back again).
Thanks
Posted: Mon May 18, 2009 10:13 am
by narcis
Hi norman.
This is because when exporting/iimporting a chart its events are not exported and therefore you should reassign them when loading the chart.
Regarding the Tag property, it exists as an overall property to the series but not specific for each point.
Posted: Mon May 18, 2009 10:25 am
by 13048070
OK thanks, but I'm exporting the chart in an effort to avoid exactly that as I have to either temporarily store the points between postbacks or hit the database again...oh well