Pie chart in sapui5 - sapui5

I have a dropdown in which i have dropdown values as Zone and State.
Now when i select Zone from the dropdown then iam displaying a pie chart with zone values and on select of pie chart section
iam displaying only the selected zone values in a table.
(for example if i select south section from the pie chart then only the south zone records will be displayed in table).
That i have done.
But when i select the State from the dropdown the pie chart with state values is displaying but on click of pie chart section the records are not displaying in the table.
So far i have used these code............
var oEvDataSet = new sap.viz.ui5.data.FlattenedDataset("EV_REPORT_DATASET", {
dimensions: [{
name: "ZONE",
axis: 1,
value: "{Key}"
}],
measures: [{
name: "NUMBER",
value: "{Number}"
}],
data: {
path: "EVENTREPORT>/ZONE"
//path: "EVENTREPORT>/Category"
}
});
var line = new sap.viz.ui5.Pie({
width: "60%",
height: "500px",
dataset: oEvDataSet
});
var fSelectionChanged = function(oEvent) {
var data = this.selection();
// var country,dso;
var dataFilter = [];
for (i in data) {
var zone = data[i].data.ZONE;
//var state = data[i].data.STATE;
// state = data[i].data.STATE;
dataFilter.push(new sap.ui.model.Filter("ZONE", "EQ", zone));
//dataFilter.push(new sap.ui.model.Filter("STATE","EQ",state));
}
for (i in eventReportAllFilter) {
dataFilter.push(eventReportAllFilter[i]);
// dataFilter.push(new sap.ui.model.Filter("STATE","EQ",state));
}
//dataFilter.push(eventReportAllFilter);
Ev_oTable_AllVenues.bindRows('AM_EventList>/eventlist', oERZoneSorter, dataFilter);
};
line.attachSelectData(fSelectionChanged);
line.attachDeselectData(fSelectionChanged);
line.attachInitialized(function() {});
oER_VerLayout.addContent(line);
U can also see in the image.
In the image if i select dropdown value as state the pie chart is displaying but on select of pie chart section the values are not displaying in the table.
How can i do this..??
Please help me on this.
Thanks
Sathish

Related

Google Bar charts - ToolTips not showing

