WPF – Maps with no spaces between drawings

I am using the WPF toolkit, and I am trying to render a graph that looks like a histogram. In particular, I want each column to correspond to each column. The columns should be There is no gap.

When creating a column chart, you applied many components. (See the sample XAML below). Does anyone know if you can set attributes on one of the elements, which refer to Is the width of the blank area between the columns?

 Title="Column Graph" LegendTitle= "Legend">

Name="theColumnSeries"
Title="Series A"
IndependentValueBinding="{Binding Path=Name}" < br /> DependentValueBinding="{Binding Path=Population}"
Margin="0"
>



Orientation="Y"
Minimum="200000"
Maximum="2500000"
ShowGridLines="True" />
Name="chartCategoryAxis"
/>

In the absence of a magical answer, I downloaded the wpftoolkit code from codeplex.

By reading the code, I can use the method ColumnSeries. Seen in UpdateDataPoint, there is this line of code:

double segmentWidth = coordinateRangeWidth * 0.8;

So this is a very clear “no”, you You cannot change the gap between columns by setting public properties.

The solution I will try is to write a new class that inherits from ColumnSeries and overrides UpdateDataPoint.

Edit later< /p>

Okay, I got it to work. If anyone is interested, I have attached the complete code of the HistogramSeries class.

public class HistogramSeries: ColumnSeries, ISeries
{
protected override void UpdateDataPoint(DataPoint dataPoint)
{
// That set the height and width.
base.UpdateDataPoint(dataPoint);
// Now we override the part about setting the width
object category = dataPoint.ActualIndependentValue;
var coordinateRange = GetCategoryRange(category);
double minimum = (double)coordinateRange.Minimum.Value;
double maximum = (double)coordinateRange.Maximum.Value;
double coordinateRangeWidth = (maximum-minimum);
const int WIDTH_MULTIPLIER = 1; // Harcoded to 0.8 in the parent. Could make this a dependency property
double segmentWidth = coordinateRangeWidth * WIDTH_MULTIPLIER;
var columnSeries = SeriesHost.Series.OfType().Where(series => series.ActualIndependentAxis == ActualIndependentAxis);
int numberOfSeries = columnSeries.Count();
double columnWidth = segmentWidth / numberOfSeries;
int seriesIndex = columnSeries. IndexOf(this);
double offset = seriesIndex * Math.Round(columnWidth) + coordinateRangeWidth * 0.1;
double dataPointX = minimum + offset;
double left = Math.Round(dataPointX);
double width = Math.Round(columnWidth);< br /> Canvas.SetLeft(dataPoint, left);
dataPoint.Width = width;
}
#region ISeries Members
System.Collections.ObjectModel.ObservableCollection ISeries .LegendItems
{
get {return base.LegendItems; }
}
#endregion
#region IRequireSeriesHost Members
ISeriesHost IRequireSeriesHost.SeriesHost
{
get {return base.SeriesHost;}
set {base.SeriesHost = value; }
}
#endregion
}
// Copied from the DataVisualization library
// (It was an internal class)
static class MyEnumerableFunctions
{
public static int IndexOf(this IEnumerable that, object value)
{< br /> int index = 0;
foreach (object item in that)
{
if (object.ReferenceEquals(value, item) || value.Equals(item))
{
return index;
}
index++;
}
return -1;
}
}

I am using the WPF toolkit, I am trying Render a graph that looks like a histogram. In particular, I want each column to correspond to each column. There should be no gaps between the columns.

When creating the column chart, you applied Many components. (See sample XAML below). Does anyone know if you can set attributes on one of the elements, which refer to the width of the white space between the columns?

 Title="Column Graph" LegendTitle= "Legend">

Name="theColumnSeries"
Title="Series A"
IndependentValueBinding="{Binding Path=Name}" < br /> DependentValueBinding="{Binding Path=Population}"
Margin="0"
>



Orientation="Y"
Minimum="200000"
Maximum="2500000"
ShowGridLines="True" />
Name="chartCategoryAxis"
/>

In the absence of a magical answer, I downloaded the wpftoolkit code from codeplex.

By reading the code, I can see in the method ColumnSeries.UpdateDataPoint that there is this line of code:

p>

double segmentWidth = coordinateRangeWidth * 0.8;

So this is a very clear “no”, you cannot change the gap between columns by setting public properties .

The solution I will try is to write a new class that inherits from ColumnSeries and overrides UpdateDataPoint.

Edit later

Ok, I let it Go to work. If anyone is interested, I have attached the complete code of the HistogramSeries class.

public class HistogramSeries: ColumnSeries, ISeries
{
protected override void UpdateDataPoint(DataPoint dataPoint)
{
// That set the height and width.
base.UpdateDataPoint(dataPoint);
// Now we override the part about setting the width
object category = dataPoint.ActualIndependentValue;
var coordinateRange = GetCategoryRange(category);
double minimum = (dou ble)coordinateRange.Minimum.Value;
double maximum = (double)coordinateRange.Maximum.Value;
double coordinateRangeWidth = (maximum-minimum);
const int WIDTH_MULTIPLIER = 1; // Harcoded to 0.8 in the parent. Could make this a dependency property
double segmentWidth = coordinateRangeWidth * WIDTH_MULTIPLIER;
var columnSeries = SeriesHost.Series.OfType().Where(series => series.ActualIndependentAxis = = ActualIndependentAxis);
int numberOfSeries = columnSeries.Count();
double columnWidth = segmentWidth / numberOfSeries;
int seriesIndex = columnSeries.IndexOf(this);
double offset = seriesIndex * Math.Round(columnWidth) + coordinateRangeWidth * 0.1;
double dataPointX = minimum + offset;
double left = Math.Round(dataPointX);
double width = Math.Round(columnWidth) ;
Canvas.SetLeft(dataPoint, left);
dat aPoint.Width = width;
}
#region ISeries Members
System.Collections.ObjectModel.ObservableCollection ISeries.LegendItems
{
get {return base. LegendItems; }
}
#endregion
#region IRequireSeriesHost Members
ISeriesHost IRequireSeriesHost.SeriesHost
{
get {return base.SeriesHost;}
set {base.SeriesHost = value; }
}
#endregion
}
// Copied from the DataVisualization library
// (It was an internal class)
static class MyEnumerableFunctions
{
public static int IndexOf(this IEnumerable that, object value)
{
int index = 0;
foreach (object item in that)
{
if (object.ReferenceEquals(value, item) || value.Equals(item))
{
return index;
}
index++;
}
return -1;
}
}

Leave a Comment

Your email address will not be published.