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

Pie Series NameField to Legend label

1 Answer 126 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 30 Aug 2018, 08:09 PM

I am having a hard time getting the Legend label values to equal the pie series NameField values.

 

<telerik:RadHtmlChart ID="rhcDiscountReasons" runat="server" DataSourceID="sqlDRRAlt" ChartTitle-Text="Discount Reasons">
<ChartTitle Text="Discount Reasons">
<Appearance Visible="True">
</Appearance>
</ChartTitle>
<Legend>
<Appearance Visible="True" BackgroundColor="WindowFrame" Align="Center" Position="Bottom" Orientation="Horizontal">
    <TextStyle Color="White" FontSize="18" />
</Appearance>
<Item Visual="legendItemVisual" />
</Legend>
  <PlotArea>
                <Series>
                    <telerik:PieSeries DataFieldY="dtypecount" Name="Discount Reasons" VisibleInLegend="true" NameField="dtype">
                        <LabelsAppearance DataField="dtype">
                        </LabelsAppearance>
                    </telerik:PieSeries>
                </Series>
 </PlotArea>
</telerik:RadHtmlChart>

 

If I use the below code, It fills all the legend labels with "Discount Reasons", I want them to have the NameField values.  I have tried everything I could think of to access those values but cannot.  If I replace e.series.name with e.series.categoryField the legend lables all say "dtype", this is close but I want the dtype value.

var label = new drawing.Text(e.series.name, [0, 0], {
        fill: {
            color: legendLabelsColor
        }
    })

Can someone point me in the right direction?

 

 

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 04 Sep 2018, 02:28 PM
Hi Chris,

By default the Chart use the series names as labels for the legend, unless there is another logic changing that. You can see the default behavior of the chart by testing the snippet below (the applied legend visual template handler is removed):
<telerik:RadHtmlChart ID="rhcDiscountReasons" runat="server" ChartTitle-Text="Discount Reasons">
    <ChartTitle Text="Discount Reasons">
        <Appearance Visible="True">
        </Appearance>
    </ChartTitle>
    <Legend>
        <Appearance Visible="True" BackgroundColor="WindowFrame" Align="Center" Position="Bottom"
            Orientation="Horizontal">
            <TextStyle Color="White" FontSize="18" />
            <ClientTemplate></ClientTemplate>
        </Appearance>
    </Legend>
    <PlotArea>
        <Series>
            <telerik:PieSeries DataFieldY="dtypecount" Name="Discount Reasons" VisibleInLegend="true" NameField="dtype">
                <LabelsAppearance DataField="dtype">
                </LabelsAppearance>
            </telerik:PieSeries>
        </Series>
    </PlotArea>
</telerik:RadHtmlChart>
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        rhcDiscountReasons.DataSource = GetData();
        rhcDiscountReasons.DataBind();
    }
}
private DataTable GetData()
{
    DataTable dt = new DataTable("ChartData");
 
    dt.Columns.Add("dtypecount", Type.GetType("System.Int32"));
    dt.Columns.Add("dtype", Type.GetType("System.String"));
    dt.Columns.Add("Value", Type.GetType("System.Int32"));
    dt.Rows.Add(7, "leaked", 15);
    dt.Rows.Add(3, "missing", 15);
 
    return dt;
}




Regards,
Vessy
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Chart (HTML5)
Asked by
Chris
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or