|
Move objects on the Plot |
Posted by John on May-03-2013 20:13 |
|
Hi,
Is there any option to move the objects (like text, points) placed on the plot ?
Please suggest.
Thanks InAdvance,
John. |
Re: Move objects on the Plot |
Posted by Peter Kwan on May-04-2013 04:51 |
|
Hi John,
To move the objects, simply draw them in different locations.
As mentioned in my responses to your other messages, if you want the user to interactively move the objects, you would need to develop the user interface yourself. Basically, your code needs to handle the user input or action and update your data or chart configuration accordingly.
Regards
Peter Kwan |
Re: Move objects on the Plot |
Posted by John on May-07-2013 20:46 |
|
Hi Peter Kwan,
How to track the mouse click event on the title of my plot area ?
Thanks in advance
John. |
Re: Move objects on the Plot |
Posted by Peter Kwan on May-08-2013 00:00 |
|
Hi John,
Basically, you can create an image map for your title, so that it can respond to mouse clicks like all other hot spots in your chart.
Many programming langauge edition of ChartDirector contains an example called "Custom Clickable Objects" that demonstrates how to make various objects clickable, including the chart title and custom text on the plot area. For example, the the "Custom Clickable Objects" sample code for ChatrDirector for .NET is as follows:
http://www.advsofteng.com/doc/cdnet.htm#customclickable.htm
You may try to look up "Custom Clickable Objects" from the ChartDirector documentation index. If you cannot find such an example, please inform me which programming langauge edition of ChartDirector you are using, and which GUI framework you are using (eg. web/html, SWING, MFC, QT, Windows Forms, ....). I can produce a short example for you.
Regards
Peter Kwan |
Re: Move objects on the Plot |
Posted by John on May-08-2013 17:15 |
|
Hi ,
Iam using vc++ Windows form application.
Thanks in advance.
John. |
Re: Move objects on the Plot |
Posted by John on May-08-2013 17:15 |
|
Hi ,
Iam using vc++ Windows form application.
Thanks in advance.
John. |
Re: Move objects on the Plot |
Posted by Peter Kwan on May-09-2013 02:25 |
|
Hi John,
I assume you are already aware that VC++ Windows Forms is not standard C++, but is a proprietary Microsoft .NET language with a similar name called "C++/CLI". As it is a .NET language, the ChartDirector edition to use should be "ChartDirector for .NET". (The "ChartDIrector for C++" is for standard C++.) So the .NET sample code should be similar to what you need. You just need to change the syntax to C++/CLI instead of C#.
The following is an example based on the "Simple Bar Chart" sample code. I have added an image map for the "My Title" text. If you create a MouseMoveHotSpot event handler for the winChartViewer1 control, you should see the mouse move events on the "My Title" text.
// The data for the bar chart
array<double> ^data = {85, 156, 179.5, 211, 123};
// The labels for the bar chart
array<String^> ^labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};
// Create a XYChart object of size 400 x 400 pixels
XYChart ^c = gcnew XYChart(400, 400);
// Set the plotarea at (50, 50) and of size 320 x 320 pixels
c->setPlotArea(50, 50, 320, 320);
// Add a bar chart layer using the given data
c->addBarLayer(data);
// Set the labels on the x axis.
c->xAxis()->setLabels(labels);
ChartDirector::TextBox ^title = c->addText(200, 20, "My Title", "Arial Bold", 15, 0x000000, Chart::TopCenter);
// Output the chart
winChartViewer1->Image = c->makeImage();
// Obtain the image map for the title
String ^titleImageMap = "<area " + title->getImageCoor() +
" href='clickable?id=title' title='This is the title!'>";
//include tool tip for the chart
winChartViewer1->ImageMap = c->getHTMLImageMap("clickable?id={xLabel}", " ",
"title='{xLabel}: US${value}K'") + titleImageMap;
For testing, you may put the following code in the MouseMoveHotSpot event handler, so you can print out the hot spot information on the debugger display:
System::Diagnostics::Debug::WriteLine(e["id"] + " at " + e->X + ", " + e->Y);
When the mouse is moving over the "My Title" text, you should see the a line like "title at 206, 99", which shows the mouse is over the title and the mouse coordinates.
Hope this can help.
Regards
Peter Kwan |
Re: Move objects on the Plot |
Posted by John on May-10-2013 20:14 |
|
Hi Peter Kwan,
I have drawn a plot using some data points in my application(Using vc++ windows form application). And now I want to allow the user to interactively move the data points and place somewhere on my plot area. Now I should be able to redraw the plot accordingly taking the new position of the moved data point.
Is there any option to do this in ChartDirector.
Thanks,
John.
|
Re: Move objects on the Plot |
Posted by John on May-10-2013 20:49 |
|
Hi,
How to add my scatterlayer or data points to image map.
Thanks,
John. |
Re: Move objects on the Plot |
Posted by Peter Kwan on May-11-2013 02:01 |
|
Hi John,
To create an image map for the scatter layer, simply use the getHTMLImageMap as in the example I included in my last post. The only thing you need to consider is what parameters you would like to use to distinguish the points. For example, if the points can be distinguish using the x and y coordinates, you can use the x and y coordinates as the parameters:
c->getHTMLImageMap("clickable?x={x}&y={value}", " ");
With the image map, the points can response to mouse events. Like many other controls (such as the standard .NET TextBox or PictureBox control), by default, the mouse events do nothing. You can put your code in the mouse event handlers to perform anything you like. For example, you can put code in the mouse event handlers to detect how far the user has drag a point, and update your data based on that, and redraw the chart based on the updated data.
Hope this can help.
Regards
Peter Kwan |
Re: Move objects on the Plot |
Posted by John on May-11-2013 12:17 |
|
Hi,
Thanks for your reply.
I want to add an array of data points to the Image Map. Is there any way to add an entire array of points to the Imagemap all at once.
Thanks,
John. |
Re: Move objects on the Plot |
Posted by John on May-11-2013 13:13 |
|
Hi ,
In my application I have a Chartdirector textbox and a linelayer.
I want to move my textbox and place at someother place on my plot area in runtime which iam able to do right now.
Now, as I stated in my last post I also want to move my datapoints at runtime and redraw the plot.
And I want these two operations to be independent of one another.
How can I able to do this. Is their any way to create two separate image maps for two objects. And how can I handle those events separately.
Thanks,
John. |
Re: Move objects on the Plot |
Posted by Peter Kwan on May-13-2013 23:33 |
|
Hi John,
In the chart in your previous message, I saw some spline curves and some data points. The spline curve does not pass through all the data points, so I assume the data points are in a separate ScatterLayer and not part of the SplineLayer.
If you use BaseChart.getHTMLImageMap, you will create an image map for the data points in the scatter layer, and also an image map for the curve segments in the SplineLayer. If you do not want the image map for the spline layer, you may use Layer.setHTMLImageMap to disable it.
String ^titleImageMap = "<area " + title->getImageCoor() +
" href='clickable?name=title' title='This is the title!'>";
mySplineLayer->setHTMLImageMap("{disable}");
//This image map contains all the data points in your chart, as well as the title
winChartViewer1->ImageMap = c->getHTMLImageMap("clickable", "x={x}&y={value}&name={dataSetName}", "") + titleImageMap;
When the mouse interacts with any hot spot, it will invoke the mouse hot spot event handler (eg. MouseDownHotSpot, MouseMoveHotSpot, etc). In those event handlers, you may use e["name"] to determine which hot spot the mouse is over. If the e["name"] equals to "title", it is interacting with your title. If it is "A1 Raw-TDRY", it is on one of the data points in your "A1 Raw-TDRY". The exact data point can be determined by using e["x"] and e["y"], which are the x and y data values as text strings. You may use Double.Parse to convert them to "double".
if ((String ^)e["name"] == "title") {
.... is on title ...
} else {
.... is on one of the e["name"] data series ....
double x = Double::Parse((String^)e["x"], CultureInfo::InvariantCulture);
....
}
Hope this can help.
Regards
Peter Kwan |
|