ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  WinChartViewer resizing
Posted by Ben Young on Aug-21-2014 01:07
Hello,

I'm trying to retro fit ChartDirector into a WinForms app, replacing the ChartFX graphing engine it currently uses.

It's mostly going well.  They have this one feature where they have multiple charts in the same plot area, with a common X axis, and then one plot for each Y of Time, Temperature, and FlowRate, etc.  I'm still figuring that out, but it is doable...  Anyways...


The tougher problem is resizing the plot.

There is sometimes LOTS of data, and the half-window plot area is too small, so there is an Expand button on the form to let the chart object take up the whole window.  In ChartFX, it persists the data and redraws just fine (as the original author of the app relied upon).  However, in ChartDirector, resizing the control just leaves the chart the same size.

From my reading, I can either have the image scale (bad, since it was un-readable before), or redraw the whole thing.

I can see that the WinChartViewer still has a reference to my XYChart object, but updating the PlotArea doesn't do anything.  I've tried many code variants, like the following.

      Dim C As ChartDirector.XYChart = Chart3.Chart
      C.setPlotArea(70, 25, Chart3.Width - 70 - 20, Chart3.Height - 55 - 20, -1)
      Chart3.Chart = Nothing
      C.makeChart()
      Chart3.Chart = C
      Chart3.Refresh()

Chart3.Width has the new size, but the image size is unchanged.

Is there a way to resize the chart object without re-pulling the data?  The original code used lots of DB calls to get the labels and other elements of the plot area, and doing the DB calls again would be a pain, as I'd have to cache those parameters, or I'd have to cache all the DB results.  I'm trying to leave the original code mostly intact, since it is fairly confusing the work through, and cleaning it up is something I don't have time for right now.


Thanks!

  Re: WinChartViewer resizing
Posted by Peter Kwan on Aug-21-2014 23:55
Hi Ben,

The recommended code structure is like:

'Member variables to hold the data arrays
Dim myData() As Double
Dim myData2() As Double
.....


Sub readDataFromDatabase()
   .... read data from your database and store them in the data arrays ....
End Sub


Sub drawChart()
    .... draw the chart using data from the data arrays ....
End Sub


When the chart is first drawn, your code calls both readDataFromDatabase and
drawChart. When the chart is resized, your code just calls drawChart.

Your existing database code should have already been reading data from the database
and storing them in the data arrays, and then use the data arrays to create the chart
layers. If your existing database code is intermingled with the chart drawing code, you
would need to move your database code so that they are separated from the charting
code.

You may not need to write additional code to "cache" things. Your existing code should
have already read the data into array variables. You just need to make sure those
variables are declared as member variables of your Form, as they can be used later. If
they are declared as local variables in a function, VB will automatically destroyed them
when the function is exited.

Regards
Peter Kwan