Hello,
I've got a problem. I've got a pie with two values. Sometimes it happens, that both values are 0.
If that happens, the Piechart will get transparent.
I already added a second series, but the gray part is still clickable and tooltip appears.
Is there any possibility to show a whole gray pie if there are no values?
Regards
4 Answers, 1 is accepted
0
Accepted
Hi,
As mentioned by you, the only way to show a whole grey chert when the chart is actually empty, is to have one additional series with static value. You can show it conditionally, only when the chart is empty, disabling its labels, tooltips, click and highlight functionality in a similar way:
<script>
function onClick(e) {
if (e.series.name == "Empty") {
e.preventDefault();
}
}
function onHover(e) {
if (e.series.name == "Empty") {
e.preventDefault();
}
}
</script>
<telerik:RadHtmlChart runat="server" ID="RadHtmlChart1" Width="800" OnDataBound="RadHtmlChart1_DataBound">
<ClientEvents OnSeriesClick="onClick" OnSeriesHover="onHover" />
<PlotArea>
<Series>
<telerik:PieSeries Name="Total cases" DataFieldY="values" NameField="labels">
</telerik:PieSeries>
<telerik:PieSeries Name="Empty" Opacity="0.2" Visible="false">
<TooltipsAppearance Visible="false"></TooltipsAppearance>
<LabelsAppearance Visible="false"></LabelsAppearance>
<SeriesItems>
<telerik:PieSeriesItem Y="1" BackgroundColor="Gray" VisibleInLegend="false" />
</SeriesItems>
</telerik:PieSeries>
</Series>
</PlotArea>
<Legend>
<Appearance Visible="false"></Appearance>
</Legend>
</telerik:RadHtmlChart>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadHtmlChart1.DataSource = GetData();
RadHtmlChart1.DataBind();
}
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("values", typeof(int)));
dt.Columns.Add(new DataColumn("labels", typeof(string)));
dt.Rows.Add(0, "Item 1");
dt.Rows.Add(0, "Item 1");
return dt;
}
protected void RadHtmlChart1_DataBound(object sender, EventArgs e)
{
bool isChartEmpty = true; //your logic for checking the data values here
if (isChartEmpty)
{
RadHtmlChart1.PlotArea.Series[1].Visible = true;
}
}
Regards,
Vessy
Progress Telerik
0
0
User1564
Top achievements
Rank 1
Veteran
answered on 04 Aug 2020, 09:03 AM
Ok I solved it. Just put the empty series before my series.
0