-
February 1st, 2014, 01:19 PM
#1
Creating Charts : Path related problems
Hey guys! It has been a really long time since my last post, but I am afraid I need your help again :P
I have been creating an application in C# for the last few days, which is some sort of Financial Manager with a small database and was going great until now. It is nearly done except the charts which is, as expected, not easy compared to the rest.
My original idea, was to check how many expenses existed in the database and their respective values and then use that information to create the chart (histogram or a bar chart). I though about using the PathGeometry, PathFigure, and LineSegment classes to start, so I decided to check some tutorials and found this, which would help me create one of the four lines of a rectangle. Anyway, the code at the end of the tutorial does not work for me:
Code:
Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;
I think I understand the logic through the code, just do not understand why is not working for me nor how to fix it.
These are the errors:
- Error 1 Cannot declare a variable of static type 'System.IO.Path'
- Error 2 Cannot create an instance of the static class 'System.IO.Path'
- Error 3 'System.IO.Path' does not contain a definition for 'Stroke' and no extension method 'Stroke' accepting a first argument of type 'System.IO.Path' could be found (are you missing a using directive or an assembly reference?)
- Error 4 The name 'Brushes' does not exist in the current context
- Error 5 'System.IO.Path' does not contain a definition for 'StrokeThickness' and no extension method 'StrokeThickness' accepting a first argument of type 'System.IO.Path' could be found (are you missing a using directive or an assembly reference?)
- Error 6 'System.IO.Path' does not contain a definition for 'Data' and no extension method 'Data' accepting a first argument of type 'System.IO.Path' could be found (are you missing a using directive or an assembly reference?)
Any kind of feedback regarding how to use these libraries or even about a more efficient way of creating charts would be gladly accepted. I am using Microsoft Visual Studio 2013 Professional.
Thanks for your time,
Pancake
-
February 1st, 2014, 08:37 PM
#2
Re: Creating Charts : Path related problems
You need to include the presentationframework.dll and the correct namespace rather than System.IO.Path
-
February 2nd, 2014, 06:35 AM
#3
Re: Creating Charts : Path related problems
I have just included the presentationframework.dll on my project, but what is the correct namespace?
Edit: I have been looking for a few alternatives to do the charts and I found out there is a chart class. But for some reason I can not use it. The chart does not appear on the toolbox and it is greyed out. I googled it and apparently it is something that happens a lot, I have both namespaces selected in the toolbox in the .NET Framekwork Components tab:
- System.Web.UI.DataVisualization.Charting
- System.Windows.Forms.DataVisualization.Charting
And the .NET Framework my project is using is 4.5. Any suggestions?
Thanks for your time,
Pancake
Last edited by Pancake; February 2nd, 2014 at 08:54 AM.
-
February 2nd, 2014, 09:16 AM
#4
Re: Creating Charts : Path related problems
The information is in msdn. Look in your original link. Then look at the base information for the class. It will specify the class details, the namespace, and what assembly to include. The good news is that once you see how msdn lays out the information for one class, you have figured out how msdn does it for all classes.
-
February 2nd, 2014, 09:47 AM
#5
Re: Creating Charts : Path related problems
I already have the System.IO namespace and the presentationframework.dll included and does not seem to work, the errors are the same
Here is what I am including in the code:
Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
And I included the .dll in the references. Any suggestions?
Thanks for your time,
Pancake
-
February 2nd, 2014, 02:24 PM
#6
Re: Creating Charts : Path related problems
Originally Posted by Pancake
Any suggestions?
Yes, please follow what I'm telling you. Btw, a class you use 'Path' is in System.IO namespace, but the one in that namespace is the wrong one. In .net, there are several classes that have the same name (but even though they are named the same, classes with the same name are always in different namespaces).
With that being said, go back to the link you included and be aware of two things: 1) The text tells you that the code snippet in the link is part of a larger code sample called the Geometries Sample. Click on that link to download the complete sample (you can see exactly what namespaces are used and what assemblies are referenced); and 2) at the bottom of the link is a "see also" section. Under "Reference", click on the Path link. This will take you to the Path class in msdn. Near the top of the page, you see:
Namespace: System.Windows.Shapes
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2...l/presentation, http://schemas.microsoft.com/netfx/2...l/presentation
That tells you to reference the presentationframework.dll (which you've done). Include the System.Windows.Shapes as the namespace meaning add using System.Windows.Shapes; to the cs file. You need to remove the using System.IO; line in your code (because it includes the wrong Path class for what you need).
-
February 2nd, 2014, 02:40 PM
#7
Re: Creating Charts : Path related problems
-
February 2nd, 2014, 08:05 PM
#8
Re: Creating Charts : Path related problems
Great. Download the geometries sample and use it to compare with your code to find out why yours is not drawing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|