CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    5

    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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Creating Charts : Path related problems

    You need to include the presentationframework.dll and the correct namespace rather than System.IO.Path

  3. #3
    Join Date
    Jan 2013
    Posts
    5

    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.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  5. #5
    Join Date
    Jan 2013
    Posts
    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

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Creating Charts : Path related problems

    Quote Originally Posted by Pancake View Post
    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).

  7. #7
    Join Date
    Jan 2013
    Posts
    5

    Re: Creating Charts : Path related problems

    Ohhh I see, the problem was I googled the name of the class Path and it came as first result this one which had the System.IO as namespace. So I was not understanding how it was not working

    Now that I see, yes, if I go through the original link and check the "Path" there is a different story. I used this code to specify the right "Path":

    Code:
    PathFigure mypathfigure = new PathFigure();
    mypathfigure.StartPoint = new Point(0, 0);
    LineSegment mylinesegment = new LineSegment();
    mylinesegment.Point = new Point(100, 100);
    PathSegmentCollection mypathsegmentcollection = new PathSegmentCollection();
    mypathsegmentcollection.Add(mylinesegment);
    mypathfigure.Segments = mypathsegmentcollection;
    PathFigureCollection mypathfigurecollection = new PathFigureCollection();
    mypathfigurecollection.Add(mypathfigure);
    PathGeometry mypathgeometry = new PathGeometry();
    mypathgeometry.Figures = mypathfigurecollection;
    Windows.UI.Xaml.Shapes.Path mypath = new Windows.UI.Xaml.Shapes.Path();
    SolidColorBrush red = new SolidColorBrush(Windows.UI.Colors.Red);
    mypath.Stroke = red;
    mypath.StrokeThickness = 10;
    mypath.Data = mypathgeometry;
    There are no more syntax errors, the program is compiled successfully, although it does not draw anything at all yet

    Anyway, thanks for quick replies

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
  •  





Click Here to Expand Forum to Full Width

Featured