Can Kendo UI chart legend automatically remove empty series? - charts

I have Kendo UI chart (defined in a razor view).
I haven't been able to find anything in the documentation, is it possible to setup the legend to ignore empty series from the chart data or am I forced to add only the relevant series to the chart data?

While not an option in the legend, there is an option in the series objects: visibleInLegend, this can be set dynamically against a collection or another logical test, e.g.:
new {
category = "Some Category",
value = Model.SomeCollection.Count,
color = "#FF9900", //Amber
visibleInLegend = Model.SomeCollection.Count > 0
},

Related

How to exclude "others" in my pie chart in Data Studio

I have a pie chart in Data Studio as below:
As you can see from the donut, there is "others" slice which I don't want to see it there, and I want to customize the label to show "python (88%)".
Can anyone share your expertise and enlighten me on how to do it?
Thank you very much.
UPDATE
Following #Jaishree's suggestion, I have selected only the top 10, so there is no "others" now.
however, I still don't get it on how to show the label as "python (88%)"
As you can see, I have two fields in my data source (the table on the left): Category and TagsTotal. There is NO percentage_field.
To show "percentage", all I need to do is switch to "percentage" in the STYLE option:
What I ended up of creating this customized labeling is detailed below for future readers:
Back to the data source, create another field pctg:
round((TagsTotal * 100 / (Select Sum(TagsTotal) From cte)),2) as pctg
for the donut chart, create a new field named my_label
CONCAT(category," (",pctg ,"% )")
add the new field my_label as the Dimension field
change in STYLE to show "label"
Voila!
Very cumbersome but finally kind of working with the rest to be sorted out:
1. The newly created field is not showing up in the right-side panel as an available field and how to modify it?
2. The legend needs to be customized to display two lines instead of showing a pagina
In Pie chart and donuts chart you can only show 20 slices. The chart shows the results in a sorted way. If you do not want to see others, then you have select only 20 data points.
"python (88%)" If you want to show the labels as "python (88%)" you can add a new field and customize the labels as you want.
You can do that by click on "create new field " then "add new field" and then give a name to the new field in formula type the below code:
CONCAT(category," (",percentage_field,"% )")
To use the above formula you have to create a percentage_field also before, in the same way with percentage formula.

AG-Grid - Apply Style to Whole Column Dynamically?

I need to apply a background color to a whole column when a custom editor is opened on a cell. I am using:
const col = this.params.column.getColDef();
col.cellStyle = { 'background-color': 'yellow' };
But this is only affecting the cell currently being edited, and not the whole column, which is what I need. I'm using Angular 4+
You need to add this to your colDef for the column, as opposed to setting it dynamically, note that this property can also be a callback so you can dynamically adjust your styling.
https://www.ag-grid.com/javascript-grid-cell-styles/
https://www.ag-grid.com/javascript-grid-cell-editing/#editing-api

Show different datasets with an MPAndroidChart pie chart