I have created a bar chart using google charts, this is a CORE Chart
I have tried getting the bar chart to change colours and adding an additional tooltip information to it, so that the tooltip shows a bit more information
I have gone through the google documentation and i cant see what i am doing wrong
For easy reading this is the output of my code on the source
google.charts.load("current", {packages:['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var exams = [["Date", "Score",({type: 'string', role: 'tooltip'})], ["18 Oct", 39,"TEST"], ["26 Oct", 20,"TEST"], ["26 Oct", 0,"TEST"], ["27 Oct", 0,"TEST"], ["27 Oct", 0,"TEST"]];
if(exams.length > 1){
var data = google.visualization.arrayToDataTable(exams);
var view = new google.visualization.DataView(data);
view.setColumns([0, 1]);
var options = {
title: "Results",
width: 1170,
height: 700,
bar: {groupWidth: "95%"},
legend: { position: "none" }
};
var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
chart.draw(view, options);
}
else{
$("#columnchart_values").html('No Data found to show graph');
}
}
This is the google documentation i have been following, its slightly different
to mine as i am getting my data from a database, but it should give the same output.
I have gone through many examples and i am replicating them as close as possible and just not having any luck
https://developers.google.com/chart/interactive/docs/customizing_tooltip_content
I also have the exact same problem with color, i cant get colors on bar charts to change both having the same problem that it just doesn't do anything
Am i missing something??
the tooltip column is not being included in the data view.
view.setColumns([0, 1]);
to add the tooltip...
view.setColumns([0, 1, 2]);

SAPUI5 Combination Chart data and chart formatting

I would like to create a SAPUI5 combination chart - a column chart with a line for a particular category for each month that will compare one year to another. There are about 11 possible categories that the user can choose but the chart would only show one category's information at a time.
It would be similar to the following for one category:
I can create the chart to show data but I am having trouble converting it to use the data based on a category. I would think I can do what I want but I think the issue is in how my data is supplied.
This is my json (I am showing two categories in the data for example - I would like to be able to apply a filter for the category the user chooses):
{
"bullet": [{
"field":"Products Classified",
"months":[{
"month":"1",
"current":"17",
"previous":"140"
} ,{
"month":"2",
"current":"37",
"previous":"66"
},{
"month":"3",
"current":"60",
"previous":"66"
},{
"month":"4",
"current":"41",
"previous":"121"
}]
}, {
"field":"Products Not Classified",
"months":[{
"month":"1",
"current":"7",
"previous":"25"
} ,{
"month":"2",
"current":"50",
"previous":"78"
},{
"month":"3",
"current":"55",
"previous":"56"
},{
"month":"4",
"current":"45",
"previous":"60"
}]
}]
}
Here is part of my controller....
var oModel = new JSONModel("ByYear_sum.json");
sap.ui.model.FilterOperator.EQ, filterText);
var oDataset = new FlattenedDataset({
dimensions: [{
name: "Month",
value: "{month}"
}],
measures: [{
name: "Start Year",
value: "{current}"
},{
name: "End Year",
value: "{previous}"
}],
data: {
path: "/bullet"
filters: [oFilter]
}
});
oVizFrame.setDataset(oDataset);
oVizFrame.setModel(oModel);
oVizFrame.setVizProperties({
plotArea: {
dataLabel: {
visible: true,
formatString: '#,##0'
}
},
valueAxis: {
title: {
visible: false
}
},
legend: {
title: {
visible: false
}
},
title: {
visible: true,
text: 'Year Comparison'
}
});
var feedValueAxis = new FeedItem({
'uid': "valueAxis",
'type': "Measure",
'values': ["Start Year", "End Year"]
}),
feedCategoryAxis = new FeedItem({
'uid': "categoryAxis",
'type': "Dimension",
'values': ["Month"]
});
The value of filterText would be used to show the chart information for the chosen category (for example Products classified or Products Not classified).
I tried putting /months/ in front of the values (for example "{/months/previous}") to get to the values for the category (i.e. Products classified) but it doesn't seem to find the data properly (I get no data).
I would also like to display the text value of the month, not the number, how can I apply a formatter to the value?
My example chart shows year numbers....The years being compared come from user input, I currently cannot figure out how to get the values of the years chosen to show - I had to put 'Start Year' and 'End Year'. Is there a way to make the legend and popover show the year values (so dynamic based on user input)? Everything I tried gave me errors and wouldn't display the chart - I think because the feeds needed to match the same text and when I tried using a value it couldn't match.
I was finally able to get this to work, with some guidance from others.
1) In the title, I was able to set and update the title properties when the user chose a different filter.
2) The path was incorrect as well....it should have been /bullet/0/months - the '0' changes depending on the filter. I just had to get the index of the category chosen and use that for the path.
3) I changed my data to return the month abbreviation, instead of the number.
4) I was finally able to get the years to show both in the legend and the popup if you click a data point. In the FlattenedDataSet definition, I put a variable name in that is passed in when creating the FlattenedDataSet - so example: name was name: sYr, where sYr was passed in and the value of the year. In the FeedItem creation, the values look like: 'values': [sYr, eYr] I thought I had tried these, but it seemed to work with all the other changes that were made. I just had to create new FlattenedDataSet and FeedItems (and remove the old FeedItems) and update the chart with the new values.

Display title series in tooltip

I need display in tooltip title series chart. I have many series in my chart.
I try this:
->add series to chart<-
addSeries("Title1", new dojox.charting.StoreSeries(store, {query: {}}, {x: "time", y: "tzewn", text: "Title1"})).
I get data from json file. But text: isn't in my store data.
->tooltip<-
new dojox.charting.action2d.Tooltip(chartT, "default"
,{text: function(e) {
var tooltiptext = e.y +", "+e.text;
return tooltiptext;
}
}
);
but I get: (e.y) the correct value and undefined (e.text),
How I can display name series in tooltip?
Your StoreSeries is defined to look for a property named "Title1" in each object that comes from the store and assign that value to "text".
If you want the name of the series in your tooltip text, then try using e.run.name in your tooltip text function:
new dojox.charting.action2d.Tooltip(chartT, "default", {
text: function(e) {
return e.y.y + ", " + e.run.name;
}
});

