Generate charts with Google chart API - c#

i'am trying to generate a chart like this one: http://chartpart.com/ but i don't know how to do that exactly.Do i need to make the string that generates the chart manually or do i need to send the data to a google server and receive the string?(if so how do i send the data?)
PS:i would like to do all this in c# and send the resulting string via web service.

apparently you need to generate the string yourself.I did just that and send the result to android via web service.
[WebMethod]
public ChartsClass GetChart(string UserId)
{
ChartsClass chart = new ChartsClass();
DataSet1TableAdapters.WS_ChartIndicatorsTableAdapter adapter = new DataSet1TableAdapters.WS_ChartIndicatorsTableAdapter();
DataSet1.WS_ChartIndicatorsDataTable table = adapter.GetChartIndicators(UserId);
StringBuilder sbDescriptions = new StringBuilder();
StringBuilder sbValues = new StringBuilder();
for(int i= 0 ;i< table.Rows.Count ;i++)
{
DataSet1.WS_ChartIndicatorsRow chartRow = (table.Rows[i] as DataSet1.WS_ChartIndicatorsRow);
if (i > 0)
{
sbDescriptions.Append("|");
sbValues.Append(",");
}
sbDescriptions.Append(chartRow.SectorId + " - " + chartRow.SectorDescription );
sbValues.Append(chartRow.NetSaleValue.ToString());
}
chart.ChartString = String.Format("http://chart.apis.google.com/chart?cht=p3&chtt={0}&chd=t:{1}&chs=480x200&chl={2}&chco=ff0000,0000ff",
"Live Sales", sbValues.ToString(), sbDescriptions.ToString());
return chart;
}
And in android you can load the result in a web view.
chartView = (WebView)findViewById(R.id.activity_chart_view);
ChartsClass chart = new ChartsClass(soapObject);
chartView.loadUrl(chart.chartStringSource);

If you are trying to create a chart with user input, there's a wikiHow on that
wikiHow Link: http://www.wikihow.com/Make-a-Google-Chart-with-User-Input
The graph this wikiHow creates is the same as the one on this website:
Website Link: http://www.quickcompromise.com/index.html

Related

Retrieve all contents of Zoho module via REST API c#

