Yale,
I want to display the zedGraph in my map. the data of zedGraph is from a InMemoryFeatureLayer of thinkgeo.
I reference the sample "DrawUsingZedGraphStyle" in "CSharp VS2005 Winforms HowDoISamples"
the following is my codes:
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
InMemoryFeatureLayer memoryFeatureLayer = new InMemoryFeatureLayer();
Dictionary<string, string> feature1Column = new Dictionary<string, string>();
feature1Column["AGE_UNDER5"] = "1500";
feature1Column["AGE_5_17"] = "5000";
feature1Column["AGE_18_21"] = "10000";
Feature feature1 = new Feature("POINT(-92 38)", "1", feature1Column);
memoryFeatureLayer.InternalFeatures.Add(feature1);
string valu1 = memoryFeatureLayer.InternalFeatures[0].ColumnValues["AGE_UNDER5"];
string valu2 = memoryFeatureLayer.InternalFeatures[0].ColumnValues["AGE_5_17"];
string valu3 = memoryFeatureLayer.InternalFeatures[0].ColumnValues["AGE_18_21"];
ZedGraphStyle zedGraphStyle = new ZedGraphStyle();
foreach (string column in feature1Column.Keys)
{
zedGraphStyle.RequiredColumnNames.Add(column);
}
zedGraphStyle.ZedGraphDrawing += new EventHandler<ZedGraphDrawingEventArgs>(zedGraphStyle_ZedGraphDrawing1);
memoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(zedGraphStyle);
memoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay Overlay = new LayerOverlay();
Overlay.Layers.Add("Cities", memoryFeatureLayer);
this.winformsMap1.Overlays.Add("CitiesOverlay", Overlay);
winformsMap1.CurrentExtent = new RectangleShape(-126.4, 48.8, -67.0, 19.0);
winformsMap1.Refresh();
private void zedGraphStyle_ZedGraphDrawing1(object sender, ZedGraphDrawingEventArgs e)
{
e.Bitmap = (Bitmap)this.Invoke(new ToUIThreadDelegate(ZedGraphDrawingPie1), new object[] { e });
}
private Bitmap ZedGraphDrawingPie1(ZedGraphDrawingEventArgs e)
{
double scale = ExtentHelper.GetScale(winformsMap1.CurrentExtent, winformsMap1.Width,GeographyUnit.DecimalDegree);
// Change the size of the graph based on the scale. It will get bigger as you zoom in.
int graphHeight = Convert.ToInt32(1400000000 / scale);
ZedGraphControl zedGraph = new ZedGraphControl();
zedGraph.Size = new Size(graphHeight, graphHeight);
zedGraph.GraphPane.Fill.Type = FillType.None;
zedGraph.GraphPane.Chart.Fill.Type = FillType.None;
zedGraph.GraphPane.Border.IsVisible = false;
zedGraph.GraphPane.Chart.Border.IsVisible = false;
zedGraph.GraphPane.XAxis.IsVisible = false;
zedGraph.GraphPane.YAxis.IsVisible = false;
zedGraph.GraphPane.Legend.IsVisible = true;
zedGraph.GraphPane.Title.IsVisible = false;
PieItem pieItem1 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues["AGE_UNDER5"]), GetColorFromGeoColor(GeoColor.StandardColors.LightBlue), 0, "AGE_UNDER5");
pieItem1.LabelDetail.IsVisible = false;
PieItem pieItem2 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues["AGE_5_17"]), GetColorFromGeoColor(GeoColor.StandardColors.LightGreen), 0, "AGE_5_17");
pieItem2.LabelDetail.IsVisible = false;
PieItem pieItem3 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues["AGE_18_21"]), GetColorFromGeoColor(GeoColor.StandardColors.LightCoral), 0, "AGE_18_21");
pieItem3.LabelDetail.IsVisible = false;
zedGraph.AxisChange();
return zedGraph.GraphPane.GetImage();
}
when I run the program,it throw a exception. Then I debug the program, I found the problem is the follwing lines
PieItem pieItem1 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues["AGE_UNDER5"]), GetColorFromGeoColor(GeoColor.StandardColors.LightBlue), 0, "AGE_UNDER5");
the value of "e.Feature.ColumnValues["AGE_UNDER5"]" is null, ConvertToDouble generates a error.
At the same time ,I modify the value of "e.Feature.ColumnValues["AGE_UNDER5"]" to 1500,the value of "e.Feature.ColumnValues["AGE_5_17"]" to 5000, the value of "e.Feature.ColumnValues["AGE_18_21"]" to 10000. then the zedGraph style display well.
How can I resovle the problem? I'm excepting your reply ?
thank you very much.