SAPUI5: Showing pie chart or Bar chart using OData service from HANA DB

I am working on SAP HANA Development project where I need to develop an UI application using SAPUI5 and Odata service.
I need a help on getting the data from HANA table and display in the Pie or Bar Chart.
I am getting the data to a table(oTable) using odata service but not able to display it in the Pie Chart.
Please find below the code snippet:
{
var oModel = sap.ui.model.odata.ODataModel('link of the .xsodata' false);
var oTable = new sap.ui.table.Table({tableId: "tableID", visibleRowCount: 10});
oTable.setTitle("Transactions");
oTable.setModel(oModel);
oTable.bindRows('/Transactions');
var dataset = new sap.service.visualization.dataset.SimpleDMDataset();
dataset.setDataTable(oTable);
var pie = new sap.service.visualization.chart.Pie("myPie", {
width: "700px",
height: "400px",
allDeSelectable: true,
legendFirst: true,
selectionMode: 'single',
legendDirection: 'right',
title: 'Transactions',
titleHorizontalAlign: 'center',
subTitle: 'Q1 - 2012',
subTitleHorizontalAlign: 'center',
showTitle: true,
defaultSelectedSliceIndexes: [5],
legendFormatString: ['0.00%'],
tooltipTextFormatString: ['0.00%'],
tooltipMainValueFormatString: ['#,##0'],
tooltipSubValueFormatString: ['0.00%'],
showLegend: true,
pieType: 'pie',
dataset: dataset
});
pie.placeAt("uiAreaForMyControls");
}
Please help me in getting the Pie chart displayed with the data as I am new and in learning phase.
I noticed you were trying to use sap.service.visualization charts with datasets, different to previous answer, here are a couple of simple examples using Northwind OData services
JSBin: Viz Pie Chart example
JSBin: Viz Bar Chart example - more advanced uses a filter on dataset
The following is a very simple Pie Chart using the NorthWind OData service, same format as XSODATA
It shows the percentage of Products per Category an Expand is used to get the CategoryName - live demo
var sURI = 'http://services.odata.org/v3/Northwind/Northwind.svc/';
var oModel = new sap.ui.model.odata.ODataModel(sURI, true);
// Pie Chart
var oChart = new sap.makit.Chart({
width : "100%",
height: "80%",
type : sap.makit.ChartType.Pie,
legendPosition : sap.makit.LegendPosition.Top,
valueAxis: new sap.makit.ValueAxis({}),
categoryAxis: new sap.makit.CategoryAxis({}),
category : new sap.makit.Category({
column : "category",
}),
values : [new sap.makit.Value({
expression : "products",
format : "number",
})],
});
oChart.addColumn(new sap.makit.Column({name:"category", value:"{Category/CategoryName}"}));
oChart.addColumn(new sap.makit.Column({name:"products", value:"{ProductID}", type:"number"}));
oChart.setModel(oModel);
oChart.bindRows({
path: "/Products",
parameters: {select: 'ProductID,Category/CategoryName',expand: 'Category'}
});
oChart.placeAt("content");

Different colors for column chart

I am using ExtJS to render charts, but my column chart is getting with the same color for all series. I need different colors for the series. Only happens with column, bar and area charts, the line chart is working fine.
My code:
Ext.Ajax.request({
method: 'get',
url: Webapp.link('chart/' + key),
success: function(response){
var resposta = Ext.JSON.decode(response.responseText);
var chart = Ext.create('Hemisphere.view.chart.Chart', {
axes: resposta.chart.axes,
series: resposta.chart.series,
store: store (The store is defined previously)
});
panel.removeAll();
panel.add(chart);
}
}
});
Anyone could help me? Thanks.
One serie code example.
You can change the color using a renderer on your series.
Ext documentation has a working example of this:
http://docs.sencha.com/ext-js/4-1/#!/example/charts/Column2.html
series: [{
type: 'column',
renderer: function(sprite, storeItem, barAttr, i, store) {
barAttr.fill = colors[i % colors.length];
return barAttr;
}
.
.
}]