How to add data table in chart from office script - charts

I create the online chart from my pivot table.that pivot table is source my chart.but i can't get chart data table in office script
I need to add "chart data table" from office script code
Here is my code. I don't have any idea how to add that data table in chart.
// Insert pivot chart on sheet sheet1
let chart_1 = sheet1.addChart(ExcelScript.ChartType.columnClustered, newPivotTable.getLayout().getRange());
// Resize and move chart chart_1
chart_1.setLeft(543.75);
chart_1.setTop(24.75);
chart_1.setWidth(360);
chart_1.setHeight(216);
// Resize and move chart chart_1
chart_1.setLeft(543.75);
chart_1.setTop(24.75);
chart_1.setWidth(468);
chart_1.setHeight(273);
// Change major gridlines visibility for chart chart_1
chart_1.getAxes().getValueAxis().getMajorGridlines().setVisible(false);
// Change minor gridlines visibility for chart chart_1
chart_1.getAxes().getValueAxis().getMinorGridlines().setVisible(false);
// Change title text for chart chart_1
chart_1.getTitle().setText("Active HC");

If you're asking about how to create a chart from a data table you can use most of the code you have above. You just have to reference the range of the data table e.g. in a variable. And then use that variable when you add the chart. So you could use your code in your initial post but edit it like so:
let dataTbl = sheet1.getRange("data_table_range here") //you will need to change the sheet if the dataTable is not located on Sheet1
let chart_1 = sheet1.addChart(ExcelScript.ChartType.columnClustered, dataTbl); //you will need to change the sheet if you don't want the chart to appear on Sheet1

Related

Display Syncfusion Chart TrackBall at top of Chart

We want to display our TrackBall label at the top of the Graph. We do not want to GroupAllPoints but that appears to be the only way to get the label to appear at the top of the graph.
When we do set LabelDisplayMode="GroupAllPoints" the label ignores the LabelTemplate we have set on the LineSeries. I assume that is because GroupAllPoints covers multiple Series.
How do set LabelDisplayMode to NearestPoint but display that label
at the top of the graph?
Alternatively how do I create a Template that does get picked up
when GroupAllPoints is set. Despite us only having a single point
to display in the TackBall. We'd only be doing this if there was no other way to get the trackball to display at the top of the graph.
Based on your requirement we have prepared a sample for your reference. In which we have achieved your requirement using the "annotation" property in the chart. Please find the below sample, code snippet, and screenshot.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AnnotationSample-1842581013.zip
Code Snippet:
<ejs-chart id="lineContainer" >
// add additional code here
<e-chart-annotations>
<e-chart-annotation Content="<div id=lineContainer_tooltip></div>" X="90%" Y="1%" CoordinateUnits='#Syncfusion.EJ2.Charts.Units.Pixel' region="Series"></e-chart-annotation>
</e-chart-annotations>
Screenshot:

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.

Creating an app script function that generates a chart object for any google sheet

I am trying to create a function in app scripts that generates a chart whenever I pass in the data labels and data points into the function as so:
makePiChart(LabelRange,DataRange)
labelRange: January,February,March....
DataRange: 5,4,3,.......
However, when I try clicking on a cell and typing in the function with the range arguments I get an error.
I first was trying to test if I could get the chart output for a single sheet.
This is the code I have for that.
function makePiChart() {
var ss = SpreadsheetApp.openById("#Id for Spreadsheet")
SpreadsheetApp.setActiveSpreadsheet(ss)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("January");
sheet1.activate()
var chart = sheet1.newChart()
.setChartType(Charts.ChartType.PIE)
.addRange(sheet1.getRange("C4:C11"))
.addRange(sheet1.getRange("H4:H11"))
.setPosition(5,5,0,0)
.setOption("Issues","Dynamic Chart")
.build();
return sheet1.insertChart(chart);
}
Now this generates the chart for the January sheet as I expect.
However, I want to create a function that generalizes this process. So if I go to some sheet in spreadsheet, say I had a Spreadsheet for the entire year and I go to the January sheet, February Sheet, March Sheet etc. and if I click on a cell and type
makePiChart(Rangeforlabels,RangeforData)
I'll get a piechart object that is made using only those data ranges.
Basically, I dont want to keep modifying scripts to generate chart objects. I want to be able to type in =makePie(labelRange,DataRange) into any cell and have a chart object appear. Its location does not matter.

Can Kendo UI chart legend automatically remove empty series?

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
},

Charts - Column chart with extra data

I have some data similar to the following chart:
http://developer.yahoo.com/yui/examples/charts/charts-seriescustomization_clean.html
Only difference is that for each of the fields - I have some other extra data - say For utlilities - I have a cash reserve for utility - as another field. I would prefer this data point to come above the utilities bar.
I have been trying from morning to get this chart working, but I am unable to do so. Could you please let me know if it is possible - someway?
Thank you very much in advance.
Regards
K
All data that is positive will appear above the origin so any positive data will be above the utilities bar. If you are trying to get your field to appear directly above the utilities bar, you cannot accomplish his with a column chart. You can do this with the stacked column chart. When using the stacked column chart, all items will be stacked. You can convert the above link to a stacked column by changing your chart constructor from ColumnChart to StackedColumnChart:
var mychart = new YAHOO.widget.StackedColumnChart
and by setting stackingEnabled to true on your vertical axis.
currencyAxis.stackingEnabled = true;
Tripp