This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi There, I have a questions about chart axis, I want to be able to put Label of axis before the Data Point is added to the curve. Here are the situations that I want to solve: Let's say I have a dataPoints that contains string values for one of directions: {"x1", double value1}, {"x2", double value2}, {"x3", double value3}, {"x4", double value4}, {"x5", double value5} I want the X axis label is shown as "x1", "x2", "x3", "x4" and "x5". Since it is real time data, at beginning I don't have data points, so the x-axis will have no tick label. then the datapoints comes in, but they are not in the order of "x1", "x2", "x3", "x4", "x5", i.e.: {"x5", double value}, {"x2", double value}, {"x4", double value}, {"x1", double value}, {"x3", double value} then the x axis label is showing on this order "x5", "x2", "x4", "x1" and "x3". But this is not what I want, I still want to have label order as: "x1", "x2", "x3", "x4" and "x5". So my question is can we set the x-axis label at beginning of chart initialization? How do I achieve the above without sorting the data? Any example will be very helpful. Thanks Gordon |
|
|
Hi Gordon, Just letting you know we are looking into this. This may involve a new feature for adding default labels, but as most of the chart is set to draw automatically based on its DataPoints this may be unsatisfactory. One alternative may be to use 'dummy' data points that have their x values set, and then update the Y values as the data comes in, along with a dictionary to avoid sorting/indexof. We will let you know here when we have a solution. |
|
|
Hello Gordon As mentioned, there isn't a way to add default labels first, but there is currently a way to tell the X axis that you want the labels to be ordered in a special way. This can be done by creating a custom axis value converter by implementing the IAxisValueConverter interface. An example of this can be found in the SampleExplorer "Custom Axis Scale" demo. The code for this is in SampleExplorer/Converters/GradeAxisValueConverter.cs file. When you implement this interface, you'll have 2 methods to implement: GetAxisPlotPosition this takes an object (in your case a string) and converters it to an axis plot position. GetDataObjectAt This reverses the other method - takes an axis plot position and converts it into an object. The scenario you described is fairly simply - in the first method, you should be able to parse the given string and return the numeric part. i.e X4 would return 4. In the GetDataObjectAt method, you simply return a string starting with "X" and append the given number as a string. After implementing this, set the ValueConverter property of the XAxis to be an instance of your custom value converter. Now when items are dynamically added to the chart, the converter will cause them to appear in the correct order and position along the axis. If you want the labels to be displayed before the data is added, you can set the Maximum property of the XAxis and the converter will cause the correct labels to be displayed before the data exists. Let us know if you need further help with this. Jason Fauchelle |
|
|
Hi Jason, I tried your solution and it is working fine except the Grid line on axis is not moving properly when resizing the window.. The only thing is different from the sample is that I don't have all the string values at beginning and I will have more information as more data coming in in real time. So the tick mark values is dynamic changed. so I need to automatically update the axis. The included example is kind of demonstrations. Everything is working now except the Grid line won't move when we re-size the window: 1) unzip the file 2) Open the solution 3) You may need to re-direct the reference for WpfElement.dll 4) Run the application 5) Click on the button Scatter Plot 6) Click on button Add Points 7) Everything is fine. 8) Resize the window, you will see the grid line on axis is not moving. The code update the axis is in function void AxisProperty_PropertyChanged(object sender, PropertyChangedEventArgs e) in file WpfMsChart.cs. Please let me know if you have probleen to run the projects. what else I need to do to make it working? Thanks Gordon |
|
|
Thanks for the repro project Gordon This was a bug in the ChartGrid where if the XAxis or YAxis properties of the parent Chart control change, the ChartGrid would still be using the old axes. This has been resolved which you can update through the next nightly build. Jason Fauchelle |
|