How to get collection data into a chart object? - c#

I have a C# app I'm building in Visual Studio 2010. The app contains code that crunches some input data to make some output data which I want to put on a chart. I can put the output data into any of the desired .NET collection objects. But I can't get the chart to look to an object defined on my form to get the chart's data. It seems the chart will only go to a service, database, or object that is external to my project.
I've reviewed all the posts I could find and it seems the chart object has evolved recently and the relevant posts aren't relevant any more because the Chart class has changed.
I've been working with the chart's DataSource property to specify the data source. I've also looked through all the options that come up with the automatic code completion facility of Visual Studio and can't find anything that looks or works like what I want.
This must be easy if one knows the trick. Anybody know the trick to this?
Thanks,
Bill

Eventually found the answer in MSDN under the heading "Adding Series Data at Run Time". Here is some example code I developed from the MSDN example code which shows the solution to my problem:
chart1.Series.Add("example");
chart1.Series["example"].ChartType = System.Windows.Forms.DataVisualization.
Charting.SeriesChartType.Line;
for (int i = 0; i < 20; ++i)
{
chart1.Series["example"].Points.Add(2 * i);
}
Cheers,
Bill

Related

Rethinkdb .net update value

I'm looking at updating stored values in a RethinkDB using the C# RethinkDB.Driver library and I'm just not getting it right.
I can achieve an update by getting the result, altering that object then making a separate call to update with that object. When there are many calls to a record to update like this, the value being updated elsewhere whilst the application is working with the record.
TestingObject record = r.Db("test").Table("learning").Get("c8c54346-e35f-4025-8641-7117f12ebc5b").Run(_conn);
record.fieldNameIntValue = record.fieldNameIntValue + 1;
var result = r.Db("test").Table("learning").Get("c8c54346-e35f-4025-8641-7117f12ebc5b").Update(record).Run(_conn);
I've been trying something along these lines :
var result = r.Db("test").Table("learning").Get("c8c54346-e35f-4025-8641-7117f12ebc5b").Update(row => row["fieldNameIntValue"].Add(1)).Run(_conn);
but the result errors with Inserted value must be an OBJECT (got NUMBER):101 which suggests this is only passing the field value back instead of updating the object.
Ideally I'd like to update multiple columns at once, any advice is appreciated :)
This is an example that works in the ReQL data explorer. You can chain as may filters before the update as you want. I assume this will translate to the C# Driver, but I dont have any experience with that.
r.db('database').table('tablename').update({clicks: r.row("clicks").add(1)}).run().then(function(result){ ...
Thanks T Resudek your answer and a clearer head helped emphasised the need to map the calculation to the property.
Looking at the javadocs for update it has HashMap method which I followed with the c# library and it works.
var result = r.Db("test").Table("learning").Get("c8c54346-e35f-4025-8641-7117f12ebc5b").Update(row => r.HashMap("fieldNameIntValue",row["fieldNameIntValue"].Add(1))).Run(_conn);
I'd be interested to know if this is the right way or was a better way.

How to do Custom Paging

I want to implement server side paging in my Silverlight application. To get an idea of the steps that I would require I went through this custom paging in asp.net
article where they described how to design a SQL query to return the results according to the Page Requested and the Total no of records per page. I am however totally confused as to how am I going to call it from my Silverlight application. Like how am I going to specify it in the c# code.
The default paging using the DataPager is pretty simple.
PagedCollectionView pagingCollection = new PagedCollectionView(e.Result); //e.Result contains `List` returned by the method that calls the stored procedure GetProducts
pagerProductGrids.Source = pagingCollection;
gridProductGrid.ItemsSource = pagingCollection;
But I'm clueless about the procedure of doing it on my own. Like what properties I will be needing to get and set the Page Size, the total no of records etc i.e how am I going to configure my DataGrid and DataPager to pass StartingRowIndex and Maximum RowcOunt
Please help!
I came across this article a few years ago and this worked like a charme for me. I've added this to my framework and have been reusing this method ever since. The article is well explained and I believe this is exactly what you are looking for.
Paging Data from the Server with Silverlight

Automatically inserting value from another table in lightswitch

I am creating a desktop, C# application in Lightswitch. I have a DB file with a table called Reports and another table called StatusList. There are going to be 3 options in StatusList table - Unresolved, In Progress and Resolved. The Report table has a couple of not important fields and a field "Status", which is supposed to hold one of the three values from StatusList table
Now, when the user will create a new Report, I need the application to automatically insert the "Unresolved" value as the "Status" without user being able to change it.
I have tried using this method
partial void Reports_Created()
{
this.Status = "Unresolved";
}
but it is not working. I guess it is because I am trying to assign a String value to the field which is populated from another table.
I am using Visual Studio 2013 and this is my first Lightswitch app as well.
Thank you in advance for any help.
It sounds like your trying to pass parameters between screens. Beth Massi does a good job explaining how to achieve that in this video. And here is another MSDN link to a similar question
Shouldn't your code before like:
This.report.status = "Unresolved"
I.e. The report entity is not referenced by "this" (that refers to the screen).

How to select library items that belong to a taxonomy in Ektron

I'm using Ektron CMS version 8.5 SP2.
I have some items in a taxonomy. Some are actual pages, some are library items (documents like Word files and PDFs).
Let's say there are 3 pages and 2 library items for a total of 5 items in my taxonomy.
I use the following code...
ContentManager cManager = new Ektron.Cms.Framework.Content.ContentManager();
Ektron.Cms.Content.ContentTaxonomyCriteria ctCriteria = new Ektron.Cms.Content.ContentTaxonomyCriteria();
ctCriteria.AddFilter(1707, true); // hard coded taxonomy ID
List<ContentData> list = cManager.GetList(ctCriteria);
Label1.Text = list.Count.ToString();
When this code runs, the count of items in the list is 3. If I output the actual list, I can see it's only the pages in the taxonomy, not the 2 library items.
It seems that the ContentManager.getList() function does not get library items, even when those items have been added to the taxonomy. I can confirm that in the admin workarea, the library items are visible in the taxonomy.
For clarification, this is a problem with retrieving items that have already been added to the taxonomy.
Does anyone know how I can retirieve a list of all items in a taxonomy, including any library items in there.
Note: If I add the files to the Document Managment System instead of the library, it works perfectly. But in the live system, I have hundreds of items in the library and I'm hoping theres' a way to view them via a taxonomy without having to move them all into the DMS.
I have posted this question on the Ektron developers forum as well, but I've had no reply. I'm hoping somebody here can help.
Cheers.
A follow up to my comment from the other day on #nedlud's answer, I felt like this deserved its own answer though.
According to the Framework API docs:
If intent is to retrieve CMS items that have been categorized in Taxonomies, use TaxonomyItemManager.
But as already noted in the comments, the TaxonomyItemData objects returned by this API have a number of empty properties such as QuickLink and Html. I've found that using the TaxonomyManager, one can successfully query for items assigned to particular taxonomy categories.
Here's a brief snippet using the Framework API (version >= 8.5); this feels reminiscent of working with the older (version <= 8.0) taxonomy API wherein one would create a TaxonomyRequest and get an object structure back that encapsulated not only the taxonomy iteself, but the items categorized into that taxonomy:
//e.g. for a single-level taxonomy
long taxRoot = 1707; //from OP's question
TaxonomyManager taxManager = new TaxonomyManager();
//GetTree overload supplying includeItems parameter
TaxonomyData taxTree = taxManager.GetTree(taxRoot, includeItems: true);
foreach(TaxonomyItemData taxItem in taxTree.TaxonomyItems)
{
//these should print true
Response.Write(!String.IsNullOrEmpty(taxItem.QuickLink));
Response.Write(!String.IsNullOrEmpty(taxItem.Html));
}
I'm currently refactoring some version 8.0 code into version 8.6 and converting to the Framework API. Until Ektron fixes the (bug?) of TaxonomyItemManager returning TaxonomyItemData with null properties, I'll be using the above method + LINQ for the sorting/filtering/etc.
I would look at the TaxonomyItemManager rather than the ContentManager.
Thanks to #maddoxej suggestion of using the TaxonomyItemManager, I have working solution code...
TaxonomyItemCriteria criteria = new TaxonomyItemCriteria();
criteria.AddFilter(TaxonomyItemProperty.TaxonomyId, CriteriaFilterOperator.EqualTo, 1707);
TaxonomyItemManager taxonomyItemManager = new TaxonomyItemManager();
List<TaxonomyItemData> taxonomyItemList = taxonomyItemManager.GetList(criteria);
Label1.Text = taxonomyItemList.Count.ToString();
This code now shows the expected count of "5", and I can display all the itmes :)
So many "manager" classes in Ektron.

MapPoint 2011- DataMap(ShadedArea) - Visual Studio

I've got a question about adding a datamap to my current map in mappoint while importing data to a dataset.
So, i have an excel file that has the following columns in order: ID,Name,Adress,City,Country,PostalCode,Service,MoneyImport.
I'm creating a dataset to be used for the datamap:
object missing = System.Reflection.Missing.Value;
MapPoint.DataSet dataset = map.DataSets.ImportData(filename, missing,
MapPoint.GeoCountry.geoCountryItaly,
MapPoint.GeoDelimiter.geoDelimiterDefault,
MapPoint.GeoImportFlags.geoImportExcelSheet);
I'm using the "missing" value cause the MapPoint Application when running through the normal interface*(importing from the same excel file i use here)* recognises perfectly the datafields, so i don't have the need to specify their types by myself.
Then i'm tryin' to use this dataset in order to create the datamap i need. This map is supposed to display as shaded areas the "MONEYIMPORT field" on the map based on zoomlevel.
When using the normal mappoint interface it does it smoothly with no problem and no errors at all.
Object Import = 8;
MapPoint.Field GainedMoney = dataset.Fields.get_Item(Import);
This two lines are ment to let me add to the GainedMoney field the values of the 8th column of excel by exctracting 'em from the dataset.
So further i add the datamap:
MapPoint.DataMap datamap =dataset.DisplayDataMap(MapPoint.GeoDataMapType.geoDataMapTypeShadedArea, GainedMoney,
ShowDataBy: MapPoint.GeoShowDataBy.geoShowByZoomLevel,
DataRangeType: MapPoint.GeoDataRangeType.geoRangeTypeDefault,
DataRangeOrder: MapPoint.GeoDataRangeOrder.geoRangeOrderDefault,
ColorScheme: 13,
CombineDataBy: MapPoint.GeoCombineDataBy.geoCombineByAdd);
So the MapPoint object model decides to throw me an error that says that the type of area i'm tryin' to add to the map cannot be recognized, so it has been impossible to add it to the map.
I've checked several times if the attributes i pass to the .DisplayDataMap are correct, and they are identical to the ones i choose when creating the datamap through the user interface of mappoint, and still no result gained. Really i don't know anymore how to fix this.
If any of you would be able to help me and provide me a hint, please do so!
Thanks in advance,
George.
There are some articles on MP2Kmag.com to help with DisplayDataMap. In particular, the arrays you pass in as parameters are tricky. Also, the book Programming MapPoint in .NET was a big help to me in dealing with the DisplayDataMap method.

Categories

Resources