This is a migrated thread and some comments may be shown as answers.

Dynamic Chart - Legend doesn't update

4 Answers 140 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Jako
Top achievements
Rank 1
Jako asked on 06 Nov 2013, 01:48 PM
Hi everyone

I have a HTMLChart that gets populated via the database, based on a drop down.

It works fine, it populates and sets the pie chart, but the legend doesn't update. For example, if the first selection has 2 values, I get two legends, but when I then I get a selection with 4 values, it stays 2 values in the legend? Also, I have set the DataFormatString, but it stays with 4 decimals for the yValue?

<telerik:RadHtmlChart ID="uxPieChart" runat="server">
    <PlotArea>
        <Series>
            <telerik:PieSeries StartAngle="90">
                <LabelsAppearance Position="Circle" DataFormatString="{0:C}" />
                <TooltipsAppearance DataFormatString="{0:C}" />
            </telerik:PieSeries>
        </Series>
    </PlotArea>
    <ChartTitle Text=""/>
</telerik:RadHtmlChart>
uxPieChart.PlotArea.Series.Clear();               
 
int fundID = int.Parse(uxFundList.SelectedValue);
 
DataTable dt = Fund.BudgetBreakDown(fundID);
 
PieSeries pieSeries = new PieSeries();
SeriesItem item;
 
foreach (DataRow budgetRow in dt.Rows)
{
    item = new SeriesItem();
    item.YValue = Decimal.Parse(budgetRow["Amount"].ToString());
    item.Name = budgetRow["Header"].ToString();
    pieSeries.Items.Add(item);
}
 
uxPieChart.PlotArea.Series.Add(pieSeries);
Any ideas?

Thank you

[EDIT] It was due to 0 Values coming through from the DB, you couldn't see it on the chart, but it created a legend. Sorted it out now.

4 Answers, 1 is accepted

Sort by
0
Stamo Gochev
Telerik team
answered on 07 Nov 2013, 02:08 PM
Hello Jako,

There shouldn't be a problem with the update of legend's items, so I am glad that you have managed to resolve the issue on your own.

Regards,
Stamo Gochev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Jako
Top achievements
Rank 1
answered on 07 Nov 2013, 02:18 PM
Hi Stamo

I still have the issue with the values not being displayed as a Currency?

As you can see I do set the DataFormatString but it's not working.

Am I missing something?

Thanks.
0
Stamo Gochev
Telerik team
answered on 12 Nov 2013, 06:36 AM
Hi Jako,

The reason why the PieSeries' labels are not formatted as a currency is that you have set the DataFormatString property for the PieSeries in the markup:
<telerik:PieSeries StartAngle="90">
    <LabelsAppearance Position="Circle" DataFormatString="{0:C}" />
    <TooltipsAppearance DataFormatString="{0:C}" />
</telerik:PieSeries>
Note that we remove this series in the code-behind file:
uxPieChart.PlotArea.Series.Clear();
so its configuration does not have any effect at all.

In order to format the labels as currencies, you should set the DataFormatString property for the second PieSeries, which is created in the code-behind file:
PieSeries pieSeries = new PieSeries();
pieSeries.LabelsAppearance.DataFormatString = "{0:C}";
I am attaching a sample page with this modification. Could you have a look at it and inform me if you could apply it in your page as well?

Regards,
Stamo Gochev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Jako
Top achievements
Rank 1
answered on 12 Nov 2013, 11:49 AM
Thanks, that did the trick.
Tags
Chart (HTML5)
Asked by
Jako
Top achievements
Rank 1
Answers by
Stamo Gochev
Telerik team
Jako
Top achievements
Rank 1
Share this question
or