In my application I want to display some data on a pie chart. I'm using the MPAndroidChart library and following the documentation I managed to program a nice looking chart with all my data correctly displayed.
Now, I'd like to improve my chart, but I'm having some trouble. My data refers to a single day, but there are two categories: incomes and revenues. Until now I've handled them as a single PieDataSet (they have labels, so it is quite easy to distinguish among them). Now I'd like to differentiate among incomes and revenues, to show them with different colors in the same pie chart.
I tried following this link (the line chart part) adapting it to pie charts, but Android Studio tells me that I can't use a List<IPieDataSet> as parameter for a constructor of a PieData object. Here is the code:
public static void drawPie( List<PieEntry> entriesU, List<PieEntry>entriesE, PieChart chart){
PieDataSet set = new PieDataSet(entriesU,"uscite");
PieDataSet set1 = new PieDataSet(entriesE,"entrate");
List<IPieDataSet> dataSets = new ArrayList<>();
dataSets.add(set);
dataSets.add(set1);
set.setSliceSpace(5);
set1.setSliceSpace(5);
PieData data = new PieData(dataSets);
chart.setData(data);
}
I've searched a lot but I still haven't found an answer to this problem.
Question:
It is possible to display multiple data sets on the same pie chart or not? And if it is possible, how can I do it?
A pie-chart is a single 360-degree circle where slices represent percentages of a total of a given dataset. This only makes sense in the context of a single IDataSet. Therefore, unlike BarChart and LineChart, a PieChart doesn't support multiple IDataSet.
I think what you really want is to use different colors for your "incomes" and "revenues". To do this, all you need to do is create a List<Integer> of resolved colors (not color resources) where the position in the list matches the order the PieEntry is added to the chart.
To illustrate, let's say we have this:
entries.add(new PieEntry(15f, "entrate1")); //revenue1
entries.add(new PieEntry(20f, "uscite1")); //expense1
entries.add(new PieEntry(10f, "entrate2")); //revenue2
entries.add(new PieEntry(50f, "uscite2")); //expense2
You just create a List<Integer> of resolved colors that matches that:
List<Integer> colors = new ArrayList<Integer>();
colors.add(ContextCompat.getColor(context, R.color.red));
colors.add(ContextCompat.getColor(context, R.color.blue));
colors.add(ContextCompat.getColor(context, R.color.red));
colors.add(ContextCompat.getColor(context, R.color.blue));
dataSet.setColors(colors);
Now all your revenues are red and your expenses are blue. You can even be clever and write a function that maps PieEntry to colors rather than do it manually.
In any case, this answer here is correct for setting colors for the pie chart slices.

I want to change one of xAxis label text on the basis of the condition in line graph in pentaho CDE

I want to change one of xAxis label text on the basis of the condition in line graph in pentaho CDE.
I am using pentaho CDE version 5.0 and I generate a line graph on the basis of dynamic values. Now those values became the x and y axis of the graph.
Now I want to do that on the basis of condition want to change the one of the label caption.
For example. X Axis lables are "India, US, China, England" and on the basis of condition like if China come in the label it automatic became hongkong.
I resolved this problem...
Find the following steps.
Go to Charts advanced properties.
Then open the Extention point and add the following parameters
baseAxisLabel_text and in value type the following function.
function(a)
{
var str = this.scene.atoms.category.label;
if(str=="Feb")
{
str="February"; /*Either we can use this option */
}
else
{
str=str;
}
return str.replace("Jan", "January").replace("Mar", "March"); /*or we can use this option */
}

Filtering legend of a Highcharts by only visible series

We are using Highcharts and have some complex charts with roughly 75 series within on chart.
The series are not used through the whole chart but only for range of three month. So we have about 15 series per year and the overall chart covers five years (makes roughly 15*5 = 75 series). However Highcharts displays all 75 charts within its legend. The goal is to minimize the legend to the visible series only. We are able to determine the related series in JS code and we tried to toggle the 'showInLegend' flags of the related series e.g.
chart.series[24].options.showInLegend = false
but without effect. We tried to redraw the chart using
chart.redraw()
but that has no effect...the legend remains unchanged.
So the questions are:
is it possible to redraw the legend based on the updated showInLegend options?
is there mechanism in Highcharts to dynamically updated the legend based on the visible series?
Well just setting the showInLegend doesn't do the trick, there are some more hooks that need to be taken care of
Refer Halvor Strand's answer for a more recent way
Old trick but still works
To Add
item.options.showInLegend = true;
chart.legend.renderItem(item);
chart.legend.render();
To Remove
item.options.showInLegend = false;
item.legendItem = null;
chart.legend.destroyItem(item);
chart.legend.render();
where, item can be a point or series
var item = chart.series[1];
Add Remove Legend Dynamically | Highchart & Highstock # jsFiddle
You can set showInLegend as false when you create the chart.
{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6],
showInLegend: false
}
demo1
If you want to update it dynamically you can do the following.
options.series[1].showInLegend = false;
chart = new Highcharts.Chart(options);
You forgot to force chart to redraw.
demo
Or chart.legend.allItems[1].destroy(); to remove the first one.
This can now be solved without any hacks through the Series.update method (API). For example:
chart.series[0].update({ showInLegend: false });
See this JSFiddle demonstration. The method signature is:
update(Object options, [Boolean redraw])
Where options are options for any regular Series object. You can optionally halt redrawing to change multiple options before redrawing.