I am trying to get the full contents of my modules From Zoho to our local Server. The deluge code does work as it returns to me the data which is being sent via the API. However, once it reaches the API, it is null. Any idea?
Below is the deluge code:
// Create a map that holds the values of the new contact that needs to be created
evaluation_info = Map();
evaluation_info.put("BulkData",zoho.crm.getRecords("Publishers"));
data = Map();
data.put(evaluation_info);
response = invokeurl
[
url :"https://zohoapi.xxxxx.com/publisher/publish"
type :POST
parameters:data
connection:"zohowebapi"
];
info data; (data returns all the data from publishers)
Here is my ASP.NET core restful API. It does ping it and create the file but the content of the file is null.
Route("[controller]")]
[ApiController]
public class PublisherController : ControllerBase
{
[HttpGet("[action]"), HttpPost("[action]")]
public void Publish(string data)
{
(it's already null when it comes here. why?)
string JSONresult = JsonConvert.SerializeObject(data);
string path = #"C:\storage\journalytics_evaluationsv2.json";
using (var file = new StreamWriter(path, true))
{
file.WriteLine(JSONresult.ToString());
file.Close();
}
}
}
}
What am I missing? Thank you
After contacting Zoho support, the solution he offered was to loop through the data in order to get all the contents from a module (if they are more than 200 records. With the solution provided, one doesn't really need the deluge code anymore as long as you have the ZOHO api set to your account in code. This was my final solution. This solution is not scalable at all. It's best to work with the BULK CSV.
// Our own ZohoAPI which lets us connect and authenticate etc. Yours may look slightly different
ZohoApi zohoApi = new ZohoApi();
zohoApi.Initialize();
ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
var allMedicalJournals = new List<ZCRMRecord>();
for (int i = 1; i <= 30; i++)
{
List<ZCRMRecord> accountAccessRecords2 =
restClient.GetModuleInstance("Journals").SearchByCriteria("Tag:equals:MedicalSet", i, 200).BulkData.ToList();
foreach (var newData in accountAccessRecords2)
allMedicalJournals.Add(newData);
}

How can Xamarin.Forms read json from WCF?

I'm trying to create my first Xamarin.Forms mobile app with a map and pins, so please bear with me.
I'm trying to add pins to the map. I use this code to add one pin:
map = new Map {
IsShowingUser = true,
HeightRequest = 100,
WidthRequest = 960,
VerticalOptions = LayoutOptions.FillAndExpand
};
map.MoveToRegion (MapSpan.FromCenterAndRadius (
new Position (36.9628066,-122.0194722), Distance.FromMiles (3)));
var position = new Position(36.9628066,-122.0194722);
var pin = new Pin {
Type = PinType.Place,
Position = position,
Label = "Santa Cruz",
Address = "custom detail info"
};
map.Pins.Add(pin);
Now, instead of adding just one pin, I'd like to add several pins from a tsql table.
So I created a WCF service that returns a list of coordinates. One returns a json and the other returns a datatable:
public DataTable ToEraseGetCoordinates()
{
string sqlQuery = "select lat,lon from MyStores";
string connString = GetConnString();
SqlDatabase sqlDatabase = new SqlDatabase(connString);
DataSet result = sqlDatabase.ExecuteDataSet(CommandType.Text, sqlQuery);
return result.Tables[0];
}
public System.IO.Stream ToEraseGetCoordinatesJson()
{
string sqlQuery = "select lat,lon from MyStores";
string connString = GetConnString();
SqlDatabase sqlDatabase = new SqlDatabase(connString);
DataSet result = sqlDatabase.ExecuteDataSet(CommandType.Text, sqlQuery);
return ConvertToJson(result.Tables[0]);
}
I invoke the WCF like so: http://80.102.51.381:101/Service1.svc/ToEraseGetCoordinates (for an xml representation of the datatable)
For the JSON: http://80.102.51.381:101/Service1.svc/ToEraseGetCoordinatesJson, which returns this:
{"lat":25.7616,"lon":-80.1917},{"lat": 28.5383,"lon":-81.3792}
My question is: what do I next so that my Xamarin.Form reads this?
Regardless of the return type, I don't know how Xamarin will consume the WCF and draw the pins.
This earthquake map sample does basically what you want (it's a bit old, sadly).
Basically you want to download your Json (eg in this class)
// your http://80.102.51.381:101/Service1.svc/ToEraseGetCoordinatesJson would go here
var response = await client.GetAsync("earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=bertt");
var earthquakesJson = response.Content.ReadAsStringAsync().Result;
then you need to convert the Json - but you said you've already done that
var rootobject = JsonConvert.DeserializeObject<Rootobject>(earthquakesJson);
lastly just create and add the pins to the map
var earthquakes = await webSvc.GetEarthquakesAsync();
Xamarin.Forms.Device.BeginInvokeOnMainThread( () => {
Debug.WriteLine("found " + earthquakeString.Length + " earthquakes");
label.Text = earthquakeString.Length + " earthquakes";
foreach (var earthquake in earthquakes)
{
var p = new Pin();
p.Position = new Position(earthquake.lat, earthquake.lng);
p.Label = "Magnitude: " + earthquake.magnitude;
m.Pins.Add(p);
}
});
Originally the pins weren't able to be databound, which is why it loops through to add them. Not sure if the ability to databind pings has been added to Xamarin.Forms since.
You'll probably want to keep track of the lat/longs so you can calculate a new region to set the maps view, to default to showing all the pins you added...
See the Maps docs and maps custom renderers for more info.

NAV Web Services getting data in chunks using C#

I am a bit new to NAV and so far I have published web services on NAV and have been able to consume these SOAP web services using C#.
Now, the data has increased and its taking longer to load. I have an idea of querying the data in chunks (e.g chunks of 10) using Datatables, but this I am yet too figure out how to set limits and offsets.
Here is my C# code to read the NAV soap service
public string getItemCardList(itemCardService_Service itemCardServiceObj, List<itemCardService_Filter> filter)
{
serializer.MaxJsonLength = 50000000;
return serializer.Serialize(itemCardServiceObj.ReadMultiple(filter.ToArray(), null, 0));
}
After some several searches I have gotten the answer on the [MSDN Website][https://msdn.microsoft.com/en-us/library/ff477110.aspx] and modified it to work for me.
public string holder()
{
const int fetchSize = 10;
string bookmarkKey = null;
List<itemCardService> itemList = new List<itemCardService>();
//Read items data in pages of 10
itemCardService[] results = itemCardServiceObj.ReadMultiple(filter.ToArray(), bookmarkKey, fetchSize);
while(results.Length > 0)
{
bookmarkKey = results.Last().Key;
itemList.AddRange(results);
results = itemCardServiceObj.ReadMultiple(filter.ToArray(), bookmarkKey, fetchSize);
}
serializer.MaxJsonLength = 50000000;
return serializer.Serialize(itemList);
}

CRM Plugin get Title of a page in C#

I am creating a Plugin for CRM Which sets the Title of the page as First Name for Account Entity.
The desired result I have achieved the same by writing a javascript function on formload Event
in CRM.
Following is the code
var titlename = Xrm.Page.data.entity.attributes.get("firstname").getValue();
var titleSpan = document.getElementById('form_title_div');
if(titleSpan) {
for(var i = 0;i < titleSpan.children.length;i++) {
if(titleSpan.children[i].className == 'ms-crm-Form-Title-Data autoellipsis') {
titleSpan.children[i].innerText = titlename;
}
}
}
But my client don't want any javascript code instead he wants it thru Plugin.
I have written a plugin but don't know how to get and set the Title of the page.
Plugin project is a C# Class library.
Code is below for Plugin
Basically I want C# code for commented(Javascipt) Lines
using (var crm = new XrmServiceContext(service))
{
var account = crm.ContactSet.Where(c => c.AccountId == id).First();
var titlename = contact.Crmp_Firstname.ToString();
//var titleSpan = document.getElementById('form_title_div');
//if(titleSpan) {
//for(var i = 0;i < titleSpan.children.length;i++) {
//if(titleSpan.children[i].className == 'ms-crm-Form-Title-Data autoellipsis') {
//titleSpan.children[i].innerText = titlename;
//}
//}
//}
}
Thanks in advance for any help
It is not possible to modify the title of an account form by a plugin.
This because plugins act server side, instead JavaScript (and your account form) is executed client side.
CRM doesn't store the title of the account, but generates it at runtime.

Amazon Product Advertising API for Asp.net & C#

I want to fetch books using Amazon Product Advertising API with asp.net and C#. All the guides and codes are so confusing as to they don't give you a single method to search the books.
Is there any single stub that can be used to call the service and fetch the books based on the ISBN.
thanks
There's a good sample solution you can download.
http://aws.amazon.com/code/2480?_encoding=UTF8&queryArg=searchQuery&x=0&fromSearch=1&y=0&searchPath=code&searchQuery=Advertising
They give you a class called SignedRequestHelper, then you make a call like this:
public static void Main()
{
SignedRequestHelper helper = new SignedRequestHelper(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY, DESTINATION);
/*
* The helper supports two forms of requests - dictionary form and query string form.
*/
String requestUrl;
String title;
/*
* Here is an ItemLookup example where the request is stored as a dictionary.
*/
IDictionary<string, string> r1 = new Dictionary<string, String>();
r1["Service"] = "AWSECommerceService";
r1["Version"] = "2009-03-31";
r1["Operation"] = "ItemLookup";
r1["ItemId"] = ITEM_ID;
r1["ResponseGroup"] = "Small";
/* Random params for testing */
r1["AnUrl"] = "http://www.amazon.com/books";
r1["AnEmailAddress"] = "foobar#nowhere.com";
r1["AUnicodeString"] = "αβγδεٵٶٷٸٹٺチャーハン叉焼";
r1["Latin1Chars"] = "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJij";
requestUrl = helper.Sign(r1);
title = FetchTitle(requestUrl);
System.Console.WriteLine("Method 1: ItemLookup Dictionary form.");
System.Console.WriteLine("Title is \"" + title + "\"");
System.Console.WriteLine();
}
You need to use the ItemLookup (like the example) but set the IdType to ISBN. Then set the ItemId to the actual ISBN. Here are the details on ItemLookup:
docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?ItemLookup.html
I get this when I use that sample. looks like there has been a change in the API recently.
System.InvalidOperationException: There is an error in the XML document. ---> Sy
stem.InvalidOperationException: <ItemLookupResponse xmlns='http://webservices.am
azon.com/AWSECommerceService/2011-08-01'> was not expected.
To fetch books install this library (Install-Package Nager.AmazonProductAdvertising)
https://www.nuget.org/packages/Nager.AmazonProductAdvertising/
Example:
var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.UK);
var result = await client.GetItemsAsync("978-0261102385");

Categories