<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hey Amitesh,<div><br></div><div>I don't have time to try out things myself right now, but I see that at least two of the Charts Cxx tests include text labels:</div><div><br></div><div>[vtk_source]/Charts/Testing/Cxx/TestStackedBarGraph.cxx</div><div>[vtk_source]/Charts/Testing/Cxx/TestStackedPlot.cxx</div><div><br></div><div>Maybe you can look at those examples and figure it out? If you have too much trouble, just write again and maybe I can do some more testing on my end.</div><div><br></div><div>Talk to you later,</div><div>-Eric</div><div><br></div><div><br><div><div>On Jun 28, 2011, at 3:16 PM, Amitesh Kumar wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><span class="Apple-style-span">Thank you very much for your reply! My apology for writing late but it is only today that I finally gotten around to test my code. I have one final question regarding vtk charts. If my x-axis labels are string or char* then how can I display them? In my case my x-axis labels are in the form of "x1-x2". I first tried using xLegends (in my code) as vtkStringArray with actual xAxis labels in there but that didn't work as my guess was that vtkCharts API tried to sort the points in the table. When that didn't work I tried using xLegends as vtkIntArray with indices 0 to n-1 for n bars in the bar plot which correctly created the plot. However 0 to n-1 is clearly not the right label in my case and I want use the values stored in xLabels (vtkStringArray) for my x-axis labels. I tried using setindexedLabels method as shown below but that </span>absolutely didn't seem to have any effect on the x-axis labels which were all int<span class="Apple-style-span">. </span></div>
<div><br></div><div><span class="Apple-style-span" style="color: rgb(37, 53, 85); font-family: 'Lucida Grande', Verdana, Geneva, Arial, sans-serif; font-size: 12px; font-weight: bold; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">void vtkPlot::SetIndexedLabels(<a class="el" href="http://www.vtk.org/doc/nightly/html/classvtkStringArray.html" style="color: rgb(61, 87, 140); font-weight: bold; text-decoration: none; ">vtkStringArray</a> * <em style="font-style: normal; ">labels</em>)</span></div>
<div><span class="Apple-style-span" style="color: rgb(37, 53, 85); font-family: 'Lucida Grande', Verdana, Geneva, Arial, sans-serif; font-size: 12px; font-weight: bold; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br>
</span></div><div>My plotting part of the code is as following. Note I am using vtk nightly 5.9 for this. Do you have any idea how to solve this problem.</div><div><br></div><div>Thank You </div><div><br></div><div>Amitesh</div>
<div><br></div><div>-----------------------------------------------------------------------------------------------------------------------------------------</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>std::stringstream ss3 (std::stringstream::in | std::stringstream::out);</div>
<div> vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>view->GetRenderWindow()->SetSize(800, 600);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>view->GetScene()->AddItem(chart);</div><div><br></div><div><div> vector<int>output = getDistribution(nPartition); //my internal function</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int numTuples = output.size();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkIntArray> xLegends = vtkSmartPointer<vtkIntArray>::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>xLegends->SetName("BarNumber");</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>std::vector<string> Labels; </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkStringArray> xLabels = vtkSmartPointer<vtkStringArray>::New();</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkIntArray>qData = vtkSmartPointer<vtkIntArray>::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>qData->SetName(ext2);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>table->AddColumn(xLegends);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>table->AddColumn(qData);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>table->SetNumberOfRows(numTuples);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>xLabels->SetNumberOfValues(numTuples);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(numTuples > nPartition)</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>{<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Labels.push_back(string("Pre"));</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>xLabels->SetValue(0, "Pre");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>table->SetValue(0,0,0);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>table->SetValue(0,1,output[nPartition]);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>for(int i = 0; i <nPartition; i++)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>float minR, maxR;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>getPartitionRange(i, nPartition, minR, maxR); //my internal function</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>ss3.str("");</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>ss3<<setprecision(2)<<minR<<"-"<<setprecision(2)<<maxR;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>Labels.push_back(ss3.str());</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>xLabels->SetValue(i+1, ss3.str().c_str());</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>table->SetValue(i+1,0,i+1);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>table->SetValue(i+1,1,output[i]);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Labels.push_back(string("Post"));</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>xLabels->SetValue(nPartition+1, "Post");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>table->SetValue(nPartition+1,0,nPartition+1);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>table->SetValue(nPartition+1,1,output[nPartition+1]);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>else</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>for(int i = 0; i <nPartition; i++)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>float minR, maxR;</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>getPartitionRange(i, nPartition, minR, maxR); //my internal function</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>ss3.str("");</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>ss3<<setprecision(2)<<minR<<"-"<<setprecision(2)<<maxR;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>xLabels->SetValue(i, ss3.str().c_str());</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>Labels.push_back(ss3.str());</div><div>
<span class="Apple-tab-span" style="white-space:pre">                        </span>//table->SetValue(i,0,ss3.str().c_str());</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>table->SetValue(i,0,i);</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>table->SetValue(i,1,output[i]);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkPlot *barPlot = 0;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>barPlot = chart->AddPlot(vtkChart::BAR);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>barPlot->SetInput(table, 0, 1);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>barPlot->SetColor(0, 0, 255, 255);<span class="Apple-tab-span" style="white-space:pre">        </span>//Blue</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>barPlot->SetIndexedLabels(xLabels); //This doesn't seem to work. </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//barPlot->GetLabels()->SetNumberOfValues(Labels.size());</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//for(int i=0; i<Labels.size(); i++)</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>//barPlot->GetLabels()->SetValue(i, Labels[i].c_str());</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>chart->SetShowLegend(true);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>chart->Update();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>view->Update();</div></div><div><br></div><div><br><div class="gmail_quote">
On Wed, Jun 22, 2011 at 9:52 AM, Eric E. Monson <span dir="ltr"><<a href="mailto:emonson@cs.duke.edu">emonson@cs.duke.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word">Hey Amitesh,<div><br></div><div>You can just build the second table you mentioned and then add a plot to the chart which uses that second table as its input. The chart should take care of it just fine.</div>
<div><br></div><div>I'll append a modified version of that example you quoted, which I think does what you're wanting. (The orange dotted line is the new data series and it has many fewer points and a different X range than the first two lines.)</div>
<div><br></div><div>Hope this helps,</div><div>-Eric</div><div><br><div>
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium"><span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<div>· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·</div><div>Eric E Monson</div><div>Duke Visualization Technology Group</div><div><br></div></div></span><span><TwoTablesPlotted.png></span><br>
</span><br>
</div><div><br></div><div><div>#include <vtkRenderer.h></div><div>#include <vtkRenderWindowInteractor.h></div><div>#include <vtkRenderWindow.h></div><div>#include <vtkSmartPointer.h></div><div>#include <vtkChartXY.h></div>
<div>#include <vtkPen.h></div><div>#include <vtkPlot.h></div><div>#include <vtkTable.h></div><div>#include <vtkFloatArray.h></div><div>#include <vtkContextView.h></div><div>#include <vtkContextScene.h></div>
<div> </div><div>int main(int, char *[])</div><div>{</div><div> // Create a table with some points in it</div><div> vtkSmartPointer<vtkTable> table = </div><div> vtkSmartPointer<vtkTable>::New();</div><div>
</div><div> vtkSmartPointer<vtkFloatArray> arrX = </div><div> vtkSmartPointer<vtkFloatArray>::New();</div><div> arrX->SetName("X Axis");</div><div> table->AddColumn(arrX);</div><div> </div>
<div> vtkSmartPointer<vtkFloatArray> arrC = </div><div> vtkSmartPointer<vtkFloatArray>::New();</div><div> arrC->SetName("Cosine");</div><div> table->AddColumn(arrC);</div><div> </div><div>
vtkSmartPointer<vtkFloatArray> arrS = </div><div> vtkSmartPointer<vtkFloatArray>::New();</div><div> arrS->SetName("Sine");</div><div> table->AddColumn(arrS);</div><div> </div><div> // Fill in the table with some example values</div>
<div> int numPoints = 69;</div><div> float inc = 7.5 / (numPoints-1);</div><div> table->SetNumberOfRows(numPoints);</div><div> for (int i = 0; i < numPoints; ++i)</div><div> {</div><div class="im"><div> table->SetValue(i, 0, i * inc);</div>
</div><div class="im"><div> table->SetValue(i, 1, cos(i * inc));</div><div> table->SetValue(i, 2, sin(i * inc));</div><div> }</div><div> </div></div><div> // Create a second table with some points in it</div>
<div> vtkSmartPointer<vtkTable> table2 = </div><div> vtkSmartPointer<vtkTable>::New();</div><div> </div><div> vtkSmartPointer<vtkFloatArray> arrX2 = </div><div> vtkSmartPointer<vtkFloatArray>::New();</div>
<div> arrX2->SetName("X Axis 2");</div><div> table2->AddColumn(arrX2);</div><div> </div><div> vtkSmartPointer<vtkFloatArray> arrC2 = </div><div> vtkSmartPointer<vtkFloatArray>::New();</div>
<div> arrC2->SetName("Cosine 2");</div><div> table2->AddColumn(arrC2);</div><div> </div><div> // Fill in the second table with some example values</div><div> numPoints = 8;</div><div> inc = 10.5 / (numPoints-1);</div>
<div> table2->SetNumberOfRows(numPoints);</div><div> for (int i = 0; i < numPoints; ++i)</div><div> {</div><div> table2->SetValue(i, 0, i * inc + 5);</div><div> table2->SetValue(i, 1, cos(i * inc));</div>
<div> }</div><div> </div><div> // Set up the view</div><div> vtkSmartPointer<vtkContextView> view = </div><div> vtkSmartPointer<vtkContextView>::New();</div><div> view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);</div>
<div> </div><div> // Add multiple line plots, setting the colors etc</div><div> vtkSmartPointer<vtkChartXY> chart = </div><div> vtkSmartPointer<vtkChartXY>::New();</div><div> view->GetScene()->AddItem(chart);</div>
<div> vtkPlot *line = chart->AddPlot(vtkChart::LINE);</div><div> line->SetInput(table, 0, 1);</div><div> line->SetColor(0, 255, 0, 255);</div><div> line->SetWidth(1.0);</div><div> line = chart->AddPlot(vtkChart::LINE);</div>
<div> line->SetInput(table, 0, 2);</div><div> line->SetColor(255, 0, 0, 255);</div><div> line->SetWidth(5.0);</div><div> </div><div> // Add a plot using the second table</div><div> line = chart->AddPlot(vtkChart::LINE);</div>
<div> line->SetInput(table2, 0, 1);</div><div> line->SetColor(255, 128, 0, 255);</div><div> line->SetWidth(3.0);</div><div> line->GetPen()->SetLineType(vtkPen::DASH_LINE);</div><div> </div><div> // Set up an interactor and start</div>
<div> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = </div><div> vtkSmartPointer<vtkRenderWindowInteractor>::New();</div><div> renderWindowInteractor->SetRenderWindow(view->GetRenderWindow());</div>
<div> renderWindowInteractor->Initialize();</div><div> renderWindowInteractor->Start();</div><div> </div><div> return EXIT_SUCCESS;</div><div>}</div></div>
<br><div><div><div></div><div class="h5"><div>On Jun 21, 2011, at 3:17 PM, Amitesh Kumar wrote:</div><br></div></div><blockquote type="cite"><div><div></div><div class="h5">I have a question about vtkChartXY and wonder if anybody would be willing to answer it?<br>
Currently as in the example shown in <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Plotting/LinePlot" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Plotting/LinePlot</a> the x-axis is defined as <br>
<br><font face="'courier new', monospace">table->SetValue(i, 0, i * inc);</font><div><br>while the datasets are defined as<br><br><font face="'courier new', monospace">table->SetValue(i, 1, cos(i * inc));<br>
table->SetValue(i, 2, sin(i * inc));</font><br><br>Which means that both plot 1 and plot 2 need to have exact same correspondence with x-axis with same number of rows and x-axis values. Lets say I have two sets of data, one in which x-axis starts from 1-10 and and another in which the x-axis starts from 5-20 and the number of points (rows) on first set is different compared with that of the second set. I clearly would need to have two tables in the current scheme of things. How can this be plotted using vtkChartXY or any other methods in VTK. Is there any chart which would support it? Are there any examples of the same? I am using version 5.9 of VTK. I really need some help on this!</div>
<div><br></div><div>Thank You</div><div><br>Amitesh<br><br><br><br><br></div></div></div>
_______________________________________________<br>Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br></div></div></blockquote></div><br></div>
<span><TriangleMetrics.Area.jpg></span></blockquote></div><br></div></body></html>