Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
255
Font set in ChartDrawItemis set to all following items, how to prevent?
posted

If I change a the Font of single Text primitive within the ChartDrawItem event-handler, this affects *all* Text primitives drawn afterward. How can I prevent this?

For example if I have a GanttChart with 4 entries:

GanttDataSource ganttData = new GanttDataSource();
GanttSeries ganttSeries = ganttData.Series.Add("Series A");
ganttSeries.Label = "";
GanttItem task1 = ganttSeries.Items.Add("Task 1");
GanttItem task2 = ganttSeries.Items.Add("Task 2");
GanttItem task3 = ganttSeries.Items.Add("foo");
GanttItem task4 = ganttSeries.Items.Add("foo2");
series = ganttSeries;
xAxis.Labels.Orientation = TextOrientation.VerticalLeftFacing;
xAxis.Labels.ItemFormatString = "<ITEM_LABEL:MMM dd, yyyy>";
yAxis.Labels.ItemFormatString = "<ITEM_LABEL>";
chartLayer.ChartType = ChartType.GanttChart;
SetAxisTypes(chartLayer);
this.UltraChart1.Series.Add(series);
chartLayer.Series.Add(series);
UltraChart1.ChartDrawItem += new Infragistics.UltraChart.Shared.Events.ChartDrawItemEventHandler(UltraChart1_ChartDrawItem);


and then want to change the font of only foo I try:


void UltraChart1_ChartDrawItem(object sender, Infragistics.UltraChart.Shared.Events.ChartDrawItemEventArgs e)
{
    if (e.Primitive is Text)
    {
        Text text = (Text)e.Primitive;
        if (text.GetTextString() == "foo")
        {
            text.labelStyle.Font = new Font(FontFamily.GenericSansSerif, 15, FontStyle.Bold);
        }
    }
}

but the result is that both "foo" and "foo2" are now in style 15pt Bold. I only want text.labelStyle.Font to affect the single item I have in ChartDrawItem, how can I do this?

Thanks

Ben

Parents
No Data
Reply
  • 17605
    posted

    Try using this code:

    if (text.GetTextString() == "foo")

    {

    LabelStyle labelStyle = text.labelStyle.Copy();

          labelStyle.Font = new Font(FontFamily.GenericSansSerif, 15, FontStyle.Bold);

     

          text.labelStyle = labelStyle;

    }

    Also you can try applying the latest service release, because even without cloning the labelstyle first, I’m not able to reproduce this issue on my machine.

Children
No Data